Skip to content

Commit 57adcf5

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. see #2217
1 parent c9b34e4 commit 57adcf5

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
2323
org.eclipse.emf.ecore;bundle-version="2.35.0",
2424
org.eclipse.e4.ui.css.swt;bundle-version="0.11.0",
2525
org.eclipse.e4.core.di.extensions;bundle-version="0.12.0",
26-
org.eclipse.core.runtime;bundle-version="3.29.0"
26+
org.eclipse.core.runtime;bundle-version="3.29.0",
27+
org.eclipse.e4.ui.workbench3;bundle-version="0.17.400"
2728
Export-Package: org.eclipse.e4.ui.internal.workbench.renderers.swt;x-friends:="org.eclipse.ui.workbench",
2829
org.eclipse.e4.ui.workbench.renderers.swt;x-friends:="org.eclipse.e4.ui.workbench.addons.swt,org.eclipse.ui.workbench"
2930
Bundle-ActivationPolicy: lazy

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414

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

17+
import org.eclipse.core.runtime.Platform;
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;
2021
import org.eclipse.jface.action.IMenuListener;
2122
import org.eclipse.jface.action.IMenuManager;
23+
import org.eclipse.ui.internal.activitysupport.IActivityManagerProxy;
24+
import org.osgi.framework.BundleContext;
25+
import org.osgi.framework.FrameworkUtil;
26+
import org.osgi.util.tracker.ServiceTracker;
2227

2328
/**
2429
* This item currently serves as a placeholder to determine the correct location
@@ -29,12 +34,17 @@ class DynamicContributionContributionItem extends ContributionItem {
2934

3035
private IMenuListener menuListener = IMenuManager::markDirty;
3136

37+
private static final String BUNDLE_CLASS_PREFIX = "bundleclass://"; //$NON-NLS-1$
38+
39+
IActivityManagerProxy activitySupportProxy;
40+
3241
/**
3342
* Create the item and associated model;
3443
*/
3544
public DynamicContributionContributionItem(MDynamicMenuContribution item) {
3645
super(item.getElementId());
3746
model = item;
47+
initializeAcivitySupportProxy();
3848
}
3949

4050
@Override
@@ -66,4 +76,34 @@ public void setParent(IContributionManager parent) {
6676
}
6777
super.setParent(parent);
6878
}
79+
80+
@Override
81+
public boolean isVisible() {
82+
if (this.activitySupportProxy != null) {
83+
// Contribution URI has the scheme bundleclass://. Ex:
84+
// bundleclass://org.eclipse.pde.spy.core/org.eclipse.pde.spy.core.SpyProcessor
85+
String contributionURI = this.getModel().getContributionURI();
86+
if (contributionURI.startsWith(BUNDLE_CLASS_PREFIX)) {
87+
return activitySupportProxy
88+
.isIdentifierEnabled(contributionURI.substring(BUNDLE_CLASS_PREFIX.length()));
89+
}
90+
}
91+
return true;
92+
}
93+
94+
/**
95+
* Initialize the Activity Support proxy from Platform Context
96+
*/
97+
private void initializeAcivitySupportProxy() {
98+
BundleContext context = FrameworkUtil.getBundle(Platform.class).getBundleContext();
99+
if (context != null) {
100+
ServiceTracker<IActivityManagerProxy, IActivityManagerProxy> tracker = new ServiceTracker<>(context,
101+
IActivityManagerProxy.class, null);
102+
if (tracker != null) {
103+
tracker.open();
104+
this.activitySupportProxy = tracker.getService();
105+
tracker.close();
106+
}
107+
}
108+
}
69109
}
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.workbench3;singleton:=true
4-
Bundle-Version: 0.17.400.qualifier
4+
Bundle-Version: 0.18.0.qualifier
55
Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
@@ -10,6 +10,7 @@ Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.7.0,4.0.0)",
1010
org.eclipse.swt;bundle-version="[3.6.0,4.0.0)",
1111
org.eclipse.equinox.registry;bundle-version="[3.5.0,4.0.0)",
1212
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)"
13-
Export-Package: org.eclipse.ui.testing,
13+
Export-Package: org.eclipse.ui.internal.activitysupport,
14+
org.eclipse.ui.testing,
1415
org.eclipse.ui.testing.dumps
1516
Automatic-Module-Name: org.eclipse.e4.ui.workbench3
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.eclipse.ui.internal.activitysupport;
2+
3+
/**
4+
* A bridge between org.eclipse.ui.workbenk and
5+
* org.eclipse.e4.ui.workbench.renderers.swt.
6+
*
7+
* Service for this interface is bound to Platform.class bundle at
8+
* Workbench.class. We cannot depend on org.eclipse.ui.workbench from
9+
* org.eclipse.e4.ui.workbench.renderers.swt
10+
*
11+
* @since 0.18
12+
*/
13+
public interface IActivityManagerProxy {
14+
/**
15+
* Checks whether the given element is enabled or not in the workbench activity
16+
* support.
17+
*
18+
* @param identifierId A qualified id if the contribution. Which has format of
19+
* bundle-id/element. Ex:
20+
* org.eclipse.pde.spy.core/org.eclipse.pde.spy.core.SpyProcessor
21+
* @return
22+
*/
23+
public boolean isIdentifierEnabled(String identifierId);
24+
}

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
import org.eclipse.ui.internal.WorkbenchWindow.WWinPartServiceSaveHandler;
199199
import org.eclipse.ui.internal.actions.CommandAction;
200200
import org.eclipse.ui.internal.activities.ws.WorkbenchActivitySupport;
201+
import org.eclipse.ui.internal.activitysupport.IActivityManagerProxy;
201202
import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport;
202203
import org.eclipse.ui.internal.commands.CommandImageManager;
203204
import org.eclipse.ui.internal.commands.CommandImageService;
@@ -241,6 +242,7 @@
241242
import org.eclipse.ui.internal.themes.FontDefinition;
242243
import org.eclipse.ui.internal.themes.ThemeElementHelper;
243244
import org.eclipse.ui.internal.themes.WorkbenchThemeManager;
245+
import org.eclipse.ui.internal.util.ActivityManagerProxy;
244246
import org.eclipse.ui.internal.util.PrefUtil;
245247
import org.eclipse.ui.intro.IIntroManager;
246248
import org.eclipse.ui.keys.IBindingService;
@@ -2173,6 +2175,11 @@ public Object compute(IEclipseContext context, String contextKey) {
21732175
}
21742176
});
21752177
WorkbenchPlugin.getDefault().initializeContext(e4Context);
2178+
2179+
BundleContext context = FrameworkUtil.getBundle(Platform.class).getBundleContext();
2180+
IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
2181+
ActivityManagerProxy service = new ActivityManagerProxy(activitySupport);
2182+
context.registerService(IActivityManagerProxy.class.getName(), service, null);
21762183
}
21772184

21782185
private ArrayList<MCommand> commandsToRemove = new ArrayList<>();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.eclipse.ui.internal.util;
2+
3+
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
4+
import org.eclipse.ui.internal.activitysupport.IActivityManagerProxy;
5+
6+
/**
7+
* @since 3.5
8+
*
9+
*/
10+
public class ActivityManagerProxy implements IActivityManagerProxy {
11+
12+
private IWorkbenchActivitySupport wbActivitySupport;
13+
14+
public ActivityManagerProxy(IWorkbenchActivitySupport wbActivitySupport) {
15+
this.wbActivitySupport = wbActivitySupport;
16+
}
17+
18+
@Override
19+
public boolean isIdentifierEnabled(String identifierId) {
20+
boolean isEnabled = wbActivitySupport.getActivityManager().getIdentifier(identifierId).isEnabled();
21+
return isEnabled;
22+
}
23+
}

0 commit comments

Comments
 (0)