Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider Activity Filtering when running in E3 compatibility mode #2768

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
org.eclipse.e4.core.services;bundle-version="0.9.0",
org.eclipse.e4.core.services;bundle-version="2.5.100",
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
org.eclipse.e4.core.di;bundle-version="1.1.0",
org.eclipse.e4.ui.services;bundle-version="0.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.internal.workbench.RenderedElementUtil;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
Expand Down Expand Up @@ -84,6 +85,9 @@ public abstract class AbstractContributionItem extends ContributionItem {
@Optional
protected EHelpService helpService;

@Inject
protected IContributionFactory contributionFactory;

protected Widget widget;
protected Listener menuItemListener;
protected LocalResourceManager localResourceManager;
Expand Down Expand Up @@ -126,6 +130,15 @@ public void update(String id) {
}
}

@Override
public boolean isVisible() {
String contributorURI = modelItem.getContributorURI();
if (contributorURI == null || contributionFactory.isEnabled(contributorURI)) {
return super.isVisible();
}
return false;
}

protected abstract void updateMenuItem();

protected abstract void updateToolItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IContributionManager;
Expand All @@ -29,12 +30,15 @@ class DynamicContributionContributionItem extends ContributionItem {

private IMenuListener menuListener = IMenuManager::markDirty;

private IContributionFactory factory;

/**
* Create the item and associated model;
*/
public DynamicContributionContributionItem(MDynamicMenuContribution item) {
public DynamicContributionContributionItem(MDynamicMenuContribution item, IContributionFactory factory) {
super(item.getElementId());
model = item;
this.factory = factory;
}

@Override
Expand All @@ -54,6 +58,14 @@ public MDynamicMenuContribution getModel() {
return model;
}

@Override
public boolean isVisible() {
if (factory.isEnabled(model.getContributionURI())) {
return super.isVisible();
}
return false;
}

@Override
public void setParent(IContributionManager parent) {
if (getParent() instanceof IMenuManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
Expand Down Expand Up @@ -783,7 +784,8 @@ private void processDynamicMenuContribution(MenuManager menuManager, MDynamicMen
return;
}
itemModel.setRenderer(this);
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel);
DynamicContributionContributionItem ci = new DynamicContributionContributionItem(itemModel,
application.getContext().get(IContributionFactory.class));
addToManager(menuManager, itemModel, ci);
linkModelToContribution(itemModel, ci);
}
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.33.0,4.0.0)",
org.eclipse.jface.databinding;bundle-version="[1.3.0,2.0.0)",
org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)",
org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)",
org.eclipse.e4.core.services;bundle-version="2.2.0",
org.eclipse.e4.core.services;bundle-version="2.5.100",
org.eclipse.e4.core.contexts;bundle-version="1.0.0",
org.eclipse.e4.core.di;bundle-version="1.1.0",
org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public void serviceChanged(ServiceEvent event) {
* specializes this workbench instance
* @since 3.0
*/
@SuppressWarnings("restriction")
private Workbench(Display display, final WorkbenchAdvisor advisor, MApplication app, IEclipseContext appContext) {
this.advisor = Objects.requireNonNull(advisor);
this.display = Objects.requireNonNull(display);
Expand Down Expand Up @@ -492,6 +493,8 @@ public void eventLoopException(Throwable exception) {
advisor.eventLoopException(exception);
}
});
appContext.set(org.eclipse.e4.core.services.contributions.IContributionFactory.class,
new WorkbenchContributionFactory(this));

// for dynamic UI [This seems to be for everything that isn't handled by
// some
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/

package org.eclipse.ui.internal;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.ui.activities.IIdentifier;
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
import org.osgi.framework.Bundle;

/**
* Contribution factory that uses a delegate and additionally provides behavior
* from the {@link Workbench} services.
*
*/
@SuppressWarnings("restriction")
class WorkbenchContributionFactory implements IContributionFactory {

private static final String BUNDLE_CLASS_PREFIX = "bundleclass://"; //$NON-NLS-1$

private final IContributionFactory delegate;

private final IEclipseContext context;

private IWorkbenchActivitySupport activitySupport;

WorkbenchContributionFactory(Workbench workbench) {
context = workbench.getApplication().getContext();
delegate = context.get(IContributionFactory.class);
}

@Override
public Object create(String uriString, IEclipseContext context) {
return delegate.create(uriString, context);
}

@Override
public Object create(String uriString, IEclipseContext context, IEclipseContext staticContext) {
return delegate.create(uriString, context, staticContext);
}

@Override
public Bundle getBundle(String uriString) {
return delegate.getBundle(uriString);
}

@Override
public boolean isEnabled(String uriString) {
if (uriString != null && uriString.startsWith(BUNDLE_CLASS_PREFIX)) {
String identifierId = uriString.substring(BUNDLE_CLASS_PREFIX.length());
if (activitySupport == null) {
activitySupport = context.get(IWorkbenchActivitySupport.class);
}
IIdentifier identifier = activitySupport.getActivityManager().getIdentifier(identifierId);
if (!identifier.isEnabled()) {
return false;
}
}
return delegate.isEnabled(uriString);
}

}
Loading