Skip to content

Commit bedb816

Browse files
raghucssitiloveeclipse
authored andcommitted
Implement activity support filtering for e4 dynamic menu contribution.
Similar to PluginActionContributionItem we can support activity filtering of menu item to be shown or not. Fixes #2217
1 parent 55481d3 commit bedb816

File tree

10 files changed

+130
-8
lines changed

10 files changed

+130
-8
lines changed

bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Bundle-RequiredExecutionEnvironment: JavaSE-17
9-
Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
9+
Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="1.17.0",
1010
org.eclipse.e4.core.services;bundle-version="0.9.0",
1111
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
1212
org.eclipse.e4.core.di;bundle-version="1.1.0",

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/DynamicContributionContributionItem.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package org.eclipse.e4.ui.workbench.renderers.swt;
1616

17+
import org.eclipse.e4.ui.activitysupport.EActivityManager;
1718
import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
1819
import org.eclipse.jface.action.ContributionItem;
1920
import org.eclipse.jface.action.IContributionManager;
@@ -29,12 +30,17 @@ class DynamicContributionContributionItem extends ContributionItem {
2930

3031
private IMenuListener menuListener = IMenuManager::markDirty;
3132

33+
private static final String BUNDLE_CLASS_PREFIX = "bundleclass://"; //$NON-NLS-1$
34+
35+
private final EActivityManager activitySupport;
36+
3237
/**
3338
* Create the item and associated model;
3439
*/
35-
public DynamicContributionContributionItem(MDynamicMenuContribution item) {
40+
public DynamicContributionContributionItem(MDynamicMenuContribution item, EActivityManager activitySupport) {
3641
super(item.getElementId());
3742
model = item;
43+
this.activitySupport = activitySupport;
3844
}
3945

4046
@Override
@@ -66,4 +72,18 @@ public void setParent(IContributionManager parent) {
6672
}
6773
super.setParent(parent);
6874
}
75+
76+
@Override
77+
public boolean isVisible() {
78+
if (activitySupport != null) {
79+
// Contribution URI has the scheme bundleclass://. Ex:
80+
// bundleclass://org.eclipse.pde.spy.core/org.eclipse.pde.spy.core.SpyProcessor
81+
String contributionURI = this.getModel().getContributionURI();
82+
if (contributionURI.startsWith(BUNDLE_CLASS_PREFIX)) {
83+
return activitySupport.isIdentifierEnabled(contributionURI.substring(BUNDLE_CLASS_PREFIX.length()));
84+
}
85+
}
86+
return true;
87+
}
88+
6989
}

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.eclipse.e4.core.contexts.RunAndTrack;
4747
import org.eclipse.e4.core.di.annotations.Optional;
4848
import org.eclipse.e4.core.services.log.Logger;
49+
import org.eclipse.e4.ui.activitysupport.EActivityManager;
4950
import org.eclipse.e4.ui.di.UIEventTopic;
5051
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
5152
import org.eclipse.e4.ui.internal.workbench.OpaqueElementUtil;
@@ -116,6 +117,9 @@ public class MenuManagerRenderer extends SWTPartRenderer {
116117
@Inject
117118
private MApplication application;
118119

120+
@Inject
121+
EActivityManager activityManager;
122+
119123
@Inject
120124
@Optional
121125
private void subscribeSelectionUpdated(@UIEventTopic(UIEvents.Item.TOPIC_SELECTED) Event event) {
@@ -783,7 +787,7 @@ private void processDynamicMenuContribution(MenuManager menuManager, MDynamicMen
783787
return;
784788
}
785789
itemModel.setRenderer(this);
786-
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel);
790+
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel, activityManager);
787791
addToManager(menuManager, itemModel, ci);
788792
linkModelToContribution(itemModel, ci);
789793
}

bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-SymbolicName: org.eclipse.e4.ui.workbench;singleton:=true
4-
Bundle-Version: 1.16.100.qualifier
4+
Bundle-Version: 1.17.0.qualifier
55
Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.2.0",
2020
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)"
2121
Bundle-ActivationPolicy: lazy
2222
Bundle-RequiredExecutionEnvironment: JavaSE-17
23-
Export-Package: org.eclipse.e4.ui.internal.workbench;
23+
Export-Package: org.eclipse.e4.ui.activitysupport,
24+
org.eclipse.e4.ui.internal.workbench;
2425
x-friends:="org.eclipse.e4.ui.workbench.fragment,
2526
org.eclipse.e4.ui.workbench.addons.swt,
2627
org.eclipse.e4.ui.workbench.renderers.swt,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Advantest Europe GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Raghunandana Murthappa
13+
*******************************************************************************/
14+
package org.eclipse.e4.ui.activitysupport;
15+
16+
/**
17+
* A bridge between org.eclipse.ui.workbench and
18+
* org.eclipse.e4.ui.workbench.renderers.swt.
19+
*
20+
* Service for this interface is bound to Platform.class bundle at
21+
* Workbench.class. We cannot depend on org.eclipse.ui.workbench from
22+
* org.eclipse.e4.ui.workbench.renderers.swt
23+
*
24+
* @since 1.17
25+
*/
26+
public interface EActivityManager {
27+
/**
28+
* Checks whether the given element is enabled or not in the workbench activity
29+
* support.
30+
*
31+
* @param identifierId A qualified id if the contribution. Which has format of
32+
* bundle-id/element. Ex:
33+
* org.eclipse.pde.spy.core/org.eclipse.pde.spy.core.SpyProcessor
34+
* @return {@code true} if the given identifierId is enabled within workbench
35+
* activity support.
36+
*/
37+
public boolean isIdentifierEnabled(String identifierId);
38+
}

bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4.0.0)",
113113
org.eclipse.e4.ui.workbench.addons.swt;bundle-version="0.10.0",
114114
org.eclipse.e4.ui.services;bundle-version="1.3.0",
115115
org.eclipse.emf.ecore.xmi;bundle-version="2.11.0",
116-
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0"
116+
org.eclipse.e4.core.di.extensions;bundle-version="0.13.0",
117+
org.eclipse.e4.ui.workbench;bundle-version="1.17.0"
117118
Import-Package: com.ibm.icu.util,
118119
jakarta.annotation;version="[2.1.0,3.0.0)",
119120
jakarta.inject;version="[2.0.0,3.0.0)",
@@ -140,4 +141,5 @@ Service-Component: OSGI-INF/org.eclipse.ui.internal.BindingToModelProcessor.xml,
140141
OSGI-INF/org.eclipse.ui.internal.CommandToModelProcessor.xml,
141142
OSGI-INF/org.eclipse.ui.internal.ContextToModelProcessor.xml,
142143
OSGI-INF/org.eclipse.ui.internal.WindowsDefenderConfigurator.xml,
143-
OSGI-INF/org.eclipse.ui.internal.themes.ColorAndFontProviderImpl.xml
144+
OSGI-INF/org.eclipse.ui.internal.themes.ColorAndFontProviderImpl.xml,
145+
OSGI-INF/org.eclipse.ui.internal.util.ActivityManagerProxy.xml

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.eclipse.e4.core.contexts.IEclipseContext;
8888
import org.eclipse.e4.core.di.InjectionException;
8989
import org.eclipse.e4.core.services.events.IEventBroker;
90+
import org.eclipse.e4.ui.activitysupport.EActivityManager;
9091
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
9192
import org.eclipse.e4.ui.internal.workbench.E4XMIResource;
9293
import org.eclipse.e4.ui.internal.workbench.renderers.swt.IUpdateService;
@@ -246,6 +247,7 @@
246247
import org.eclipse.ui.internal.themes.FontDefinition;
247248
import org.eclipse.ui.internal.themes.ThemeElementHelper;
248249
import org.eclipse.ui.internal.themes.WorkbenchThemeManager;
250+
import org.eclipse.ui.internal.util.ActivityManagerProxy;
249251
import org.eclipse.ui.internal.util.PrefUtil;
250252
import org.eclipse.ui.intro.IIntroManager;
251253
import org.eclipse.ui.keys.IBindingService;
@@ -2212,6 +2214,10 @@ public Object compute(IEclipseContext context, String contextKey) {
22122214
}
22132215
});
22142216
WorkbenchPlugin.getDefault().initializeContext(e4Context);
2217+
2218+
BundleContext context = FrameworkUtil.getBundle(Platform.class).getBundleContext();
2219+
ActivityManagerProxy service = new ActivityManagerProxy();
2220+
context.registerService(EActivityManager.class.getName(), service, null);
22152221
}
22162222

22172223
private ArrayList<MCommand> commandsToRemove = new ArrayList<>();

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/providers/ViewProvider.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.eclipse.jface.resource.ImageDescriptor;
2424
import org.eclipse.ui.IWorkbenchWindow;
2525
import org.eclipse.ui.PlatformUI;
26+
import org.eclipse.ui.activities.IActivityManager;
27+
import org.eclipse.ui.activities.IIdentifier;
2628
import org.eclipse.ui.activities.WorkbenchActivityHelper;
2729
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
2830
import org.eclipse.ui.internal.WorkbenchImages;
@@ -39,6 +41,11 @@
3941
*/
4042
public class ViewProvider extends QuickAccessProvider {
4143

44+
/**
45+
* URI of any view on the platform has this prefix. ex:
46+
* bundleclass://org.eclipse.pde.spy.bundle/org.eclipse.pde.spy.bundle.BundleSpyPart
47+
*/
48+
private static final String BUNDLE_CLASS_SCHEME = "bundleclass://"; //$NON-NLS-1$
4249
private MApplication application;
4350
private MWindow window;
4451
private Map<String, QuickAccessElement> idToElement = new HashMap<>();
@@ -69,6 +76,7 @@ public QuickAccessElement[] getElements() {
6976
}
7077

7178
if (idToElement.isEmpty()) {
79+
IActivityManager activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
7280
for (MPartDescriptor descriptor : application.getDescriptors()) {
7381
String uri = descriptor.getContributionURI();
7482
if (uri != null) {
@@ -85,7 +93,15 @@ public QuickAccessElement[] getElements() {
8593
idToElement.put(element.getId(), element);
8694
}
8795
} else {
88-
idToElement.put(id, element);
96+
if (uri.startsWith(BUNDLE_CLASS_SCHEME)) {
97+
String viewQualUri = uri.substring(BUNDLE_CLASS_SCHEME.length());
98+
IIdentifier identifier = activityManager.getIdentifier(viewQualUri);
99+
if (identifier.isEnabled()) {
100+
idToElement.put(element.getId(), element);
101+
}
102+
} else {
103+
idToElement.put(element.getId(), element);
104+
}
89105
}
90106
}
91107
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Advantest Europe GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Raghunandana Murthappa
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.util;
15+
import org.eclipse.e4.ui.activitysupport.EActivityManager;
16+
import org.eclipse.ui.PlatformUI;
17+
import org.eclipse.ui.activities.IActivityManager;
18+
import org.osgi.service.component.annotations.Component;
19+
20+
@Component(service = { EActivityManager.class })
21+
public class ActivityManagerProxy implements EActivityManager {
22+
23+
private final IActivityManager activityManager;
24+
25+
public ActivityManagerProxy() {
26+
activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
27+
}
28+
29+
@Override
30+
public boolean isIdentifierEnabled(String identifierId) {
31+
boolean isEnabled = activityManager.getIdentifier(identifierId).isEnabled();
32+
return isEnabled;
33+
}
34+
}

docs/Eclipse4_RCP_EAS_List_of_All_Provided_Services.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Application Context
6969
* org.eclipse.ui.ISharedImages
7070
* org.eclipse.ui.progress.IProgressService
7171
* org.eclipse.e4.ui.services.help.EHelpService
72+
* org.eclipse.e4.ui.activitysupport.EActivityManager
7273

7374
### Runtime Data
7475

0 commit comments

Comments
 (0)