Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 224912 Details for
Bug 366528
[Compatibility] Implement IMenuService#populateContributionManager(*)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Partial patch 3 (previous one was not taking all my changes into account, sorry...)
mbarbero_366528_2.patch (text/plain), 15.73 KB, created by
Mikaël Barbero
on 2012-12-19 08:10:42 EST
(
hide
)
Description:
Partial patch 3 (previous one was not taking all my changes into account, sorry...)
Filename:
MIME Type:
Creator:
Mikaël Barbero
Created:
2012-12-19 08:10:42 EST
Size:
15.73 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >index f1d953a..df3e0b1 100644 >--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >@@ -289,7 +289,7 @@ public class ToolBarManagerRenderer extends SWTPartRenderer { > /** > * @param element > */ >- private void processContribution(MToolBar toolbarModel) { >+ public void processContribution(MToolBar toolbarModel) { > final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); > ContributionsAnalyzer.XXXgatherToolBarContributions(toolbarModel, > application.getToolBarContributions(), >diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java >index 39a1a89..e664d42 100644 >--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java >+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java >@@ -2687,6 +2687,7 @@ UIEvents.Context.TOPIC_CONTEXT, > cancelEarlyStartup(); > if (workbenchService != null) > workbenchService.unregister(); >+ workbenchService = null; > > // for dynamic UI > Platform.getExtensionRegistry().removeRegistryChangeListener(extensionEventHandler); >diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java >index 690af33..2ad5642 100755 >--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java >+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java >@@ -11,7 +11,9 @@ > > package org.eclipse.ui.internal.menus; > >+import java.util.ArrayList; > import java.util.HashMap; >+import java.util.List; > import java.util.Map; > import java.util.Set; > import org.eclipse.core.expressions.Expression; >@@ -19,61 +21,92 @@ import org.eclipse.core.expressions.IEvaluationContext; > import org.eclipse.e4.core.contexts.ContextFunction; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; >+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; > import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.ui.MElementContainer; >+import org.eclipse.e4.ui.model.application.ui.MUIElement; >+import org.eclipse.e4.ui.model.application.ui.basic.MPart; >+import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; > import org.eclipse.e4.ui.workbench.renderers.swt.ContributionRecord; >+import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer; > import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord; >+import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer; >+import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; > import org.eclipse.jface.action.ContributionManager; > import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.action.ToolBarManager; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Menu; > import org.eclipse.ui.ISourceProvider; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.internal.WorkbenchWindow; > import org.eclipse.ui.internal.e4.compatibility.E4Util; >+import org.eclipse.ui.internal.services.IWorkbenchLocationService; > import org.eclipse.ui.internal.services.ServiceLocator; > import org.eclipse.ui.menus.AbstractContributionFactory; > import org.eclipse.ui.menus.IMenuService; > > /** > * @since 3.5 >- * >+ * > */ > public class WorkbenchMenuService implements IMenuService { > > private IEclipseContext e4Context; >- // private ServiceLocator serviceLocator; >+ private ServiceLocator serviceLocator; > private ExpressionContext legacyContext; > private MenuPersistence persistence; > private Map<AbstractContributionFactory, Object> factoriesToContributions = new HashMap<AbstractContributionFactory, Object>(); >+ private IWorkbenchWindow window; >+ >+ private Map<ContributionManager, MenuLocationURI> managers = new HashMap<ContributionManager, MenuLocationURI>(); > > /** > * @param serviceLocator > * @param e4Context > */ > public WorkbenchMenuService(ServiceLocator serviceLocator, IEclipseContext e4Context) { >- // this.serviceLocator = serviceLocator; >+ this.serviceLocator = serviceLocator; > this.e4Context = e4Context; > > persistence = new MenuPersistence(e4Context.get(MApplication.class), e4Context); > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse.ui.ISourceProvider) >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse >+ * .ui.ISourceProvider) > */ > public void addSourceProvider(ISourceProvider provider) { > // TODO Auto-generated method stub > > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.services.IServiceWithSources#removeSourceProvider(org.eclipse.ui.ISourceProvider) >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.services.IServiceWithSources#removeSourceProvider(org. >+ * eclipse.ui.ISourceProvider) > */ > public void removeSourceProvider(ISourceProvider provider) { > // TODO Auto-generated method stub > > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.ui.services.IDisposable#dispose() > */ > public void dispose() { >@@ -84,8 +117,12 @@ public class WorkbenchMenuService implements IMenuService { > return location.getScheme().startsWith("toolbar"); //$NON-NLS-1$ > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.menus.IMenuService#addContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory) >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.menus.IMenuService#addContributionFactory(org.eclipse. >+ * ui.menus.AbstractContributionFactory) > */ > public void addContributionFactory(final AbstractContributionFactory factory) { > MenuLocationURI location = new MenuLocationURI(factory.getLocation()); >@@ -133,6 +170,17 @@ public class WorkbenchMenuService implements IMenuService { > factoriesToContributions.put(factory, menuContribution); > MApplication app = e4Context.get(MApplication.class); > app.getMenuContributions().add(menuContribution); >+ >+ // OK, now update any managers that use this uri >+ for (Map.Entry<ContributionManager, MenuLocationURI> entry : managers.entrySet()) { >+ MenuLocationURI mgrURI = entry.getValue(); >+ if (mgrURI.getScheme().equals(location.getScheme()) >+ && mgrURI.getPath().equals(location.getPath())) { >+ ContributionManager mgr = entry.getKey(); >+ populateContributionManager(mgr, mgrURI.toString()); >+ mgr.update(true); >+ } >+ } > } > > private void processToolbarChildren(AbstractContributionFactory factory, >@@ -151,8 +199,12 @@ public class WorkbenchMenuService implements IMenuService { > app.getToolBarContributions().add(toolBarContribution); > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory) >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse >+ * .ui.menus.AbstractContributionFactory) > */ > public void removeContributionFactory(AbstractContributionFactory factory) { > Object contribution; >@@ -166,25 +218,208 @@ public class WorkbenchMenuService implements IMenuService { > app.getToolBarContributions().remove(contribution); > } > } >+ >+ // OK, now remove any managers that use this uri >+ MenuLocationURI location = new MenuLocationURI(factory.getLocation()); >+ List<ContributionManager> toRemove = new ArrayList<ContributionManager>(); >+ for (Map.Entry<ContributionManager, MenuLocationURI> entry : managers.entrySet()) { >+ MenuLocationURI mgrURI = entry.getValue(); >+ if (mgrURI.getScheme().equals(location.getScheme()) >+ && mgrURI.getPath().equals(location.getPath())) { >+ toRemove.add(entry.getKey()); >+ } >+ } >+ for (ContributionManager mgr : toRemove) { >+ mgr.removeAll(); >+ managers.remove(mgr); >+ } >+ } >+ >+ protected IWorkbenchWindow getWindow() { >+ if (serviceLocator == null) >+ return null; >+ >+ IWorkbenchLocationService wls = (IWorkbenchLocationService) serviceLocator >+ .getService(IWorkbenchLocationService.class); >+ >+ if (window == null) { >+ window = wls.getWorkbenchWindow(); >+ } >+ if (window == null) { >+ IWorkbench wb = wls.getWorkbench(); >+ if (wb != null) { >+ window = wb.getActiveWorkbenchWindow(); >+ } >+ } >+ return window; > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.menus.IMenuService#populateContributionManager(org.eclipse.jface.action.ContributionManager, java.lang.String) >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.menus.IMenuService#populateContributionManager(org.eclipse >+ * .jface.action.ContributionManager, java.lang.String) > */ > public void populateContributionManager(ContributionManager mgr, String location) { >- // TODO Auto-generated method stub >+ MenuLocationURI uri = new MenuLocationURI(location); >+ // Track this call by recording the manager and location! >+ if (!managers.containsKey(mgr)) { >+ managers.put(mgr, uri); >+ } > >+ // Now handle registering dynamic additions by querying E4 model >+ if (mgr instanceof MenuManager) { >+ MenuManager menu = (MenuManager) mgr; >+ MMenu mMenu = getMenuModel(menu, uri); >+ >+ IRendererFactory factory = e4Context.get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(mMenu, null); >+ if (obj instanceof MenuManagerRenderer) { >+ MenuManagerRenderer renderer = (MenuManagerRenderer) obj; >+ mMenu.setRenderer(renderer); >+ renderer.reconcileManagerToModel(menu, mMenu); >+ renderer.processContributions(mMenu, false, false); >+ // double cast because we're bad people >+ renderer.processContents((MElementContainer<MUIElement>) ((Object) mMenu)); >+ } >+ } else if (mgr instanceof ToolBarManager) { >+ ToolBarManager toolbar = (ToolBarManager) mgr; >+ MToolBar mToolBar = getToolbarModel(toolbar, uri); >+ >+ IRendererFactory factory = e4Context.get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(mToolBar, null); >+ if (obj instanceof ToolBarManagerRenderer) { >+ ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj; >+ mToolBar.setRenderer(renderer); >+ renderer.reconcileManagerToModel(toolbar, mToolBar); >+ renderer.processContribution(mToolBar); >+ // double cast because we're bad people >+ renderer.processContents((MElementContainer<MUIElement>) ((Object) mToolBar)); >+ } >+ } else { >+ System.err.println("Unhandled manager: " + mgr); //$NON-NLS-1$ >+ } > } > >- /* (non-Javadoc) >- * @see org.eclipse.ui.menus.IMenuService#releaseContributions(org.eclipse.jface.action.ContributionManager) >+ protected MToolBar getToolbarModel(ToolBarManager toolbarManager, MenuLocationURI location) { >+ MToolBar mToolBar = null; >+ >+ MPart modelPart = getPartToExtend(toolbarManager.getControl()); >+ if (modelPart != null) { >+ mToolBar = modelPart.getToolbar(); >+ } else { >+ System.err.println("Can not register a ToolBarManager without a MPart"); //$NON-NLS-1$ >+ } >+ if (mToolBar == null) { >+ mToolBar = MenuFactoryImpl.eINSTANCE.createToolBar(); >+ mToolBar.setElementId(location.getPath()); >+ } >+ if (modelPart != null) { >+ modelPart.setToolbar(mToolBar); >+ } >+ >+ IRendererFactory factory = e4Context.get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(mToolBar, null); >+ if (obj instanceof ToolBarManagerRenderer) { >+ ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj; >+ renderer.linkModelToManager(mToolBar, toolbarManager); >+ } >+ >+ return mToolBar; >+ } >+ >+ protected MMenu getMenuModel(MenuManager menuManager, MenuLocationURI location) { >+ // FIXME See if we can find the already existing matching menu with this >+ // id? >+ if ("org.eclipse.ui.main.menu".equals(location.getPath())) //$NON-NLS-1$ >+ { >+ WorkbenchWindow workbenchWindow = (WorkbenchWindow) getWindow(); >+ MWindow window = workbenchWindow.getModel(); >+ return window.getMainMenu(); >+ } >+ >+ MMenu mMenu = null; >+ >+ Menu menu = menuManager.getMenu(); >+ final MPart mPart = getPartToExtend(menu == null ? null : menu.getParent()); >+ if (mPart != null) { >+ for (MMenu mMenuIt : mPart.getMenus()) { >+ if (mMenuIt.getElementId().equals(menuManager.getId())) { >+ mMenu = mMenuIt; >+ } >+ } >+ } else { >+ System.err.println("Can not register a MenuManager without a MPart"); //$NON-NLS-1$ >+ } >+ if (mMenu == null) { >+ mMenu = MenuFactoryImpl.eINSTANCE.createMenu(); >+ mMenu.setElementId(menuManager.getId()); >+ if (mMenu.getElementId() == null) { >+ mMenu.setElementId(location.getPath()); >+ } >+ mMenu.getTags().add(ContributionsAnalyzer.MC_MENU); >+ mMenu.setLabel(menuManager.getMenuText()); >+ } >+ >+ if (mPart != null) { >+ mPart.getMenus().add(mMenu); >+ } >+ >+ // TODO Otherwise create one >+ // if ("popup".equals(location.getScheme())) { //$NON-NLS-1$ >+ // menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu(); >+ // menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP); >+ // } else { >+ >+ // } >+ >+ IRendererFactory factory = e4Context.get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(mMenu, null); >+ if (obj instanceof MenuManagerRenderer) { >+ MenuManagerRenderer renderer = (MenuManagerRenderer) obj; >+ renderer.linkModelToManager(mMenu, menuManager); >+ } >+ >+ return mMenu; >+ } >+ >+ private MPart getOwnerPart(Control control) { >+ return (MPart) control >+ .getData(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.OWNING_ME); >+ } >+ >+ private MPart getPartToExtend(Control control) { >+ MPart part = null; >+ if (control == null) { >+ // part = (MPart) e4Context.get(IServiceConstants.ACTIVE_PART); >+ } else { >+ Control currentControl = control; >+ MPart ownerPart = getOwnerPart(currentControl); >+ while (currentControl != null && ownerPart == null) { >+ currentControl = currentControl.getParent(); >+ ownerPart = getOwnerPart(currentControl); >+ } >+ part = ownerPart; >+ } >+ return part; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.menus.IMenuService#releaseContributions(org.eclipse.jface >+ * .action.ContributionManager) > */ > public void releaseContributions(ContributionManager mgr) { > // TODO Auto-generated method stub > > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.ui.menus.IMenuService#getCurrentState() > */ > public IEvaluationContext getCurrentState() { >@@ -214,7 +449,7 @@ public class WorkbenchMenuService implements IMenuService { > */ > public void registerVisibleWhen(IContributionItem item, Expression visibleWhen, > Set restriction, String createIdentifierId) { >- // TODO Auto-generated method stub >+ // TODO Remove - no longer used > > } > >@@ -223,7 +458,7 @@ public class WorkbenchMenuService implements IMenuService { > * @param restriction > */ > public void unregisterVisibleWhen(IContributionItem item, Set restriction) { >- // TODO Auto-generated method stub >+ // TODO Remove - no longer used > > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 366528
:
219171
|
224911
| 224912 |
225216
|
225598
|
232176