Skip to content

Commit 39d5b25

Browse files
committed
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 cc770ec commit 39d5b25

File tree

7 files changed

+124
-7
lines changed

7 files changed

+124
-7
lines changed

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.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
}

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.15.500.qualifier
4+
Bundle-Version: 1.16.0.qualifier
55
Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
@@ -33,7 +33,8 @@ Export-Package: org.eclipse.e4.ui.internal.workbench;
3333
org.eclipse.e4.ui.internal.workbench.handlers;x-internal:=true,
3434
org.eclipse.e4.ui.workbench,
3535
org.eclipse.e4.ui.workbench.lifecycle,
36-
org.eclipse.e4.ui.workbench.modeling
36+
org.eclipse.e4.ui.workbench.modeling,
37+
org.eclipse.ui.activitysupport
3738
Bundle-Activator: org.eclipse.e4.ui.internal.workbench.Activator
3839
Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)",
3940
jakarta.inject;version="[2.0.0,3.0.0)",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.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.16
25+
*/
26+
public interface IActivityManagerProxy {
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
35+
*/
36+
public boolean isIdentifierEnabled(String identifierId);
37+
}

bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
8888
import org.eclipse.ui.progress.IProgressService;
8989
import org.eclipse.ui.statushandlers.AbstractStatusHandler;
90-
import org.eclipse.urischeme.AutoRegisterSchemeHandlersJob;
9190
import org.osgi.framework.Bundle;
9291
import org.osgi.framework.FrameworkUtil;
9392
import org.osgi.framework.ServiceReference;
@@ -226,9 +225,9 @@ public void initialize(IWorkbenchConfigurer configurer) {
226225
jfaceComparatorIsSet = true;
227226
}
228227

229-
if (!Platform.inDevelopmentMode() && !JUnitTestUtil.isJunitTestRunning()) {
230-
new AutoRegisterSchemeHandlersJob().schedule();
231-
}
228+
// if (!Platform.inDevelopmentMode() && !JUnitTestUtil.isJunitTestRunning()) {
229+
// new AutoRegisterSchemeHandlersJob().schedule();
230+
// }
232231
}
233232

234233
protected void initResourceTracking() {

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
@@ -186,6 +186,7 @@
186186
import org.eclipse.ui.WorkbenchException;
187187
import org.eclipse.ui.XMLMemento;
188188
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
189+
import org.eclipse.ui.activitysupport.IActivityManagerProxy;
189190
import org.eclipse.ui.application.WorkbenchAdvisor;
190191
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
191192
import org.eclipse.ui.commands.ICommandImageService;
@@ -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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
16+
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
17+
import org.eclipse.ui.activitysupport.IActivityManagerProxy;
18+
19+
public class ActivityManagerProxy implements IActivityManagerProxy {
20+
21+
private IWorkbenchActivitySupport wbActivitySupport;
22+
23+
public ActivityManagerProxy(IWorkbenchActivitySupport wbActivitySupport) {
24+
this.wbActivitySupport = wbActivitySupport;
25+
}
26+
27+
@Override
28+
public boolean isIdentifierEnabled(String identifierId) {
29+
boolean isEnabled = wbActivitySupport.getActivityManager().getIdentifier(identifierId).isEnabled();
30+
return isEnabled;
31+
}
32+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.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.15.500"
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)",

0 commit comments

Comments
 (0)