Skip to content

Commit 5fa25b1

Browse files
laeubiiloveeclipse
authored andcommitted
Consider Activity Filtering when running in E3 compatibility mode
Currently contributions by E4 are not filtered using the E3 activity mechanism as it is a pure E3 concept. To improve integration and interaction of E4 and E3 when using the compatibility layer this now installs a WorkbenchContributionFactory into the application context that additionally takes activity filtering of the E3 workbench into account. See #2217
1 parent 8c2be45 commit 5fa25b1

File tree

7 files changed

+108
-4
lines changed

7 files changed

+108
-4
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
@@ -7,7 +7,7 @@ Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Bundle-RequiredExecutionEnvironment: JavaSE-17
99
Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
10-
org.eclipse.e4.core.services;bundle-version="0.9.0",
10+
org.eclipse.e4.core.services;bundle-version="2.5.100",
1111
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
1212
org.eclipse.e4.core.di;bundle-version="1.1.0",
1313
org.eclipse.e4.ui.services;bundle-version="0.9.0",

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.e4.core.contexts.IContextFunction;
2121
import org.eclipse.e4.core.contexts.IEclipseContext;
2222
import org.eclipse.e4.core.di.annotations.Optional;
23+
import org.eclipse.e4.core.services.contributions.IContributionFactory;
2324
import org.eclipse.e4.core.services.log.Logger;
2425
import org.eclipse.e4.ui.internal.workbench.RenderedElementUtil;
2526
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
@@ -84,6 +85,9 @@ public abstract class AbstractContributionItem extends ContributionItem {
8485
@Optional
8586
protected EHelpService helpService;
8687

88+
@Inject
89+
protected IContributionFactory contributionFactory;
90+
8791
protected Widget widget;
8892
protected Listener menuItemListener;
8993
protected LocalResourceManager localResourceManager;
@@ -126,6 +130,15 @@ public void update(String id) {
126130
}
127131
}
128132

133+
@Override
134+
public boolean isVisible() {
135+
String contributorURI = modelItem.getContributorURI();
136+
if (contributorURI == null || contributionFactory.isEnabled(contributorURI)) {
137+
return super.isVisible();
138+
}
139+
return false;
140+
}
141+
129142
protected abstract void updateMenuItem();
130143

131144
protected abstract void updateToolItem();

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

Lines changed: 13 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.core.services.contributions.IContributionFactory;
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,15 @@ class DynamicContributionContributionItem extends ContributionItem {
2930

3031
private IMenuListener menuListener = IMenuManager::markDirty;
3132

33+
private IContributionFactory factory;
34+
3235
/**
3336
* Create the item and associated model;
3437
*/
35-
public DynamicContributionContributionItem(MDynamicMenuContribution item) {
38+
public DynamicContributionContributionItem(MDynamicMenuContribution item, IContributionFactory factory) {
3639
super(item.getElementId());
3740
model = item;
41+
this.factory = factory;
3842
}
3943

4044
@Override
@@ -54,6 +58,14 @@ public MDynamicMenuContribution getModel() {
5458
return model;
5559
}
5660

61+
@Override
62+
public boolean isVisible() {
63+
if (factory.isEnabled(model.getContributionURI())) {
64+
return super.isVisible();
65+
}
66+
return false;
67+
}
68+
5769
@Override
5870
public void setParent(IContributionManager parent) {
5971
if (getParent() instanceof IMenuManager) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.eclipse.e4.core.contexts.IEclipseContext;
4646
import org.eclipse.e4.core.contexts.RunAndTrack;
4747
import org.eclipse.e4.core.di.annotations.Optional;
48+
import org.eclipse.e4.core.services.contributions.IContributionFactory;
4849
import org.eclipse.e4.core.services.log.Logger;
4950
import org.eclipse.e4.ui.di.UIEventTopic;
5051
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
@@ -783,7 +784,8 @@ private void processDynamicMenuContribution(MenuManager menuManager, MDynamicMen
783784
return;
784785
}
785786
itemModel.setRenderer(this);
786-
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel);
787+
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel,
788+
application.getContext().get(IContributionFactory.class));
787789
addToManager(menuManager, itemModel, ci);
788790
linkModelToContribution(itemModel, ci);
789791
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4.0.0)",
100100
org.eclipse.jface.databinding;bundle-version="[1.3.0,2.0.0)",
101101
org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)",
102102
org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)",
103-
org.eclipse.e4.core.services;bundle-version="2.2.0",
103+
org.eclipse.e4.core.services;bundle-version="2.5.100",
104104
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
105105
org.eclipse.e4.core.di;bundle-version="1.1.0",
106106
org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.1",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ public void serviceChanged(ServiceEvent event) {
457457
* specializes this workbench instance
458458
* @since 3.0
459459
*/
460+
@SuppressWarnings("restriction")
460461
private Workbench(Display display, final WorkbenchAdvisor advisor, MApplication app, IEclipseContext appContext) {
461462
this.advisor = Objects.requireNonNull(advisor);
462463
this.display = Objects.requireNonNull(display);
@@ -492,6 +493,8 @@ public void eventLoopException(Throwable exception) {
492493
advisor.eventLoopException(exception);
493494
}
494495
});
496+
appContext.set(org.eclipse.e4.core.services.contributions.IContributionFactory.class,
497+
new WorkbenchContributionFactory(this));
495498

496499
// for dynamic UI [This seems to be for everything that isn't handled by
497500
// some
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Christoph Läubrich 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+
* Christoph Läubrich - initial API and implementation
13+
*******************************************************************************/
14+
15+
package org.eclipse.ui.internal;
16+
17+
import org.eclipse.e4.core.contexts.IEclipseContext;
18+
import org.eclipse.e4.core.services.contributions.IContributionFactory;
19+
import org.eclipse.ui.activities.IIdentifier;
20+
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
21+
import org.osgi.framework.Bundle;
22+
23+
/**
24+
* Contribution factory that uses a delegate and additionally provides behavior
25+
* from the {@link Workbench} services.
26+
*
27+
*/
28+
@SuppressWarnings("restriction")
29+
class WorkbenchContributionFactory implements IContributionFactory {
30+
31+
private static final String BUNDLE_CLASS_PREFIX = "bundleclass://"; //$NON-NLS-1$
32+
33+
private final IContributionFactory delegate;
34+
35+
private final IEclipseContext context;
36+
37+
private IWorkbenchActivitySupport activitySupport;
38+
39+
WorkbenchContributionFactory(Workbench workbench) {
40+
context = workbench.getApplication().getContext();
41+
delegate = context.get(IContributionFactory.class);
42+
}
43+
44+
@Override
45+
public Object create(String uriString, IEclipseContext context) {
46+
return delegate.create(uriString, context);
47+
}
48+
49+
@Override
50+
public Object create(String uriString, IEclipseContext context, IEclipseContext staticContext) {
51+
return delegate.create(uriString, context, staticContext);
52+
}
53+
54+
@Override
55+
public Bundle getBundle(String uriString) {
56+
return delegate.getBundle(uriString);
57+
}
58+
59+
@Override
60+
public boolean isEnabled(String uriString) {
61+
if (uriString != null && uriString.startsWith(BUNDLE_CLASS_PREFIX)) {
62+
String identifierId = uriString.substring(BUNDLE_CLASS_PREFIX.length());
63+
if (activitySupport == null) {
64+
activitySupport = context.get(IWorkbenchActivitySupport.class);
65+
}
66+
IIdentifier identifier = activitySupport.getActivityManager().getIdentifier(identifierId);
67+
if (!identifier.isEnabled()) {
68+
return false;
69+
}
70+
}
71+
return delegate.isEnabled(uriString);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)