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 180901 Details for
Bug 325392
Render menu contributions using the ContributionManagers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Revert renderer changes for I build
revertRenderer-v01.txt (text/plain), 214.31 KB, created by
Paul Webster
on 2010-10-14 14:22:12 EDT
(
hide
)
Description:
Revert renderer changes for I build
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2010-10-14 14:22:12 EDT
Size:
214.31 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.ui.tests >Index: src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java,v >retrieving revision 1.8 >diff -u -r1.8 MMenuItemTest.java >--- src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java 8 Oct 2010 12:03:06 -0000 1.8 >+++ src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java 14 Oct 2010 18:20:37 -0000 >@@ -36,13 +36,9 @@ > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.workbench.renderers.swt.MenuRenderer; > import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; >-import org.eclipse.jface.action.IContributionItem; >-import org.eclipse.jface.action.MenuManager; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.MenuItem; >-import org.eclipse.swt.widgets.Widget; > > public class MMenuItemTest extends TestCase { > protected IEclipseContext appContext; >@@ -86,8 +82,6 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); >- > Object widget = menuItem.getWidget(); > assertNotNull(widget); > assertTrue(widget instanceof MenuItem); >@@ -163,8 +157,6 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); >- > Object widget1 = menuItem1.getWidget(); > assertNotNull(widget1); > assertTrue(widget1 instanceof MenuItem); >@@ -220,8 +212,6 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- ((MenuManager) ((Widget) menu.getWidget()).getData()).updateAll(true); >- > Object widget1 = menuItem.getWidget(); > assertNotNull(widget1); > assertTrue(widget1 instanceof MenuItem); >@@ -238,6 +228,7 @@ > MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand(); > > command.setElementId("commandId"); >+ command.setCommandName("CommandForTest"); > > menuItem.setCommand(command); > menuItem.setType(ItemType.CHECK); >@@ -249,16 +240,13 @@ > MApplication application = ApplicationFactoryImpl.eINSTANCE > .createApplication(); > application.getChildren().add(window); >+ application.getCommands().add(command); > application.setContext(appContext); > appContext.set(MApplication.class.getName(), application); > > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuManager barManager = (MenuManager) ((Menu) menu.getWidget()) >- .getData(); >- barManager.updateAll(true); >- > Object widget1 = menuItem.getWidget(); > assertNotNull(widget1); > assertTrue(widget1 instanceof MenuItem); >@@ -267,7 +255,7 @@ > assertTrue(menuItemWidget.getSelection()); > } > >- public void testSubMenuCreation() throws Exception { >+ public void XXXtestSubMenuCreation() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -301,20 +289,9 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- MenuManager manager = renderer.getManager(menuBar); >- assertNotNull("failed to create menu bar manager", manager); >- >- assertEquals(1, manager.getSize()); >- >- MenuManager fileManager = (MenuManager) manager.getItems()[0]; >- MenuManager fileR = renderer.getManager(fileMenu); >- assertEquals(fileManager, fileR); >- >- assertEquals(3, fileManager.getSize()); > } > >- public void testTbrItem() throws Exception { >+ public void XXXtestTbrItem() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -349,20 +326,11 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- MenuManager manager = renderer.getManager(menuBar); >- assertNotNull("failed to create menu bar manager", manager); >- >- assertEquals(1, manager.getSize()); >- >- MenuManager fileManager = (MenuManager) manager.getItems()[0]; >- MenuManager fileR = renderer.getManager(fileMenu); >- assertEquals(fileManager, fileR); >+ // MenuRenderer renderer = getRenderer(appContext, menuBar); > >- assertEquals(2, fileManager.getSize()); > } > >- public void testInvisibleItem() throws Exception { >+ public void XXXtestInvisibleItem() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -397,22 +365,11 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- MenuManager manager = renderer.getManager(menuBar); >- assertNotNull("failed to create menu bar manager", manager); >- >- assertEquals(1, manager.getSize()); >- >- MenuManager fileManager = (MenuManager) manager.getItems()[0]; >- MenuManager fileR = renderer.getManager(fileMenu); >- assertEquals(fileManager, fileR); >+ // MenuRenderer renderer = getRenderer(appContext, menuBar); > >- assertEquals(3, fileManager.getSize()); >- >- assertEquals(false, fileManager.getItems()[2].isVisible()); > } > >- public void testMenuContribution() throws Exception { >+ public void XXXtestMenuContribution() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -447,17 +404,9 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- >- MenuManager fileManager = renderer.getManager(fileMenu); >- assertNotNull("No file menu?", fileManager); >- >- assertEquals(4, fileManager.getSize()); >- >- assertEquals("mmc.item1", fileManager.getItems()[3].getId()); > } > >- public void testWithVisible() throws Exception { >+ public void XXXtestWithVisible() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -492,59 +441,9 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- >- MenuManager fileManager = renderer.getManager(fileMenu); >- assertNotNull("No file menu?", fileManager); >- >- assertEquals(4, fileManager.getSize()); >- >- IContributionItem mmcItem = fileManager.getItems()[3]; >- assertEquals("mmc.item1", mmcItem.getId()); >- assertEquals("before the first show, we have no context to evaluate", >- true, mmcItem.isVisible()); >- >- MenuManager manager = renderer.getManager(menuBar); >- manager.updateAll(true); >- Menu fileWidget = fileManager.getMenu(); >- assertNotNull(fileWidget); >- >- Event show = new Event(); >- show.widget = fileWidget; >- show.type = SWT.Show; >- >- Event hide = new Event(); >- hide.widget = fileWidget; >- hide.type = SWT.Hide; >- >- fileWidget.notifyListeners(SWT.Show, show); >- >- assertEquals("after the first show, it should not be visible", false, >- mmcItem.isVisible()); >- >- fileWidget.notifyListeners(SWT.Hide, hide); >- >- appContext.set("mmc1", Boolean.TRUE); >- >- assertEquals("Change should not show up until next show", false, >- mmcItem.isVisible()); >- >- fileWidget.notifyListeners(SWT.Show, show); >- >- assertEquals(true, mmcItem.isVisible()); >- >- fileWidget.notifyListeners(SWT.Hide, hide); >- >- appContext.remove("mmc1"); >- >- fileWidget.notifyListeners(SWT.Show, show); >- >- assertEquals(false, mmcItem.isVisible()); >- >- fileWidget.notifyListeners(SWT.Hide, hide); > } > >- public void testMenuBarVisibility() throws Exception { >+ public void XXXtestMenuBarVisibility() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -579,36 +478,6 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- MenuRenderer renderer = getRenderer(appContext, menuBar); >- MenuManager manager = renderer.getManager(menuBar); >- manager.updateAll(true); >- >- assertEquals(2, manager.getSize()); >- >- MenuManager vanishManager = (MenuManager) manager.getItems()[1]; >- assertEquals("vanish", vanishManager.getId()); >- >- assertFalse(vanishManager.isVisible()); >- assertNull(vanishManager.getMenu()); >- >- appContext.set("mmc1", Boolean.TRUE); >- >- assertTrue(vanishManager.isVisible()); >- assertNotNull(vanishManager.getMenu()); >- >- appContext.remove("mmc1"); >- >- assertFalse(vanishManager.isVisible()); >- Menu vanishMenu = vanishManager.getMenu(); >- if (vanishMenu != null) { >- assertTrue(vanishMenu.isDisposed()); >- } >- >- appContext.set("mmc1", Boolean.TRUE); >- >- assertTrue(vanishManager.isVisible()); >- assertNotNull(vanishManager.getMenu()); >- assertFalse(vanishManager.getMenu().isDisposed()); > } > > private MMenuContribution createContribution(boolean withVisibleWhen) { >@@ -668,7 +537,7 @@ > application.getMenuContributions().add(mmc); > } > >- private MenuRenderer getRenderer(IEclipseContext context, MUIElement element) { >+ MenuRenderer getRenderer(IEclipseContext context, MUIElement element) { > IRendererFactory rendererFactory = context.get(IRendererFactory.class); > AbstractPartRenderer renderer = rendererFactory.getRenderer(element, > null); >Index: src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java,v >retrieving revision 1.44 >diff -u -r1.44 MWindowTest.java >--- src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java 8 Oct 2010 12:03:06 -0000 1.44 >+++ src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java 14 Oct 2010 18:20:37 -0000 >@@ -30,7 +30,6 @@ > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.services.IServiceConstants; > import org.eclipse.e4.ui.widgets.CTabFolder; >-import org.eclipse.jface.action.MenuManager; > import org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Composite; >@@ -231,8 +230,6 @@ > > wb = new E4Workbench(application, appContext); > wb.createAndRunUI(window); >- ((MenuManager) ((Widget) window.getMainMenu().getWidget()).getData()) >- .updateAll(true); > > Widget topWidget = (Widget) window.getWidget(); > assertNotNull(topWidget); >#P org.eclipse.e4.ui.workbench >Index: src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java,v >retrieving revision 1.17 >diff -u -r1.17 ContributionsAnalyzer.java >--- src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java 8 Oct 2010 14:27:52 -0000 1.17 >+++ src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java 14 Oct 2010 18:20:37 -0000 >@@ -70,7 +70,7 @@ > return false; > } > >- public static void gatherToolBarContributions(final MToolBar toolbarModel, >+ public static void XXXgatherToolBarContributions(final MToolBar toolbarModel, > final List<MToolBarContribution> toolbarContributionList, final String id, > final ArrayList<MToolBarContribution> toContribute) { > for (MToolBarContribution toolBarContribution : toolbarContributionList) { >@@ -83,6 +83,19 @@ > } > } > >+ public static void gatherToolBarContributions(final MToolBar toolbarModel, >+ final List<MToolBarContribution> toolbarContributionList, final String id, >+ final ArrayList<MToolBarContribution> toContribute, final ExpressionContext eContext) { >+ for (MToolBarContribution toolBarContribution : toolbarContributionList) { >+ String parentID = toolBarContribution.getParentId(); >+ boolean filtered = isFiltered(toolbarModel, toolBarContribution); >+ if (filtered || !parentID.equals(id) || !toolBarContribution.isToBeRendered()) { >+ continue; >+ } >+ toContribute.add(toolBarContribution); >+ } >+ } >+ > static boolean isFiltered(MToolBar toolbarModel, MToolBarContribution toolBarContribution) { > return false; > } >#P org.eclipse.e4.ui.workbench.renderers.swt >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/DirectMenuItemRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/DirectMenuItemRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/DirectMenuItemRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/DirectMenuItemRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,114 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import javax.inject.Inject; >+import org.eclipse.e4.core.contexts.ContextInjectionFactory; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.di.annotations.Execute; >+import org.eclipse.e4.core.services.contributions.IContributionFactory; >+import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.model.application.ui.MUIElement; >+import org.eclipse.e4.ui.model.application.ui.menu.ItemType; >+import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+ >+/** >+ * Create a contribute part. >+ */ >+public class DirectMenuItemRenderer extends MenuItemRenderer { >+ >+ @Inject >+ Logger logger; >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MDirectMenuItem) || !(parent instanceof Menu)) >+ return null; >+ >+ MDirectMenuItem itemModel = (MDirectMenuItem) element; >+ if (itemModel.getVisibleWhen() != null) { >+ processVisible(itemModel); >+ } >+ >+ if (!itemModel.isVisible()) { >+ return null; >+ } >+ >+ // determine the index at which we should create the new item >+ int addIndex = calcVisibleIndex(element); >+ >+ // OK, it's a real menu item, what kind? >+ int flags = 0; >+ if (itemModel.getType() == ItemType.PUSH) >+ flags = SWT.PUSH; >+ else if (itemModel.getType() == ItemType.CHECK) >+ flags = SWT.CHECK; >+ else if (itemModel.getType() == ItemType.RADIO) >+ flags = SWT.RADIO; >+ >+ MenuItem newItem = new MenuItem((Menu) parent, flags, addIndex); >+ setItemText(itemModel, newItem); >+ newItem.setImage(getImage(itemModel)); >+ setEnabled(itemModel, newItem); >+ newItem.setEnabled(itemModel.isEnabled()); >+ newItem.setSelection(itemModel.isSelected()); >+ >+ return newItem; >+ } >+ >+ private void setEnabled(MDirectMenuItem itemModel, final MenuItem newItem) { >+ // TODO direct query to @CanExecute goes here >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#hookControllerLogic >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hookControllerLogic(MUIElement me) { >+ super.hookControllerLogic(me); >+ >+ // 'Execute' the operation if possible >+ if (me instanceof MDirectMenuItem >+ && ((MDirectMenuItem) me).getContributionURI() != null) { >+ final MMenuItem item = (MMenuItem) me; >+ final MDirectMenuItem contrib = (MDirectMenuItem) me; >+ final IEclipseContext lclContext = getContext(me); >+ MenuItem mi = (MenuItem) me.getWidget(); >+ mi.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ if (contrib.getObject() == null) { >+ IContributionFactory cf = (IContributionFactory) lclContext >+ .get(IContributionFactory.class.getName()); >+ contrib.setObject(cf.create( >+ contrib.getContributionURI(), lclContext)); >+ } >+ lclContext.set(MItem.class.getName(), item); >+ ContextInjectionFactory.invoke(contrib.getObject(), >+ Execute.class, lclContext); >+ lclContext.remove(MItem.class.getName()); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ }); >+ } >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/HandledMenuItemRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/HandledMenuItemRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/HandledMenuItemRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/HandledMenuItemRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,177 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+import javax.inject.Inject; >+import org.eclipse.core.commands.ParameterizedCommand; >+import org.eclipse.core.commands.common.NotDefinedException; >+import org.eclipse.e4.core.commands.ECommandService; >+import org.eclipse.e4.core.commands.EHandlerService; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.bindings.EBindingService; >+import org.eclipse.e4.ui.model.application.commands.MParameter; >+import org.eclipse.e4.ui.model.application.ui.MUIElement; >+import org.eclipse.e4.ui.model.application.ui.menu.ItemType; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; >+import org.eclipse.jface.bindings.TriggerSequence; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+ >+/** >+ * Create a contribute part. >+ */ >+public class HandledMenuItemRenderer extends MenuItemRenderer { >+ >+ @Inject >+ Logger logger; >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MHandledMenuItem) || !(parent instanceof Menu)) >+ return null; >+ >+ MHandledMenuItem itemModel = (MHandledMenuItem) element; >+ if (itemModel.getVisibleWhen() != null) { >+ processVisible(itemModel); >+ } >+ >+ if (!itemModel.isVisible()) { >+ return null; >+ } >+ >+ // determine the index at which we should create the new item >+ int addIndex = calcVisibleIndex(element); >+ >+ // OK, it's a real menu item, what kind? >+ int flags = 0; >+ if (itemModel.getType() == ItemType.PUSH) >+ flags = SWT.PUSH; >+ else if (itemModel.getType() == ItemType.CHECK) >+ flags = SWT.CHECK; >+ else if (itemModel.getType() == ItemType.RADIO) >+ flags = SWT.RADIO; >+ >+ ParameterizedCommand cmd = itemModel.getWbCommand(); >+ if (cmd == null) { >+ IEclipseContext lclContext = getContext(itemModel); >+ cmd = generateParameterizedCommand(itemModel, lclContext); >+ } >+ MenuItem newItem = new MenuItem((Menu) parent, flags, addIndex); >+ setItemText(itemModel, newItem); >+ setEnabled(itemModel, newItem); >+ newItem.setImage(getImage(itemModel)); >+ newItem.setSelection(itemModel.isSelected()); >+ >+ return newItem; >+ } >+ >+ private void setEnabled(MHandledMenuItem itemModel, MenuItem newItem) { >+ ParameterizedCommand cmd = itemModel.getWbCommand(); >+ if (cmd == null) { >+ return; >+ } >+ final IEclipseContext lclContext = getContext(itemModel); >+ EHandlerService service = lclContext.get(EHandlerService.class); >+ itemModel.setEnabled(service.canExecute(cmd)); >+ newItem.setEnabled(itemModel.isEnabled()); >+ } >+ >+ protected void setItemText(MMenuItem model, MenuItem item) { >+ String text = model.getLabel(); >+ if (model instanceof MHandledItem) { >+ MHandledItem handledItem = (MHandledItem) model; >+ IEclipseContext context = getContext(model); >+ EBindingService bs = (EBindingService) context >+ .get(EBindingService.class.getName()); >+ ParameterizedCommand cmd = handledItem.getWbCommand(); >+ if (cmd != null && (text == null || text.length() == 0)) { >+ try { >+ text = cmd.getName(); >+ } catch (NotDefinedException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ TriggerSequence sequence = bs.getBestSequenceFor(handledItem >+ .getWbCommand()); >+ if (sequence != null) { >+ text = text + '\t' + sequence.format(); >+ } >+ item.setText(text == null ? handledItem.getCommand().getElementId() >+ : text); >+ } else { >+ super.setItemText(model, item); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#hookControllerLogic >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hookControllerLogic(MUIElement me) { >+ // If the item is a CHECK or RADIO update the model's state to match >+ super.hookControllerLogic(me); >+ >+ // 'Execute' the operation if possible >+ if (me instanceof MHandledItem) { >+ final MHandledItem item = (MHandledItem) me; >+ final IEclipseContext lclContext = getContext(me); >+ MenuItem mi = (MenuItem) me.getWidget(); >+ mi.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ EHandlerService service = (EHandlerService) lclContext >+ .get(EHandlerService.class.getName()); >+ ParameterizedCommand cmd = item.getWbCommand(); >+ if (cmd == null) { >+ return; >+ } >+ lclContext.set(MItem.class.getName(), item); >+ service.executeHandler(cmd); >+ lclContext.remove(MItem.class.getName()); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ }); >+ } >+ } >+ >+ public static ParameterizedCommand generateParameterizedCommand( >+ final MHandledItem item, final IEclipseContext lclContext) { >+ ECommandService cmdService = (ECommandService) lclContext >+ .get(ECommandService.class.getName()); >+ Map<String, Object> parameters = null; >+ List<MParameter> modelParms = item.getParameters(); >+ if (modelParms != null && !modelParms.isEmpty()) { >+ parameters = new HashMap<String, Object>(); >+ for (MParameter mParm : modelParms) { >+ parameters.put(mParm.getName(), mParm.getValue()); >+ } >+ } >+ ParameterizedCommand cmd = cmdService.createCommand(item.getCommand() >+ .getElementId(), parameters); >+ item.setWbCommand(cmd); >+ return cmd; >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java,v >retrieving revision 1.20 >diff -u -r1.20 LazyStackRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java 12 Oct 2010 16:17:56 -0000 1.20 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java 14 Oct 2010 18:20:38 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2010 IBM Corporation and others. >+ * Copyright (c) 2008, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -27,6 +27,7 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; > import org.eclipse.e4.ui.widgets.CTabFolder; >@@ -168,7 +169,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MToolBar) >+ if (tbME instanceof MRenderedToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -261,7 +262,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MToolBar) >+ if (tbME instanceof MRenderedToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -286,6 +287,8 @@ > IEclipseContext newParentContext = modelService > .getContainingContext(element); > if (context.getParent() != newParentContext) { >+ // System.out.println("Update Context: " + context.toString() //$NON-NLS-1$ >+ // + " new parent: " + newParentContext.toString()); //$NON-NLS-1$ > context.setParent(newParentContext); > } > } >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,236 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator; >+ >+import java.util.HashMap; >+import javax.annotation.PostConstruct; >+import javax.annotation.PreDestroy; >+import javax.inject.Inject; >+import org.eclipse.core.expressions.EvaluationResult; >+import org.eclipse.core.expressions.Expression; >+import org.eclipse.core.internal.expressions.ReferenceExpression; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.contexts.RunAndTrack; >+import org.eclipse.e4.core.services.events.IEventBroker; >+import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.model.application.ui.MCoreExpression; >+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.menu.ItemType; >+import org.eclipse.e4.ui.model.application.ui.menu.MItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; >+import org.eclipse.e4.ui.workbench.UIEvents; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.Widget; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventHandler; >+ >+/** >+ * Create a contribute part. >+ */ >+public abstract class MenuItemRenderer extends SWTPartRenderer { >+ static class VisibleRAT extends RunAndTrack { >+ Expression exp; >+ MMenuItem item; >+ ExpressionContext ec; >+ boolean participating = true; >+ >+ public VisibleRAT(MMenuItem i, Expression e, IEclipseContext c) { >+ exp = e; >+ item = i; >+ ec = new ExpressionContext(c); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.core.contexts.RunAndTrack#changed(org.eclipse.e4.core >+ * .contexts.IEclipseContext) >+ */ >+ @Override >+ public boolean changed(IEclipseContext context) { >+ try { >+ item.setVisible(EvaluationResult.FALSE != exp.evaluate(ec)); >+ } catch (CoreException e) { >+ item.setVisible(false); >+ WorkbenchSWTActivator.trace( >+ "/trace/menus", "VisibleRAT failed", e); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ return participating; >+ } >+ } >+ >+ private HashMap<MMenuItem, Expression> menuItemToExpression = new HashMap<MMenuItem, Expression>(); >+ private HashMap<MMenuItem, VisibleRAT> menuItemToRAT = new HashMap<MMenuItem, VisibleRAT>(); >+ >+ @Inject >+ Logger logger; >+ @Inject >+ IEventBroker eventBroker; >+ private EventHandler itemUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ MenuItem menuItem = (MenuItem) itemModel.getWidget(); >+ >+ // No widget == nothing to update >+ if (menuItem == null) >+ return; >+ >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (UIEvents.UILabel.LABEL.equals(attName)) { >+ setItemText(itemModel, menuItem); >+ } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >+ menuItem.setImage(getImage(itemModel)); >+ } >+ } >+ }; >+ >+ private EventHandler selectionUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ MenuItem menuItem = (MenuItem) itemModel.getWidget(); >+ if (menuItem != null) { >+ menuItem.setSelection(itemModel.isSelected()); >+ } >+ } >+ }; >+ >+ private EventHandler enabledUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ MenuItem menuItem = (MenuItem) itemModel.getWidget(); >+ if (menuItem != null) { >+ menuItem.setEnabled(itemModel.isEnabled()); >+ } >+ } >+ }; >+ >+ @PostConstruct >+ public void init() { >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >+ itemUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.SELECTED), selectionUpdater); >+ eventBroker >+ .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.ENABLED), enabledUpdater); >+ } >+ >+ @PreDestroy >+ public void contextDisposed() { >+ eventBroker.unsubscribe(itemUpdater); >+ eventBroker.unsubscribe(selectionUpdater); >+ eventBroker.unsubscribe(enabledUpdater); >+ } >+ >+ protected void processVisible(MMenuItem item) { >+ if (menuItemToExpression.get(item) != null) { >+ return; >+ } >+ MCoreExpression exp = (MCoreExpression) item.getVisibleWhen(); >+ Expression ref = null; >+ if (exp.getCoreExpression() instanceof Expression) { >+ ref = (Expression) exp.getCoreExpression(); >+ } else { >+ ref = new ReferenceExpression(exp.getCoreExpressionId()); >+ exp.setCoreExpression(ref); >+ } >+ menuItemToExpression.put(item, ref); >+ IEclipseContext itemContext = getContext(item); >+ VisibleRAT rat = new VisibleRAT(item, ref, itemContext); >+ menuItemToRAT.put(item, rat); >+ itemContext.runAndTrack(rat); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); >+ menuItemToExpression.remove(child); >+ VisibleRAT rat = menuItemToRAT.remove(child); >+ if (rat != null) { >+ rat.participating = false; >+ } >+ } >+ >+ protected void setItemText(MMenuItem model, MenuItem item) { >+ String text = model.getLabel(); >+ if (text == null) { >+ text = ""; //$NON-NLS-1$ >+ } >+ item.setText(text); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#hookControllerLogic >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hookControllerLogic(MUIElement me) { >+ // If the item is a CHECK or RADIO update the model's state to match >+ if (me instanceof MItem) { >+ final MItem item = (MItem) me; >+ if (item.getType() == ItemType.CHECK >+ || item.getType() == ItemType.RADIO) { >+ MenuItem ti = (MenuItem) me.getWidget(); >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ item.setSelected(((MenuItem) e.widget).getSelection()); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ item.setSelected(((MenuItem) e.widget).getSelection()); >+ } >+ }); >+ } >+ } >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,703 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.List; >+import java.util.Map; >+import javax.annotation.PostConstruct; >+import javax.annotation.PreDestroy; >+import javax.inject.Inject; >+import org.eclipse.e4.core.contexts.ContextInjectionFactory; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.contexts.RunAndTrack; >+import org.eclipse.e4.core.services.events.IEventBroker; >+import org.eclipse.e4.core.services.log.Logger; >+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.MContext; >+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.MUILabel; >+import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >+import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; >+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.MMenuElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; >+import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >+import org.eclipse.e4.ui.workbench.IResourceUtilities; >+import org.eclipse.e4.ui.workbench.UIEvents; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.util.EcoreUtil; >+import org.eclipse.jface.action.AbstractGroupMarker; >+import org.eclipse.jface.action.GroupMarker; >+import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.IMenuListener; >+import org.eclipse.jface.action.IMenuManager; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.action.Separator; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Decorations; >+import org.eclipse.swt.widgets.Menu; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventHandler; >+ >+/** >+ * Create a contribute part. >+ */ >+public class MenuManagerRenderer extends SWTPartRenderer { >+ private static final String NO_LABEL = "UnLabled"; //$NON-NLS-1$ >+ >+ private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>(); >+ private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>(); >+ >+ private Map<MMenuItem, IContributionItem> modelToContribution = new HashMap<MMenuItem, IContributionItem>(); >+ >+ private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>(); >+ >+ @Inject >+ private Logger logger; >+ >+ @Inject >+ private MApplication application; >+ >+ @Inject >+ IEventBroker eventBroker; >+ private EventHandler itemUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ >+ IContributionItem ici = getContribution(itemModel); >+ if (ici == null) { >+ return; >+ } >+ >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (UIEvents.UILabel.LABEL.equals(attName)) { >+ ici.update(); >+ } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >+ ici.update(); >+ } >+ } >+ }; >+ >+ private EventHandler toBeRenderedUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ Object element = event.getProperty(UIEvents.EventTags.ELEMENT); >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (element instanceof MMenuItem) { >+ MMenuItem itemModel = (MMenuItem) element; >+ if (UIEvents.UIElement.TOBERENDERED.equals(attName)) { >+ Object obj = itemModel.getParent(); >+ if (!(obj instanceof MMenu)) { >+ return; >+ } >+ MenuManager parent = getManager((MMenu) obj); >+ if (itemModel.isToBeRendered()) { >+ if (parent != null) { >+ modelProcessSwitch(parent, itemModel); >+ } >+ } else { >+ IContributionItem ici = modelToContribution >+ .remove(itemModel); >+ if (ici != null && parent != null) { >+ parent.remove(ici); >+ } >+ if (ici != null) { >+ ici.dispose(); >+ } >+ } >+ } >+ } >+ if (UIEvents.UIElement.VISIBLE.equals(attName)) { >+ if (element instanceof MMenu) { >+ MMenu menuModel = (MMenu) element; >+ MenuManager manager = getManager(menuModel); >+ if (manager == null) { >+ return; >+ } >+ manager.setVisible(menuModel.isVisible()); >+ } else if (element instanceof MMenuElement) { >+ MMenuElement itemModel = (MMenuElement) element; >+ IContributionItem ici = getContribution(itemModel); >+ if (ici == null) { >+ return; >+ } >+ ici.setVisible(itemModel.isVisible()); >+ } >+ } >+ } >+ }; >+ >+ private EventHandler selectionUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ IContributionItem ici = modelToContribution.get(itemModel); >+ if (ici != null) { >+ ici.update(); >+ } >+ } >+ }; >+ >+ private EventHandler enabledUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >+ return; >+ >+ MMenuItem itemModel = (MMenuItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ IContributionItem ici = modelToContribution.get(itemModel); >+ if (ici != null) { >+ ici.update(); >+ } >+ } >+ }; >+ >+ private IMenuListener visibilityCalculationListener = new IMenuListener() { >+ public void menuAboutToShow(IMenuManager manager) { >+ MenuManager menuManager = (MenuManager) manager; >+ if (menuManager.getMenu() == null) { >+ return; >+ } >+ MMenu menuModel = getMenuModel(menuManager); >+ if (menuModel == null) { >+ Menu menu = menuManager.getMenu(); >+ Object obj = menu.getData(AbstractPartRenderer.OWNING_ME); >+ if (obj == null && menu.getParentItem() != null) { >+ obj = menu.getParentItem().getData( >+ AbstractPartRenderer.OWNING_ME); >+ } >+ if (!(obj instanceof MMenu)) { >+ return; >+ } >+ menuModel = (MMenu) obj; >+ } else if (menuModel.getWidget() == null) { >+ bindWidget(menuModel, menuManager.getMenu()); >+ } >+ final IEclipseContext evalContext; >+ if (menuModel instanceof MContext) { >+ evalContext = ((MContext) menuModel).getContext(); >+ } else { >+ evalContext = modelService.getContainingContext(menuModel); >+ } >+ HashSet<ContributionRecord> records = new HashSet<ContributionRecord>(); >+ for (MMenuElement element : menuModel.getChildren()) { >+ ContributionRecord record = modelContributionToRecord >+ .get(element); >+ if (record != null && records.add(record)) { >+ record.updateVisibility(evalContext); >+ } >+ } >+ } >+ }; >+ >+ @PostConstruct >+ public void init() { >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >+ itemUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.SELECTED), selectionUpdater); >+ eventBroker >+ .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.ENABLED), enabledUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), >+ toBeRenderedUpdater); >+ >+ } >+ >+ @PreDestroy >+ public void contextDisposed() { >+ eventBroker.unsubscribe(itemUpdater); >+ eventBroker.unsubscribe(selectionUpdater); >+ eventBroker.unsubscribe(enabledUpdater); >+ eventBroker.unsubscribe(toBeRenderedUpdater); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget >+ * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) >+ */ >+ @Override >+ public Object createWidget(MUIElement element, Object parent) { >+ if (!(element instanceof MMenu)) >+ return null; >+ >+ final MMenu menuModel = (MMenu) element; >+ Menu newMenu = null; >+ boolean menuBar = false; >+ >+ if (parent instanceof Decorations) { >+ MUIElement container = (MUIElement) ((EObject) element) >+ .eContainer(); >+ if (container instanceof MWindow) { >+ MenuManager menuBarManager = getManager(menuModel); >+ if (menuBarManager == null) { >+ menuBarManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, menuBarManager); >+ } >+ newMenu = menuBarManager.createMenuBar((Decorations) parent); >+ ((Decorations) parent).setMenuBar(newMenu); >+ newMenu.setData(menuBarManager); >+ menuBar = true; >+ } else { >+ MenuManager popupManager = getManager(menuModel); >+ if (popupManager == null) { >+ popupManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, popupManager); >+ } >+ newMenu = popupManager.createContextMenu((Control) parent); >+ ((Control) parent).setMenu(newMenu); >+ newMenu.setData(popupManager); >+ } >+ } else if (parent instanceof Menu) { >+ // Object data = ((Menu) parent).getData(); >+ logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$ >+ + menuModel + "\n\t" + parent); //$NON-NLS-1$ >+ >+ } else if (parent instanceof Control) { >+ MenuManager popupManager = getManager(menuModel); >+ if (popupManager == null) { >+ popupManager = new MenuManager(NO_LABEL, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, popupManager); >+ } >+ newMenu = popupManager.createContextMenu((Control) parent); >+ ((Control) parent).setMenu(newMenu); >+ newMenu.setData(popupManager); >+ } >+ processContributions(menuModel, menuBar); >+ if (newMenu != null) { >+ newMenu.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp(menuModel); >+ } >+ }); >+ } >+ return newMenu; >+ } >+ >+ /** >+ * @param menuModel >+ */ >+ protected void cleanUp(MMenu menuModel) { >+ Collection<ContributionRecord> vals = modelContributionToRecord >+ .values(); >+ for (ContributionRecord record : vals >+ .toArray(new ContributionRecord[vals.size()])) { >+ if (record.menuModel == menuModel) { >+ record.dispose(); >+ for (MMenuElement copy : record.generatedElements) { >+ modelContributionToRecord.remove(copy); >+ if (copy instanceof MMenu) { >+ MMenu menuCopy = (MMenu) copy; >+ cleanUp(menuCopy); >+ MenuManager copyManager = getManager(menuCopy); >+ clearModelToManager(menuCopy, copyManager); >+ if (copyManager != null) { >+ copyManager.dispose(); >+ } >+ } else { >+ IContributionItem ici = modelToContribution >+ .remove(copy); >+ if (ici != null) { >+ record.manager.remove(ici); >+ } >+ } >+ } >+ record.generatedElements.clear(); >+ } >+ } >+ } >+ >+ /** >+ * @param menuModel >+ * @param menuBar >+ */ >+ private void processContributions(MMenu menuModel, boolean menuBar) { >+ final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >+ ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, >+ application.getMenuContributions(), menuModel.getElementId(), >+ toContribute, null, menuModel instanceof MPopupMenu); >+ generateContributions(menuModel, toContribute, menuBar); >+ } >+ >+ /** >+ * @param menuModel >+ * @param toContribute >+ */ >+ private void generateContributions(MMenu menuModel, >+ ArrayList<MMenuContribution> toContribute, boolean menuBar) { >+ HashSet<String> existingMenuIds = new HashSet<String>(); >+ HashSet<String> existingSeparatorNames = new HashSet<String>(); >+ for (MMenuElement child : menuModel.getChildren()) { >+ String elementId = child.getElementId(); >+ if (child instanceof MMenu && elementId != null) { >+ existingMenuIds.add(elementId); >+ } else if (child instanceof MMenuSeparator && elementId != null) { >+ existingSeparatorNames.add(elementId); >+ } >+ } >+ >+ MenuManager manager = getManager(menuModel); >+ boolean done = toContribute.size() == 0; >+ while (!done) { >+ ArrayList<MMenuContribution> curList = new ArrayList<MMenuContribution>( >+ toContribute); >+ int retryCount = toContribute.size(); >+ toContribute.clear(); >+ >+ for (MMenuContribution menuContribution : curList) { >+ if (!processAddition(menuModel, manager, menuContribution, >+ existingMenuIds, existingSeparatorNames, menuBar)) { >+ toContribute.add(menuContribution); >+ } >+ } >+ >+ // We're done if the retryList is now empty (everything done) or >+ // if the list hasn't changed at all (no hope) >+ done = (toContribute.size() == 0) >+ || (toContribute.size() == retryCount); >+ } >+ } >+ >+ /** >+ * @param menuModel >+ * @param manager >+ * @param menuContribution >+ * @return true if the menuContribution was processed >+ */ >+ private boolean processAddition(MMenu menuModel, final MenuManager manager, >+ MMenuContribution menuContribution, >+ final HashSet<String> existingMenuIds, >+ HashSet<String> existingSeparatorNames, boolean menuBar) { >+ int idx = getIndex(menuModel, menuContribution.getPositionInParent()); >+ if (idx == -1) { >+ return false; >+ } >+ final ContributionRecord record = new ContributionRecord(menuModel, >+ menuContribution, manager); >+ record.generate(); >+ for (MMenuElement copy : record.generatedElements) { >+ modelContributionToRecord.put(copy, record); >+ if (copy instanceof MMenu >+ && existingMenuIds.contains(copy.getElementId())) { >+ // skip this, it's already there >+ continue; >+ } else if (copy instanceof MMenuSeparator >+ && existingSeparatorNames.contains(copy.getElementId())) { >+ // skip this, it's already there >+ continue; >+ } >+ menuModel.getChildren().add(idx++, copy); >+ if (copy instanceof MMenu && copy.getElementId() != null) { >+ existingMenuIds.add(copy.getElementId()); >+ } else if (copy instanceof MMenuSeparator >+ && copy.getElementId() != null) { >+ existingSeparatorNames.add(copy.getElementId()); >+ } >+ } >+ if (menuBar) { >+ if (menuContribution.getVisibleWhen() != null) { >+ final IEclipseContext parentContext = modelService >+ .getContainingContext(menuModel); >+ parentContext.runAndTrack(new RunAndTrack() { >+ @Override >+ public boolean changed(IEclipseContext context) { >+ record.updateVisibility(parentContext.getActiveLeaf()); >+ manager.update(true); >+ return true; >+ } >+ }); >+ } >+ } >+ return true; >+ } >+ >+ private static int getIndex(MElementContainer<?> menuModel, >+ String positionInParent) { >+ String id = null; >+ String modifier = null; >+ if (positionInParent != null && positionInParent.length() > 0) { >+ String[] array = positionInParent.split("="); //$NON-NLS-1$ >+ modifier = array[0]; >+ id = array[1]; >+ } >+ if (id == null) { >+ return menuModel.getChildren().size(); >+ } >+ >+ int idx = 0; >+ int size = menuModel.getChildren().size(); >+ while (idx < size) { >+ if (id.equals(menuModel.getChildren().get(idx).getElementId())) { >+ if ("after".equals(modifier)) { //$NON-NLS-1$ >+ idx++; >+ } >+ return idx; >+ } >+ idx++; >+ } >+ return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ >+ } >+ >+ static class ContributionRecord { >+ MMenu menuModel; >+ MMenuContribution menuContribution; >+ ArrayList<MMenuElement> generatedElements = new ArrayList<MMenuElement>(); >+ MenuManager manager; >+ >+ public ContributionRecord(MMenu menuModel, >+ MMenuContribution contribution, MenuManager manager) { >+ this.menuModel = menuModel; >+ this.menuContribution = contribution; >+ this.manager = manager; >+ } >+ >+ /** >+ * @param context >+ */ >+ public void updateVisibility(IEclipseContext context) { >+ ExpressionContext exprContext = new ExpressionContext(context); >+ boolean isVisible = ContributionsAnalyzer.isVisible( >+ menuContribution, exprContext); >+ for (MMenuElement item : generatedElements) { >+ item.setVisible(isVisible); >+ } >+ manager.markDirty(); >+ } >+ >+ public void generate() { >+ for (MMenuElement item : menuContribution.getChildren()) { >+ MMenuElement copy = (MMenuElement) EcoreUtil >+ .copy((EObject) item); >+ generatedElements.add(copy); >+ } >+ } >+ >+ public void dispose() { >+ for (MMenuElement copy : generatedElements) { >+ menuModel.getChildren().remove(copy); >+ } >+ } >+ } >+ >+ void removeMenuContributions(final MMenu menuModel, >+ final ArrayList<MMenuElement> menuContributionsToRemove) { >+ for (MMenuElement item : menuContributionsToRemove) { >+ menuModel.getChildren().remove(item); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ */ >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ // I can either simply stop processing, or we can walk the model >+ // ourselves like the "old" days >+ // EMF gives us null lists if empty >+ if (container == null) >+ return; >+ >+ // this is in direct violation of good programming >+ MenuManager parentManager = getManager((MMenu) ((Object) container)); >+ if (parentManager == null) { >+ return; >+ } >+ // Process any contents of the newly created ME >+ List<MUIElement> parts = container.getChildren(); >+ if (parts != null) { >+ MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]); >+ for (int i = 0; i < plist.length; i++) { >+ MUIElement childME = plist[i]; >+ modelProcessSwitch(parentManager, (MMenuElement) childME); >+ } >+ } >+ parentManager.update(false); >+ } >+ >+ /** >+ * @param parentManager >+ * @param menuModel >+ */ >+ private void processMenu(MenuManager parentManager, MMenu menuModel) { >+ String menuText = getText(menuModel); >+ ImageDescriptor desc = getImageDescriptor(menuModel); >+ MenuManager menuManager = new MenuManager(menuText, desc, >+ menuModel.getElementId()); >+ linkModelToManager(menuModel, menuManager); >+ menuManager.setVisible(menuModel.isVisible()); >+ parentManager.add(menuManager); >+ processContributions(menuModel, false); >+ List<MMenuElement> parts = menuModel.getChildren(); >+ if (parts != null) { >+ MMenuElement[] plist = parts >+ .toArray(new MMenuElement[parts.size()]); >+ for (int i = 0; i < plist.length; i++) { >+ MMenuElement childME = plist[i]; >+ modelProcessSwitch(menuManager, childME); >+ } >+ } >+ } >+ >+ /** >+ * @param menuManager >+ * @param childME >+ */ >+ void modelProcessSwitch(MenuManager menuManager, MMenuElement childME) { >+ if (!childME.isToBeRendered()) { >+ return; >+ } >+ if (childME instanceof MHandledMenuItem) { >+ MHandledMenuItem itemModel = (MHandledMenuItem) childME; >+ processHandledItem(menuManager, itemModel); >+ } else if (childME instanceof MDirectMenuItem) { >+ MDirectMenuItem itemModel = (MDirectMenuItem) childME; >+ processDirectItem(menuManager, itemModel, null); >+ } else if (childME instanceof MMenuSeparator) { >+ MMenuSeparator sep = (MMenuSeparator) childME; >+ processSeparator(menuManager, sep); >+ } else if (childME instanceof MMenu) { >+ MMenu itemModel = (MMenu) childME; >+ processMenu(menuManager, itemModel); >+ } >+ } >+ >+ /** >+ * @param menuManager >+ * @param itemModel >+ */ >+ private void processSeparator(MenuManager menuManager, >+ MMenuSeparator itemModel) { >+ AbstractGroupMarker marker = null; >+ if (itemModel.isVisible()) { >+ marker = new Separator(); >+ marker.setId(itemModel.getElementId()); >+ } else { >+ if (itemModel.getElementId() != null) { >+ marker = new GroupMarker(itemModel.getElementId()); >+ } >+ } >+ menuManager.add(marker); >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ * @param id >+ * TODO >+ */ >+ void processDirectItem(MenuManager parentManager, >+ MDirectMenuItem itemModel, String id) { >+ final IEclipseContext lclContext = getContext(itemModel); >+ DirectContributionItem ci = ContextInjectionFactory.make( >+ DirectContributionItem.class, lclContext); >+ ci.setModel(itemModel); >+ ci.setVisible(itemModel.isVisible()); >+ parentManager.add(ci); >+ modelToContribution.put(itemModel, ci); >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ */ >+ void processHandledItem(MenuManager parentManager, >+ MHandledMenuItem itemModel) { >+ final IEclipseContext lclContext = getContext(itemModel); >+ HandledContributionItem ci = ContextInjectionFactory.make( >+ HandledContributionItem.class, lclContext); >+ ci.setModel(itemModel); >+ ci.setVisible(itemModel.isVisible()); >+ parentManager.add(ci); >+ modelToContribution.put(itemModel, ci); >+ } >+ >+ private String getText(MMenu menuModel) { >+ String text = menuModel.getLabel(); >+ if (text == null || text.length() == 0) { >+ return NO_LABEL; >+ } >+ return text; >+ } >+ >+ private ImageDescriptor getImageDescriptor(MUILabel element) { >+ IEclipseContext localContext = context; >+ String iconURI = element.getIconURI(); >+ if (iconURI != null && iconURI.length() > 0) { >+ ISWTResourceUtilities resUtils = (ISWTResourceUtilities) localContext >+ .get(IResourceUtilities.class.getName()); >+ return resUtils.imageDescriptorFromURI(URI.createURI(iconURI)); >+ } >+ return null; >+ } >+ >+ public MenuManager getManager(MMenu model) { >+ return modelToManager.get(model); >+ } >+ >+ public MMenu getMenuModel(MenuManager manager) { >+ return managerToModel.get(manager); >+ } >+ >+ public void linkModelToManager(MMenu model, MenuManager manager) { >+ modelToManager.put(model, manager); >+ managerToModel.put(manager, model); >+ manager.addMenuListener(visibilityCalculationListener); >+ } >+ >+ public void clearModelToManager(MMenu model, MenuManager manager) { >+ modelToManager.remove(model); >+ managerToModel.remove(manager); >+ if (manager != null) { >+ manager.removeMenuListener(visibilityCalculationListener); >+ } >+ } >+ >+ public IContributionItem getContribution(MMenuElement model) { >+ return modelToContribution.get(model); >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java,v >retrieving revision 1.9 >diff -u -r1.9 MenuRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 12 Oct 2010 16:17:56 -0000 1.9 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 14 Oct 2010 18:20:38 -0000 >@@ -11,361 +11,127 @@ > package org.eclipse.e4.ui.workbench.renderers.swt; > > import java.util.ArrayList; >-import java.util.Collection; > import java.util.HashMap; > import java.util.HashSet; >-import java.util.List; >-import java.util.Map; >-import javax.annotation.PostConstruct; >-import javax.annotation.PreDestroy; >-import javax.inject.Inject; >-import org.eclipse.e4.core.contexts.ContextInjectionFactory; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.core.contexts.RunAndTrack; >-import org.eclipse.e4.core.services.events.IEventBroker; >-import org.eclipse.e4.core.services.log.Logger; > 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.MContext; > 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.MUILabel; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >-import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; >-import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; > 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.MMenuElement; >-import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; >-import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >-import org.eclipse.e4.ui.workbench.IResourceUtilities; >-import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >-import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities; >-import org.eclipse.emf.common.util.URI; >+import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; > import org.eclipse.emf.ecore.EObject; >-import org.eclipse.emf.ecore.util.EcoreUtil; >-import org.eclipse.jface.action.AbstractGroupMarker; >-import org.eclipse.jface.action.GroupMarker; >-import org.eclipse.jface.action.IContributionItem; >-import org.eclipse.jface.action.IMenuListener; >-import org.eclipse.jface.action.IMenuManager; >-import org.eclipse.jface.action.MenuManager; >-import org.eclipse.jface.action.Separator; >-import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.swt.SWT; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Decorations; > import org.eclipse.swt.widgets.Menu; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventHandler; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.Widget; > > /** > * Create a contribute part. > */ > public class MenuRenderer extends SWTPartRenderer { >- private static final String NO_LABEL = "UnLabled"; //$NON-NLS-1$ >- >- private Map<MMenu, MenuManager> modelToManager = new HashMap<MMenu, MenuManager>(); >- private Map<MenuManager, MMenu> managerToModel = new HashMap<MenuManager, MMenu>(); >- >- private Map<MMenuItem, IContributionItem> modelToContribution = new HashMap<MMenuItem, IContributionItem>(); >- >- private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>(); >- >- @Inject >- private Logger logger; >- >- @Inject > private MApplication application; >+ private HashMap<MMenu, ArrayList<ArrayList<MMenuElement>>> pendingCleanup = new HashMap<MMenu, ArrayList<ArrayList<MMenuElement>>>(); > >- @Inject >- IEventBroker eventBroker; >- private EventHandler itemUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MMenuItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >- return; >- >- MMenuItem itemModel = (MMenuItem) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- >- IContributionItem ici = getContribution(itemModel); >- if (ici == null) { >- return; >- } >- >- String attName = (String) event >- .getProperty(UIEvents.EventTags.ATTNAME); >- if (UIEvents.UILabel.LABEL.equals(attName)) { >- ici.update(); >- } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >- ici.update(); >- } >- } >- }; >- >- private EventHandler toBeRenderedUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- Object element = event.getProperty(UIEvents.EventTags.ELEMENT); >- String attName = (String) event >- .getProperty(UIEvents.EventTags.ATTNAME); >- if (element instanceof MMenuItem) { >- MMenuItem itemModel = (MMenuItem) element; >- if (UIEvents.UIElement.TOBERENDERED.equals(attName)) { >- Object obj = itemModel.getParent(); >- if (!(obj instanceof MMenu)) { >- return; >- } >- MenuManager parent = getManager((MMenu) obj); >- if (itemModel.isToBeRendered()) { >- if (parent != null) { >- modelProcessSwitch(parent, itemModel); >- } >- } else { >- IContributionItem ici = modelToContribution >- .remove(itemModel); >- if (ici != null && parent != null) { >- parent.remove(ici); >- } >- if (ici != null) { >- ici.dispose(); >- } >- } >- } >- } >- if (UIEvents.UIElement.VISIBLE.equals(attName)) { >- if (element instanceof MMenu) { >- MMenu menuModel = (MMenu) element; >- MenuManager manager = getManager(menuModel); >- if (manager == null) { >- return; >- } >- manager.setVisible(menuModel.isVisible()); >- } else if (element instanceof MMenuElement) { >- MMenuElement itemModel = (MMenuElement) element; >- IContributionItem ici = getContribution(itemModel); >- if (ici == null) { >- return; >- } >- ici.setVisible(itemModel.isVisible()); >- } >- } >- } >- }; >- >- private EventHandler selectionUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MToolItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >- return; >- >- MMenuItem itemModel = (MMenuItem) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = modelToContribution.get(itemModel); >- if (ici != null) { >- ici.update(); >- } >- } >- }; >- >- private EventHandler enabledUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MMenuItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) >- return; >- >- MMenuItem itemModel = (MMenuItem) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = modelToContribution.get(itemModel); >- if (ici != null) { >- ici.update(); >- } >- } >- }; >- >- private IMenuListener visibilityCalculationListener = new IMenuListener() { >- public void menuAboutToShow(IMenuManager manager) { >- MenuManager menuManager = (MenuManager) manager; >- if (menuManager.getMenu() == null) { >- return; >- } >- MMenu menuModel = getMenuModel(menuManager); >- if (menuModel == null) { >- Menu menu = menuManager.getMenu(); >- Object obj = menu.getData(AbstractPartRenderer.OWNING_ME); >- if (obj == null && menu.getParentItem() != null) { >- obj = menu.getParentItem().getData( >- AbstractPartRenderer.OWNING_ME); >- } >- if (!(obj instanceof MMenu)) { >- return; >- } >- menuModel = (MMenu) obj; >- } else if (menuModel.getWidget() == null) { >- bindWidget(menuModel, menuManager.getMenu()); >- } >- final IEclipseContext evalContext; >- if (menuModel instanceof MContext) { >- evalContext = ((MContext) menuModel).getContext(); >- } else { >- evalContext = modelService.getContainingContext(menuModel); >- } >- HashSet<ContributionRecord> records = new HashSet<ContributionRecord>(); >- for (MMenuElement element : menuModel.getChildren()) { >- ContributionRecord record = modelContributionToRecord >- .get(element); >- if (record != null && records.add(record)) { >- record.updateVisibility(evalContext); >- } >- } >- } >- }; >- >- @PostConstruct >- public void init() { >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >- itemUpdater); >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >- UIEvents.Item.SELECTED), selectionUpdater); >- eventBroker >- .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >- UIEvents.Item.ENABLED), enabledUpdater); >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), >- toBeRenderedUpdater); >- >- } >- >- @PreDestroy >- public void contextDisposed() { >- eventBroker.unsubscribe(itemUpdater); >- eventBroker.unsubscribe(selectionUpdater); >- eventBroker.unsubscribe(enabledUpdater); >- eventBroker.unsubscribe(toBeRenderedUpdater); >+ @Override >+ public void init(IEclipseContext context) { >+ super.init(context); >+ application = context.get(MApplication.class); > } > >- /* >- * (non-Javadoc) >- * >- * @see >- * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget >- * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) >- */ >- @Override >- public Object createWidget(MUIElement element, Object parent) { >+ public Object createWidget(final MUIElement element, Object parent) { > if (!(element instanceof MMenu)) > return null; > > final MMenu menuModel = (MMenu) element; >- Menu newMenu = null; >- boolean menuBar = false; > >+ Menu newMenu = null; > if (parent instanceof Decorations) { > MUIElement container = (MUIElement) ((EObject) element) > .eContainer(); > if (container instanceof MWindow) { >- MenuManager menuBarManager = getManager(menuModel); >- if (menuBarManager == null) { >- menuBarManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, menuBarManager); >- } >- newMenu = menuBarManager.createMenuBar((Decorations) parent); >- ((Decorations) parent).setMenuBar(newMenu); >- newMenu.setData(menuBarManager); >- menuBar = true; >+ newMenu = new Menu((Decorations) parent, SWT.BAR); >+ newMenu.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp(menuModel); >+ } >+ }); > } else { >- MenuManager popupManager = getManager(menuModel); >- if (popupManager == null) { >- popupManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >- } >- newMenu = popupManager.createContextMenu((Control) parent); >- ((Control) parent).setMenu(newMenu); >- newMenu.setData(popupManager); >+ newMenu = new Menu((Decorations) parent, SWT.POP_UP); > } > } else if (parent instanceof Menu) { >- // Object data = ((Menu) parent).getData(); >- logger.debug(new Exception(), "Trying to render a sub menu " //$NON-NLS-1$ >- + menuModel + "\n\t" + parent); //$NON-NLS-1$ >- >+ int addIndex = calcVisibleIndex(menuModel); >+ MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, >+ addIndex); >+ setItemText(menuModel, newItem); >+ newItem.setImage(getImage(menuModel)); >+ newItem.setEnabled(menuModel.isEnabled()); >+ return newItem; > } else if (parent instanceof Control) { >- MenuManager popupManager = getManager(menuModel); >- if (popupManager == null) { >- popupManager = new MenuManager(NO_LABEL, >- menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >- } >- newMenu = popupManager.createContextMenu((Control) parent); >- ((Control) parent).setMenu(newMenu); >- newMenu.setData(popupManager); >- } >- processContributions(menuModel, menuBar); >- if (newMenu != null) { >- newMenu.addDisposeListener(new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- cleanUp(menuModel); >- } >- }); >+ newMenu = new Menu((Control) parent); > } >+ > return newMenu; > } > >- /** >- * @param menuModel >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) > */ >- protected void cleanUp(MMenu menuModel) { >- Collection<ContributionRecord> vals = modelContributionToRecord >- .values(); >- for (ContributionRecord record : vals >- .toArray(new ContributionRecord[vals.size()])) { >- if (record.menuModel == menuModel) { >- record.dispose(); >- for (MMenuElement copy : record.generatedElements) { >- modelContributionToRecord.remove(copy); >- if (copy instanceof MMenu) { >- MMenu menuCopy = (MMenu) copy; >- cleanUp(menuCopy); >- MenuManager copyManager = getManager(menuCopy); >- clearModelToManager(menuCopy, copyManager); >- if (copyManager != null) { >- copyManager.dispose(); >- } >- } else { >- IContributionItem ici = modelToContribution >- .remove(copy); >- if (ici != null) { >- record.manager.remove(ici); >- } >- } >- } >- record.generatedElements.clear(); >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ if (container.getChildren().size() == 0) { >+ Object obj = container.getWidget(); >+ if (obj instanceof MenuItem) { >+ MenuItem mi = (MenuItem) obj; >+ if (mi.getMenu() == null) { >+ mi.setMenu(new Menu(mi)); >+ } >+ Menu menu = mi.getMenu(); >+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH); >+ menuItem.setText(MenuServiceFilter.NUL_MENU_ITEM); >+ menuItem.setEnabled(false); > } > } >- } > >- /** >- * @param menuModel >- * @param menuBar >- */ >- private void processContributions(MMenu menuModel, boolean menuBar) { >- final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >- ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, >- application.getMenuContributions(), menuModel.getElementId(), >- toContribute, null, menuModel instanceof MPopupMenu); >- generateContributions(menuModel, toContribute, menuBar); >+ super.processContents(container); >+ >+ Object obj = container.getWidget(); >+ Object menuObj = container; >+ if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0 >+ && (menuObj instanceof MMenu)) { >+ MMenu menuModel = (MMenu) menuObj; >+ IEclipseContext ctx = getContext(container); >+ ExpressionContext eContext = new ExpressionContext(ctx); >+ ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >+ ContributionsAnalyzer.gatherMenuContributions(menuModel, >+ application.getMenuContributions(), >+ menuModel.getElementId(), toContribute, eContext, false); >+ addMenuBarContributions(menuModel, toContribute, ctx, eContext); >+ } > } > >- /** >- * @param menuModel >- * @param toContribute >- */ >- private void generateContributions(MMenu menuModel, >- ArrayList<MMenuContribution> toContribute, boolean menuBar) { >+ // this is similar in nature to: >+ // org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.addMenuContributions(MMenu, >+ // ArrayList<MMenuContribution>, ArrayList<MMenuElement>) >+ // the difference is it needs to add all the contributions and manage their >+ // visiblility through a RAT >+ private void addMenuBarContributions(final MMenu menuModel, >+ ArrayList<MMenuContribution> toContribute, >+ final IEclipseContext ctx, final ExpressionContext eContext) { > HashSet<String> existingMenuIds = new HashSet<String>(); > HashSet<String> existingSeparatorNames = new HashSet<String>(); > for (MMenuElement child : menuModel.getChildren()) { >@@ -377,7 +143,6 @@ > } > } > >- MenuManager manager = getManager(menuModel); > boolean done = toContribute.size() == 0; > while (!done) { > ArrayList<MMenuContribution> curList = new ArrayList<MMenuContribution>( >@@ -385,13 +150,40 @@ > int retryCount = toContribute.size(); > toContribute.clear(); > >- for (MMenuContribution menuContribution : curList) { >- if (!processAddition(menuModel, manager, menuContribution, >- existingMenuIds, existingSeparatorNames, menuBar)) { >+ for (final MMenuContribution menuContribution : curList) { >+ final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>(); >+ if (!ContributionsAnalyzer.processAddition(menuModel, >+ menuContributionsToRemove, menuContribution, >+ existingMenuIds, existingSeparatorNames)) { > toContribute.add(menuContribution); >+ } else { >+ if (menuContribution.getVisibleWhen() != null) { >+ ctx.runAndTrack(new RunAndTrack() { >+ @Override >+ public boolean changed(IEclipseContext context) { >+ if (!menuModel.isToBeRendered() >+ || !menuModel.isVisible() >+ || menuModel.getWidget() == null) { >+ return false; >+ } >+ boolean rc = ContributionsAnalyzer.isVisible( >+ menuContribution, eContext); >+ for (MMenuElement element : menuContributionsToRemove) { >+ element.setToBeRendered(rc); >+ } >+ return true; >+ } >+ }); >+ } >+ ArrayList<ArrayList<MMenuElement>> lists = pendingCleanup >+ .get(menuModel); >+ if (lists == null) { >+ lists = new ArrayList<ArrayList<MMenuElement>>(); >+ pendingCleanup.put(menuModel, lists); >+ } >+ lists.add(menuContributionsToRemove); > } > } >- > // We're done if the retryList is now empty (everything done) or > // if the list hasn't changed at all (no hope) > done = (toContribute.size() == 0) >@@ -399,305 +191,67 @@ > } > } > >- /** >- * @param menuModel >- * @param manager >- * @param menuContribution >- * @return true if the menuContribution was processed >- */ >- private boolean processAddition(MMenu menuModel, final MenuManager manager, >- MMenuContribution menuContribution, >- final HashSet<String> existingMenuIds, >- HashSet<String> existingSeparatorNames, boolean menuBar) { >- int idx = getIndex(menuModel, menuContribution.getPositionInParent()); >- if (idx == -1) { >- return false; >+ private void setItemText(MMenu model, MenuItem item) { >+ String text = model.getLabel(); >+ if (text == null) { >+ text = ""; //$NON-NLS-1$ > } >- final ContributionRecord record = new ContributionRecord(menuModel, >- menuContribution, manager); >- record.generate(); >- for (MMenuElement copy : record.generatedElements) { >- modelContributionToRecord.put(copy, record); >- if (copy instanceof MMenu >- && existingMenuIds.contains(copy.getElementId())) { >- // skip this, it's already there >- continue; >- } else if (copy instanceof MMenuSeparator >- && existingSeparatorNames.contains(copy.getElementId())) { >- // skip this, it's already there >- continue; >- } >- menuModel.getChildren().add(idx++, copy); >- if (copy instanceof MMenu && copy.getElementId() != null) { >- existingMenuIds.add(copy.getElementId()); >- } else if (copy instanceof MMenuSeparator >- && copy.getElementId() != null) { >- existingSeparatorNames.add(copy.getElementId()); >- } >- } >- if (menuBar) { >- if (menuContribution.getVisibleWhen() != null) { >- final IEclipseContext parentContext = modelService >- .getContainingContext(menuModel); >- parentContext.runAndTrack(new RunAndTrack() { >- @Override >- public boolean changed(IEclipseContext context) { >- record.updateVisibility(parentContext.getActiveLeaf()); >- manager.update(true); >- return true; >- } >- }); >- } >- } >- return true; >+ item.setText(text); > } > >- private static int getIndex(MElementContainer<?> menuModel, >- String positionInParent) { >- String id = null; >- String modifier = null; >- if (positionInParent != null && positionInParent.length() > 0) { >- String[] array = positionInParent.split("="); //$NON-NLS-1$ >- modifier = array[0]; >- id = array[1]; >- } >- if (id == null) { >- return menuModel.getChildren().size(); >- } >- >- int idx = 0; >- int size = menuModel.getChildren().size(); >- while (idx < size) { >- if (id.equals(menuModel.getChildren().get(idx).getElementId())) { >- if ("after".equals(modifier)) { //$NON-NLS-1$ >- idx++; >- } >- return idx; >- } >- idx++; >- } >- return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ >- } >- >- static class ContributionRecord { >- MMenu menuModel; >- MMenuContribution menuContribution; >- ArrayList<MMenuElement> generatedElements = new ArrayList<MMenuElement>(); >- MenuManager manager; >- >- public ContributionRecord(MMenu menuModel, >- MMenuContribution contribution, MenuManager manager) { >- this.menuModel = menuModel; >- this.menuContribution = contribution; >- this.manager = manager; >- } >- >- /** >- * @param context >- */ >- public void updateVisibility(IEclipseContext context) { >- ExpressionContext exprContext = new ExpressionContext(context); >- boolean isVisible = ContributionsAnalyzer.isVisible( >- menuContribution, exprContext); >- for (MMenuElement item : generatedElements) { >- item.setVisible(isVisible); >- } >- manager.markDirty(); >- } >- >- public void generate() { >- for (MMenuElement item : menuContribution.getChildren()) { >- MMenuElement copy = (MMenuElement) EcoreUtil >- .copy((EObject) item); >- generatedElements.add(copy); >- } >- } >- >- public void dispose() { >- for (MMenuElement copy : generatedElements) { >- menuModel.getChildren().remove(copy); >- } >- } >- } >- >- void removeMenuContributions(final MMenu menuModel, >- final ArrayList<MMenuElement> menuContributionsToRemove) { >- for (MMenuElement item : menuContributionsToRemove) { >- menuModel.getChildren().remove(item); >- } >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); > } > > /* > * (non-Javadoc) > * > * @see >- * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >- * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ * org.eclipse.e4.ui.workbench.renderers.AbstractPartRenderer#getUIContainer >+ * (org.eclipse.e4.ui.model.application.MUIElement) > */ > @Override >- public void processContents(MElementContainer<MUIElement> container) { >- // I can either simply stop processing, or we can walk the model >- // ourselves like the "old" days >- // EMF gives us null lists if empty >- if (container == null) >- return; >+ public Object getUIContainer(MUIElement element) { >+ if (!(element instanceof MMenuElement)) >+ return null; > >- // this is in direct violation of good programming >- MenuManager parentManager = getManager((MMenu) ((Object) container)); >- if (parentManager == null) { >- return; >- } >- // Process any contents of the newly created ME >- List<MUIElement> parts = container.getChildren(); >- if (parts != null) { >- MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]); >- for (int i = 0; i < plist.length; i++) { >- MUIElement childME = plist[i]; >- modelProcessSwitch(parentManager, (MMenuElement) childME); >+ if (element.getParent().getWidget() instanceof MenuItem) { >+ MenuItem mi = (MenuItem) element.getParent().getWidget(); >+ if (mi.getMenu() == null) { >+ mi.setMenu(new Menu(mi)); > } >+ return mi.getMenu(); > } >- parentManager.update(false); >- } > >- /** >- * @param parentManager >- * @param menuModel >- */ >- private void processMenu(MenuManager parentManager, MMenu menuModel) { >- String menuText = getText(menuModel); >- ImageDescriptor desc = getImageDescriptor(menuModel); >- MenuManager menuManager = new MenuManager(menuText, desc, >- menuModel.getElementId()); >- linkModelToManager(menuModel, menuManager); >- menuManager.setVisible(menuModel.isVisible()); >- parentManager.add(menuManager); >- processContributions(menuModel, false); >- List<MMenuElement> parts = menuModel.getChildren(); >- if (parts != null) { >- MMenuElement[] plist = parts >- .toArray(new MMenuElement[parts.size()]); >- for (int i = 0; i < plist.length; i++) { >- MMenuElement childME = plist[i]; >- modelProcessSwitch(menuManager, childME); >- } >- } >+ return super.getUIContainer(element); > } > >- /** >- * @param menuManager >- * @param childME >- */ >- void modelProcessSwitch(MenuManager menuManager, MMenuElement childME) { >- if (!childME.isToBeRendered()) { >+ void cleanUp(MMenu menuModel) { >+ ArrayList<ArrayList<MMenuElement>> lists = pendingCleanup >+ .remove(menuModel); >+ if (lists == null) { > return; > } >- if (childME instanceof MHandledMenuItem) { >- MHandledMenuItem itemModel = (MHandledMenuItem) childME; >- processHandledItem(menuManager, itemModel); >- } else if (childME instanceof MDirectMenuItem) { >- MDirectMenuItem itemModel = (MDirectMenuItem) childME; >- processDirectItem(menuManager, itemModel, null); >- } else if (childME instanceof MMenuSeparator) { >- MMenuSeparator sep = (MMenuSeparator) childME; >- processSeparator(menuManager, sep); >- } else if (childME instanceof MMenu) { >- MMenu itemModel = (MMenu) childME; >- processMenu(menuManager, itemModel); >- } >- } >- >- /** >- * @param menuManager >- * @param itemModel >- */ >- private void processSeparator(MenuManager menuManager, >- MMenuSeparator itemModel) { >- AbstractGroupMarker marker = null; >- if (itemModel.isVisible()) { >- marker = new Separator(); >- marker.setId(itemModel.getElementId()); >- } else { >- if (itemModel.getElementId() != null) { >- marker = new GroupMarker(itemModel.getElementId()); >+ for (ArrayList<MMenuElement> list : lists) { >+ for (MMenuElement item : list) { >+ menuModel.getChildren().remove(item); > } > } >- menuManager.add(marker); >- } >- >- /** >- * @param parentManager >- * @param itemModel >- * @param id >- * TODO >- */ >- void processDirectItem(MenuManager parentManager, >- MDirectMenuItem itemModel, String id) { >- final IEclipseContext lclContext = getContext(itemModel); >- DirectContributionItem ci = ContextInjectionFactory.make( >- DirectContributionItem.class, lclContext); >- ci.setModel(itemModel); >- ci.setVisible(itemModel.isVisible()); >- parentManager.add(ci); >- modelToContribution.put(itemModel, ci); >- } >- >- /** >- * @param parentManager >- * @param itemModel >- */ >- void processHandledItem(MenuManager parentManager, >- MHandledMenuItem itemModel) { >- final IEclipseContext lclContext = getContext(itemModel); >- HandledContributionItem ci = ContextInjectionFactory.make( >- HandledContributionItem.class, lclContext); >- ci.setModel(itemModel); >- ci.setVisible(itemModel.isVisible()); >- parentManager.add(ci); >- modelToContribution.put(itemModel, ci); >- } >- >- private String getText(MMenu menuModel) { >- String text = menuModel.getLabel(); >- if (text == null || text.length() == 0) { >- return NO_LABEL; >- } >- return text; >- } >- >- private ImageDescriptor getImageDescriptor(MUILabel element) { >- IEclipseContext localContext = context; >- String iconURI = element.getIconURI(); >- if (iconURI != null && iconURI.length() > 0) { >- ISWTResourceUtilities resUtils = (ISWTResourceUtilities) localContext >- .get(IResourceUtilities.class.getName()); >- return resUtils.imageDescriptorFromURI(URI.createURI(iconURI)); >- } >- return null; >- } >- >- public MenuManager getManager(MMenu model) { >- return modelToManager.get(model); >- } >- >- public MMenu getMenuModel(MenuManager manager) { >- return managerToModel.get(manager); >- } >- >- public void linkModelToManager(MMenu model, MenuManager manager) { >- modelToManager.put(model, manager); >- managerToModel.put(manager, model); >- manager.addMenuListener(visibilityCalculationListener); >- } >- >- public void clearModelToManager(MMenu model, MenuManager manager) { >- modelToManager.remove(model); >- managerToModel.remove(manager); >- if (manager != null) { >- manager.removeMenuListener(visibilityCalculationListener); >- } >- } >- >- public IContributionItem getContribution(MMenuElement model) { >- return modelToContribution.get(model); > } > } >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuItemRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuItemRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuItemRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuItemRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,258 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import java.util.ArrayList; >+import java.util.List; >+import java.util.Map; >+import java.util.WeakHashMap; >+import org.eclipse.e4.ui.internal.workbench.ExtensionPointProxy; >+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.menu.MMenuElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem; >+import org.eclipse.jface.action.ContributionItem; >+import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * Create a contribute part. >+ */ >+public class RenderedMenuItemRenderer extends SWTPartRenderer { >+ >+ private static Method aboutToShow; >+ >+ private static Method getAboutToShow() { >+ if (aboutToShow == null) { >+ try { >+ aboutToShow = MenuManager.class >+ .getDeclaredMethod("handleAboutToShow"); //$NON-NLS-1$ >+ aboutToShow.setAccessible(true); >+ } catch (SecurityException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (NoSuchMethodException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ return aboutToShow; >+ } >+ >+ private Map<IContributionItem, List<MenuRecord>> map = new WeakHashMap<IContributionItem, List<MenuRecord>>(); >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MRenderedMenuItem) >+ || !(parent instanceof Menu)) { >+ return null; >+ } >+ >+ MRenderedMenuItem menuModel = (MRenderedMenuItem) element; >+ Object contribution = menuModel.getContributionItem(); >+ if (contribution instanceof ExtensionPointProxy) { >+ ExtensionPointProxy proxy = (ExtensionPointProxy) contribution; >+ Object delegate = proxy.createDelegate(menuModel); >+ if (delegate != null) { >+ proxy.setField("dirty", Boolean.TRUE); //$NON-NLS-1$ >+ return fill((IContributionItem) delegate, (Menu) parent); >+ } >+ } else if (contribution instanceof IContributionItem) { >+ return fill((IContributionItem) contribution, (Menu) parent); >+ } >+ return null; >+ } >+ >+ private Object fill(IContributionItem item, Menu menu) { >+ ContributionItem contribution = (ContributionItem) item; >+ MenuManager manager = (MenuManager) contribution.getParent(); >+ try { >+ if (manager == null) { >+ manager = new MenuManager(); >+ manager.add(contribution); >+ } >+ getAboutToShow().invoke(manager, new Object[0]); >+ } catch (IllegalArgumentException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ return null; >+ } catch (IllegalAccessException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ return null; >+ } catch (InvocationTargetException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ return null; >+ } >+ >+ int itemCount = menu.getItemCount(); >+ List<MenuRecord> list = map.get(item); >+ if (list != null) { >+ for (int i = 0; i < list.size(); i++) { >+ MenuRecord record = list.get(i); >+ Menu storedMenu = record.getMenu(); >+ if (storedMenu.isDisposed()) { >+ list.remove(i); >+ i--; >+ } else if (storedMenu == menu) { >+ record.dispose(); >+ itemCount = menu.getItemCount(); >+ list.remove(i); >+ break; >+ } >+ } >+ } >+ >+ item.fill(menu, itemCount); >+ int endIndex = menu.getItemCount(); >+ >+ if (list == null) { >+ if (itemCount != endIndex) { >+ list = new ArrayList<MenuRecord>(); >+ MenuRecord record = new MenuRecord(menu); >+ for (int i = itemCount; i < endIndex; i++) { >+ record.addItem(menu.getItem(i)); >+ } >+ list.add(record); >+ map.put(item, list); >+ } >+ } else { >+ for (int i = 0; i < list.size(); i++) { >+ MenuRecord record = list.get(i); >+ if (record.getMenu() == menu) { >+ list.remove(i); >+ record = new MenuRecord(menu); >+ for (int j = itemCount; j < endIndex; j++) { >+ record.addItem(menu.getItem(j)); >+ } >+ list.add(record); >+ return null; >+ } >+ } >+ >+ MenuRecord record = new MenuRecord(menu); >+ for (int i = itemCount; i < endIndex; i++) { >+ record.addItem(menu.getItem(i)); >+ } >+ list.add(record); >+ map.put(item, list); >+ } >+ return null; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#unbindWidget >+ * (org.eclipse.e4.ui.model.application.ui.MUIElement) >+ */ >+ @Override >+ public Object unbindWidget(MUIElement me) { >+ MRenderedMenuItem item = (MRenderedMenuItem) me; >+ Object contributionItem = item.getContributionItem(); >+ if (contributionItem instanceof ExtensionPointProxy) { >+ ExtensionPointProxy proxy = (ExtensionPointProxy) contributionItem; >+ Object delegate = proxy.getDelegate(); >+ if (delegate instanceof IContributionItem) { >+ ((IContributionItem) delegate).dispose(); >+ } >+ } else if (contributionItem instanceof IContributionItem) { >+ ((IContributionItem) contributionItem).dispose(); >+ } >+ return super.unbindWidget(me); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.AbstractPartRenderer#getUIContainer >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public Object getUIContainer(MUIElement element) { >+ if (!(element instanceof MMenuElement)) >+ return null; >+ >+ if (element.getParent().getWidget() instanceof MenuItem) { >+ MenuItem mi = (MenuItem) element.getParent().getWidget(); >+ if (mi.getMenu() == null) { >+ mi.setMenu(new Menu(mi)); >+ } >+ return mi.getMenu(); >+ } >+ >+ return super.getUIContainer(element); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ */ >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ // We've delegated further rendering to the ContributionManager >+ // it's their fault the menu items don't show up! >+ } >+ >+ class MenuRecord { >+ >+ private Menu menu; >+ private List<MenuItem> items = new ArrayList<MenuItem>(); >+ >+ public MenuRecord(Menu menu) { >+ this.menu = menu; >+ } >+ >+ public Menu getMenu() { >+ return menu; >+ } >+ >+ public void addItem(MenuItem item) { >+ items.add(item); >+ } >+ >+ public void dispose() { >+ for (MenuItem item : items) { >+ item.dispose(); >+ } >+ } >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedMenuRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,150 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+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.MWindow; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.jface.action.IMenuCreator; >+import org.eclipse.jface.action.IMenuManager; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Decorations; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * Create a contribute part. >+ */ >+public class RenderedMenuRenderer extends SWTPartRenderer { >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MRenderedMenu)) >+ return null; >+ >+ MRenderedMenu menuModel = (MRenderedMenu) element; >+ Object contributionManager = menuModel.getContributionManager(); >+ if (contributionManager instanceof MenuManager) { >+ Menu newMenu = null; >+ MenuManager mm = (MenuManager) contributionManager; >+ MUIElement container = (MUIElement) ((EObject) menuModel) >+ .eContainer(); >+ if (parent instanceof Decorations && container instanceof MWindow) { >+ newMenu = mm.createMenuBar((Decorations) parent); >+ } else if (parent instanceof Menu) { >+ mm.update(true); >+ newMenu = mm.getMenu(); >+ } else { >+ newMenu = mm.createContextMenu((Control) parent); >+ } >+ mm.update(true); >+ return newMenu; >+ } else if (contributionManager instanceof IMenuCreator) { >+ final IMenuCreator creator = (IMenuCreator) contributionManager; >+ if (parent instanceof Control) { >+ Control control = (Control) parent; >+ return creator.getMenu(control); >+ } else if (parent instanceof Menu) { >+ int addIndex = calcVisibleIndex(menuModel); >+ MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, >+ addIndex); >+ setItemText(menuModel, newItem); >+ newItem.setImage(getImage(menuModel)); >+ newItem.setEnabled(menuModel.isEnabled()); >+ Menu menu = (Menu) parent; >+ newItem.setMenu(creator.getMenu(menu)); >+ return newItem; >+ } >+ } >+ >+ return null; >+ } >+ >+ private void setItemText(MMenu model, MenuItem item) { >+ String text = model.getLabel(); >+ if (text == null) { >+ text = ""; //$NON-NLS-1$ >+ } >+ item.setText(text); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); >+ } >+ >+ @Override >+ public Object unbindWidget(MUIElement me) { >+ MRenderedMenu menuModel = (MRenderedMenu) me; >+ Object contributionManager = menuModel.getContributionManager(); >+ if (contributionManager instanceof IMenuManager) { >+ ((IMenuManager) contributionManager).dispose(); >+ } >+ return super.unbindWidget(me); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.AbstractPartRenderer#getUIContainer >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public Object getUIContainer(MUIElement element) { >+ if (!(element instanceof MMenuElement)) >+ return null; >+ >+ if (element.getParent().getWidget() instanceof MenuItem) { >+ MenuItem mi = (MenuItem) element.getParent().getWidget(); >+ if (mi.getMenu() == null) { >+ mi.setMenu(new Menu(mi)); >+ } >+ return mi.getMenu(); >+ } >+ >+ return super.getUIContainer(element); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ */ >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ // We've delegated further rendering to the ContributionManager >+ // it's their fault the menu items don't show up! >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,309 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import javax.inject.Inject; >+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.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; >+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.MToolBarElement; >+import org.eclipse.e4.ui.workbench.IPresentationEngine; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.jface.action.ToolBarManager; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * Create a contribute part. >+ */ >+public class RenderedToolBarRenderer extends SWTPartRenderer { >+ >+ public static final String TAG_VIEW_MENU = "ViewMenu"; //$NON-NLS-1$ >+ >+ private MApplication application; >+ >+ @Inject >+ IPresentationEngine renderer; >+ >+ HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup = new HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>>(); >+ >+ private Image viewMenuImage; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#init(org.eclipse >+ * .e4.core.contexts.IEclipseContext) >+ */ >+ @Override >+ public void init(IEclipseContext context) { >+ super.init(context); >+ application = context.get(MApplication.class); >+ } >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MRenderedToolBar) >+ || !(parent instanceof Composite)) >+ return null; >+ >+ final MRenderedToolBar toolBar = (MRenderedToolBar) element; >+ if (!(toolBar.getContributionManager() instanceof ToolBarManager)) { >+ return null; >+ } >+ >+ ToolBarManager tbm = (ToolBarManager) toolBar.getContributionManager(); >+ ToolBar tb = tbm.createControl((Composite) parent); >+ if (tb.getParent() != parent) { >+ tb.setParent((Composite) parent); >+ tb.setVisible(true); >+ } >+ >+ tbm.update(true); >+ tb.setData(ToolBarManager.class.getName(), tbm); >+ tb.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp(toolBar); >+ } >+ }); >+ >+ tb.getParent().layout(true); >+ >+ return tb; >+ } >+ >+ /** >+ * @param toolBar >+ */ >+ protected void cleanUp(MRenderedToolBar element) { >+ ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup >+ .remove(element); >+ if (lists == null) { >+ return; >+ } >+ for (ArrayList<MToolBarElement> list : lists) { >+ for (MToolBarElement child : list) { >+ element.getChildren().remove(child); >+ } >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ */ >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ // We've delegated further rendering to the ContributionManager >+ // it's their fault the menu items don't show up! >+ IEclipseContext ctx = getContext(container); >+ ExpressionContext eContext = new ExpressionContext(ctx); >+ ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); >+ MElementContainer<?> toolbarObj = container; >+ MToolBar toolbarModel = (MToolBar) toolbarObj; >+ ContributionsAnalyzer.gatherToolBarContributions(toolbarModel, >+ application.getToolBarContributions(), >+ toolbarModel.getElementId(), toContribute, eContext); >+ ToolBarRenderer.addToolBarContributions(toolbarModel, toContribute, >+ ctx, eContext, pendingCleanup); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#postProcess >+ * (org.eclipse.e4.ui.model.application.ui.MUIElement) >+ */ >+ @Override >+ public void postProcess(MUIElement element) { >+ ToolBar tb = (ToolBar) element.getWidget(); >+ if (((EObject) element).eContainer() instanceof MPart) { >+ MPart part = (MPart) ((EObject) element).eContainer(); >+ MMenu viewMenu = getViewMenu(part); >+ >+ // View menu (if any) >+ if (viewMenu != null) { >+ addMenuButton(part, tb, viewMenu); >+ } >+ } >+ >+ tb.pack(); >+ tb.setVisible(true); >+ super.postProcess(element); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#disposeWidget >+ * (org.eclipse.e4.ui.model.application.ui.MUIElement) >+ */ >+ @Override >+ public void disposeWidget(MUIElement element) { >+ ToolBar tb = (ToolBar) element.getWidget(); >+ tb.setVisible(false); >+ unbindWidget(element); >+ tb.setData(AbstractPartRenderer.OWNING_ME, element); >+ } >+ >+ /** >+ * @param tb >+ */ >+ private void addMenuButton(MPart part, ToolBar tb, MMenu menu) { >+ ToolItem ti = new ToolItem(tb, SWT.PUSH); >+ ti.setImage(getViewMenuImage()); >+ ti.setHotImage(null); >+ ti.setToolTipText("View Menu"); //$NON-NLS-1$ >+ ti.setData("theMenu", menu); //$NON-NLS-1$ >+ ti.setData("thePart", part); //$NON-NLS-1$ >+ >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ }); >+ } >+ >+ /** >+ * @param item >+ */ >+ protected void showMenu(ToolItem item) { >+ // Create the UI for the menu >+ final MMenu menuModel = (MMenu) item.getData("theMenu"); //$NON-NLS-1$ >+ MPart part = (MPart) item.getData("thePart"); //$NON-NLS-1$ >+ Control ctrl = (Control) part.getWidget(); >+ Menu menu = (Menu) renderer.createGui(menuModel, ctrl.getShell(), >+ part.getContext()); >+ >+ // ...and Show it... >+ Rectangle ib = item.getBounds(); >+ Point displayAt = item.getParent().toDisplay(ib.x, ib.y + ib.height); >+ menu.setLocation(displayAt); >+ menu.setVisible(true); >+ >+ Display display = Display.getCurrent(); >+ while (!menu.isDisposed() && menu.isVisible()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ menu.dispose(); >+ } >+ >+ private Image getViewMenuImage() { >+ if (viewMenuImage == null) { >+ Display d = Display.getCurrent(); >+ >+ Image viewMenu = new Image(d, 16, 16); >+ Image viewMenuMask = new Image(d, 16, 16); >+ >+ Display display = Display.getCurrent(); >+ GC gc = new GC(viewMenu); >+ GC maskgc = new GC(viewMenuMask); >+ gc.setForeground(display >+ .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >+ gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); >+ >+ int[] shapeArray = new int[] { 6, 1, 15, 1, 11, 5, 10, 5 }; >+ gc.fillPolygon(shapeArray); >+ gc.drawPolygon(shapeArray); >+ >+ Color black = display.getSystemColor(SWT.COLOR_BLACK); >+ Color white = display.getSystemColor(SWT.COLOR_WHITE); >+ >+ maskgc.setBackground(black); >+ maskgc.fillRectangle(0, 0, 16, 16); >+ >+ maskgc.setBackground(white); >+ maskgc.setForeground(white); >+ maskgc.fillPolygon(shapeArray); >+ maskgc.drawPolygon(shapeArray); >+ gc.dispose(); >+ maskgc.dispose(); >+ >+ ImageData data = viewMenu.getImageData(); >+ data.transparentPixel = data.getPixel(0, 0); >+ >+ viewMenuImage = new Image(d, viewMenu.getImageData(), >+ viewMenuMask.getImageData()); >+ viewMenu.dispose(); >+ viewMenuMask.dispose(); >+ } >+ return viewMenuImage; >+ } >+ >+ private MMenu getViewMenu(MPart part) { >+ if (part.getMenus() == null) { >+ return null; >+ } >+ for (MMenu menu : part.getMenus()) { >+ if (menu.getTags().contains(TAG_VIEW_MENU)) { >+ return menu; >+ } >+ } >+ return null; >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java,v >retrieving revision 1.23 >diff -u -r1.23 StackRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java 12 Oct 2010 16:17:56 -0000 1.23 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java 14 Oct 2010 18:20:39 -0000 >@@ -30,6 +30,7 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MStackElement; > 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.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.services.IStylingEngine; >@@ -403,7 +404,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MToolBar) >+ if (tbME instanceof MRenderedToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >@@ -522,7 +523,7 @@ > if (!curTB.isDisposed()) { > MUIElement tbME = (MUIElement) curTB > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbME instanceof MToolBar) >+ if (tbME instanceof MRenderedToolBar) > renderer.removeGui(tbME); > else > curTB.dispose(); >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,826 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.List; >+import java.util.Map; >+import javax.annotation.PostConstruct; >+import javax.annotation.PreDestroy; >+import javax.inject.Inject; >+import org.eclipse.e4.core.contexts.ContextInjectionFactory; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.contexts.RunAndTrack; >+import org.eclipse.e4.core.services.events.IEventBroker; >+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.SideValue; >+import org.eclipse.e4.ui.model.application.ui.basic.MPart; >+import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; >+import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+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.MToolBarElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; >+import org.eclipse.e4.ui.workbench.IPresentationEngine; >+import org.eclipse.e4.ui.workbench.UIEvents; >+import org.eclipse.e4.ui.workbench.modeling.EModelService; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.util.EcoreUtil; >+import org.eclipse.jface.action.AbstractGroupMarker; >+import org.eclipse.jface.action.ContributionItem; >+import org.eclipse.jface.action.GroupMarker; >+import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.Separator; >+import org.eclipse.jface.action.ToolBarManager; >+import org.eclipse.jface.layout.RowLayoutFactory; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Widget; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventHandler; >+ >+/** >+ * Create a contribute part. >+ */ >+public class ToolBarManagerRenderer extends SWTPartRenderer { >+ >+ private Map<MToolBar, ToolBarManager> modelToManager = new HashMap<MToolBar, ToolBarManager>(); >+ private Map<ToolBarManager, MToolBar> managerToModel = new HashMap<ToolBarManager, MToolBar>(); >+ >+ private Map<MToolBarElement, IContributionItem> modelToContribution = new HashMap<MToolBarElement, IContributionItem>(); >+ >+ private ArrayList<ContributionRecord> contributionRecords = new ArrayList<ContributionRecord>(); >+ >+ // @Inject >+ // private Logger logger; >+ >+ @Inject >+ IPresentationEngine renderer; >+ @Inject >+ private MApplication application; >+ @Inject >+ private EModelService modelService; >+ >+ @Inject >+ IEventBroker eventBroker; >+ private EventHandler itemUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >+ return; >+ >+ MToolBarElement itemModel = (MToolBarElement) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ >+ IContributionItem ici = getContribution(itemModel); >+ if (ici == null) { >+ return; >+ } >+ >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (UIEvents.UILabel.LABEL.equals(attName)) { >+ ici.update(); >+ } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >+ ici.update(); >+ } else if (UIEvents.UILabel.TOOLTIP.equals(attName)) { >+ ici.update(); >+ } >+ } >+ }; >+ >+ private EventHandler toBeRenderedUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >+ return; >+ >+ MToolBarElement itemModel = (MToolBarElement) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (UIEvents.UIElement.TOBERENDERED.equals(attName)) { >+ Object obj = itemModel.getParent(); >+ if (!(obj instanceof MToolBar)) { >+ return; >+ } >+ ToolBarManager parent = getManager((MToolBar) obj); >+ if (itemModel.isToBeRendered()) { >+ if (parent != null) { >+ modelProcessSwitch(parent, itemModel); >+ parent.update(true); >+ ToolBar tb = parent.getControl(); >+ if (tb != null && !tb.isDisposed()) { >+ tb.getShell().layout(new Control[] { tb }, >+ SWT.DEFER); >+ } >+ } >+ } else { >+ IContributionItem ici = modelToContribution >+ .remove(itemModel); >+ if (ici != null && parent != null) { >+ parent.remove(ici); >+ } >+ if (ici != null) { >+ ici.dispose(); >+ } >+ } >+ } else if (UIEvents.UIElement.VISIBLE.equals(attName)) { >+ IContributionItem ici = getContribution(itemModel); >+ if (ici == null) { >+ return; >+ } >+ ici.setVisible(itemModel.isVisible()); >+ ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici) >+ .getParent(); >+ if (parent != null) { >+ parent.markDirty(); >+ ToolBar tb = parent.getControl(); >+ if (tb != null && !tb.isDisposed()) { >+ tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ } >+ } >+ } >+ } >+ }; >+ >+ private EventHandler selectionUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >+ return; >+ >+ MToolBarElement itemModel = (MToolBarElement) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ IContributionItem ici = getContribution(itemModel); >+ if (ici != null) { >+ ici.update(); >+ } >+ } >+ }; >+ >+ private EventHandler enabledUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MMenuItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >+ return; >+ >+ MToolBarElement itemModel = (MToolBarElement) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ IContributionItem ici = getContribution(itemModel); >+ if (ici != null) { >+ ici.update(); >+ } >+ } >+ }; >+ private Image viewMenuImage; >+ >+ @PostConstruct >+ public void init() { >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >+ itemUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.SELECTED), selectionUpdater); >+ eventBroker >+ .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.ENABLED), enabledUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC, >+ UIEvents.UIElement.TOBERENDERED), toBeRenderedUpdater); >+ >+ } >+ >+ @PreDestroy >+ public void contextDisposed() { >+ eventBroker.unsubscribe(itemUpdater); >+ eventBroker.unsubscribe(selectionUpdater); >+ eventBroker.unsubscribe(enabledUpdater); >+ eventBroker.unsubscribe(toBeRenderedUpdater); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget >+ * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) >+ */ >+ @Override >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MToolBar) || !(parent instanceof Composite)) >+ return null; >+ >+ // HACK!! This should be done using a separate renderer >+ Composite intermediate = new Composite((Composite) parent, SWT.NONE); >+ createToolbar(element, intermediate); >+ processContribution((MToolBar) element); >+ >+ return intermediate; >+ } >+ >+ /** >+ * @param element >+ */ >+ private void processContribution(MToolBar toolbarModel) { >+ final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); >+ ContributionsAnalyzer.XXXgatherToolBarContributions(toolbarModel, >+ application.getToolBarContributions(), >+ toolbarModel.getElementId(), toContribute); >+ generateContributions(toolbarModel, toContribute); >+ } >+ >+ /** >+ * @param toolbarModel >+ * @param toContribute >+ */ >+ private void generateContributions(MToolBar toolbarModel, >+ ArrayList<MToolBarContribution> toContribute) { >+ HashSet<String> existingSeparatorNames = new HashSet<String>(); >+ for (MToolBarElement child : toolbarModel.getChildren()) { >+ String elementId = child.getElementId(); >+ if (child instanceof MToolBarSeparator && elementId != null) { >+ existingSeparatorNames.add(elementId); >+ } >+ } >+ >+ ToolBarManager manager = getManager(toolbarModel); >+ boolean done = toContribute.size() == 0; >+ while (!done) { >+ ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>( >+ toContribute); >+ int retryCount = toContribute.size(); >+ toContribute.clear(); >+ >+ for (final MToolBarContribution contribution : curList) { >+ if (!processAddition(toolbarModel, manager, contribution, >+ existingSeparatorNames)) { >+ toContribute.add(contribution); >+ } >+ } >+ // We're done if the retryList is now empty (everything done) or >+ // if the list hasn't changed at all (no hope) >+ done = (toContribute.size() == 0) >+ || (toContribute.size() == retryCount); >+ } >+ } >+ >+ static class ContributionRecord { >+ public ContributionRecord(MToolBar toolbarModel, >+ MToolBarContribution contribution, ToolBarManager manager) { >+ this.toolbarModel = toolbarModel; >+ this.contribution = contribution; >+ this.manager = manager; >+ } >+ >+ MToolBar toolbarModel; >+ MToolBarContribution contribution; >+ ToolBarManager manager; >+ ArrayList<MToolBarElement> generatedElements = new ArrayList<MToolBarElement>(); >+ >+ public void generate() { >+ for (MToolBarElement element : contribution.getChildren()) { >+ MToolBarElement copy = (MToolBarElement) EcoreUtil >+ .copy((EObject) element); >+ generatedElements.add(copy); >+ } >+ } >+ >+ public void updateVisibility(IEclipseContext context) { >+ ExpressionContext exprContext = new ExpressionContext(context); >+ boolean isVisible = ContributionsAnalyzer.isVisible(contribution, >+ exprContext); >+ for (MToolBarElement item : generatedElements) { >+ item.setVisible(isVisible); >+ } >+ manager.markDirty(); >+ } >+ >+ public void dispose() { >+ for (MToolBarElement copy : generatedElements) { >+ toolbarModel.getChildren().remove(copy); >+ } >+ } >+ } >+ >+ /** >+ * @param toolbarModel >+ * @param manager >+ * @param contribution >+ * @param existingSeparatorNames >+ * @return <code>true</code> if the contribution was successfuly processed >+ */ >+ private boolean processAddition(MToolBar toolbarModel, >+ final ToolBarManager manager, MToolBarContribution contribution, >+ HashSet<String> existingSeparatorNames) { >+ int idx = getIndex(toolbarModel, contribution.getPositionInParent()); >+ if (idx == -1) { >+ return false; >+ } >+ final ContributionRecord record = new ContributionRecord(toolbarModel, >+ contribution, manager); >+ contributionRecords.add(record); >+ record.generate(); >+ for (MToolBarElement copy : record.generatedElements) { >+ if (copy instanceof MToolBarSeparator >+ && existingSeparatorNames.contains(copy.getElementId())) { >+ // skip this, it's already there >+ continue; >+ } >+ toolbarModel.getChildren().add(idx++, copy); >+ if (copy instanceof MToolBarSeparator >+ && copy.getElementId() != null) { >+ existingSeparatorNames.add(copy.getElementId()); >+ } >+ } >+ if (contribution.getVisibleWhen() != null) { >+ final IEclipseContext parentContext = modelService >+ .getContainingContext(toolbarModel); >+ parentContext.runAndTrack(new RunAndTrack() { >+ @Override >+ public boolean changed(IEclipseContext context) { >+ record.updateVisibility(parentContext.getActiveLeaf()); >+ manager.update(false); >+ return true; >+ } >+ }); >+ } >+ >+ return true; >+ } >+ >+ private static int getIndex(MElementContainer<?> menuModel, >+ String positionInParent) { >+ String id = null; >+ String modifier = null; >+ if (positionInParent != null && positionInParent.length() > 0) { >+ String[] array = positionInParent.split("="); //$NON-NLS-1$ >+ modifier = array[0]; >+ id = array[1]; >+ } >+ if (id == null) { >+ return menuModel.getChildren().size(); >+ } >+ >+ int idx = 0; >+ int size = menuModel.getChildren().size(); >+ while (idx < size) { >+ if (id.equals(menuModel.getChildren().get(idx).getElementId())) { >+ if ("after".equals(modifier)) { //$NON-NLS-1$ >+ idx++; >+ } >+ return idx; >+ } >+ idx++; >+ } >+ return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ >+ } >+ >+ private ToolBar createToolbar(final MUIElement element, >+ Composite intermediate) { >+ int orientation = getOrientation(element); >+ RowLayout layout = RowLayoutFactory.fillDefaults().wrap(false) >+ .spacing(0).type(orientation).create(); >+ layout.marginLeft = 3; >+ layout.center = true; >+ intermediate.setLayout(layout); >+ // new Label(intermediate, (orientation == SWT.HORIZONTAL ? SWT.VERTICAL >+ // : SWT.HORIZONTAL) | SWT.SEPARATOR); >+ >+ ToolBar separatorToolBar = new ToolBar(intermediate, orientation >+ | SWT.WRAP | SWT.FLAT | SWT.RIGHT); >+ new ToolItem(separatorToolBar, SWT.SEPARATOR); >+ ToolBarManager manager = getManager((MToolBar) element); >+ if (manager == null) { >+ manager = new ToolBarManager(orientation | SWT.WRAP | SWT.FLAT >+ | SWT.RIGHT); >+ linkModelToManager((MToolBar) element, manager); >+ } >+ ToolBar bar = manager.createControl(intermediate); >+ bar.setData(manager); >+ bar.getShell().layout(new Control[] { bar }, SWT.DEFER); >+ bar.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp((MToolBar) element); >+ } >+ }); >+ return bar; >+ } >+ >+ /** >+ * @param element >+ */ >+ protected void cleanUp(MToolBar toolbarModel) { >+ for (ContributionRecord record : contributionRecords >+ .toArray(new ContributionRecord[contributionRecords.size()])) { >+ if (record.toolbarModel == toolbarModel) { >+ record.dispose(); >+ contributionRecords.remove(record); >+ for (MToolBarElement copy : record.generatedElements) { >+ IContributionItem ici = modelToContribution.remove(copy); >+ if (ici != null) { >+ record.manager.remove(ici); >+ } >+ } >+ record.generatedElements.clear(); >+ } >+ } >+ } >+ >+ int getOrientation(final MUIElement element) { >+ MUIElement theParent = element.getParent(); >+ if (theParent instanceof MTrimBar) { >+ MTrimBar trimContainer = (MTrimBar) theParent; >+ SideValue side = trimContainer.getSide(); >+ if (side.getValue() == SideValue.LEFT_VALUE >+ || side.getValue() == SideValue.RIGHT_VALUE) >+ return SWT.VERTICAL; >+ } >+ return SWT.HORIZONTAL; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >+ * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >+ */ >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ // I can either simply stop processing, or we can walk the model >+ // ourselves like the "old" days >+ // EMF gives us null lists if empty >+ if (container == null) >+ return; >+ >+ Object obj = container; >+ ToolBarManager parentManager = getManager((MToolBar) obj); >+ if (parentManager == null) { >+ return; >+ } >+ // Process any contents of the newly created ME >+ List<MUIElement> parts = container.getChildren(); >+ if (parts != null) { >+ MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]); >+ for (int i = 0; i < plist.length; i++) { >+ MUIElement childME = plist[i]; >+ modelProcessSwitch(parentManager, (MToolBarElement) childME); >+ } >+ } >+ parentManager.update(false); >+ >+ ToolBar tb = getToolbarFrom(container.getWidget()); >+ if (tb != null && ((EObject) container).eContainer() instanceof MPart) { >+ MPart part = (MPart) ((EObject) container).eContainer(); >+ MMenu viewMenu = getViewMenu(part); >+ >+ // View menu (if any) >+ if (viewMenu != null) { >+ addMenuButton(part, tb, viewMenu); >+ } >+ tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ } >+ } >+ >+ /** >+ * @param widget >+ * @return >+ */ >+ private ToolBar getToolbarFrom(Object widget) { >+ if (widget instanceof ToolBar) { >+ return (ToolBar) widget; >+ } >+ if (widget instanceof Composite) { >+ Composite intermediate = (Composite) widget; >+ if (!intermediate.isDisposed()) { >+ Control[] children = intermediate.getChildren(); >+ int length = children.length; >+ if (length > 0 && children[length - 1] instanceof ToolBar) { >+ return (ToolBar) children[length - 1]; >+ } >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * @param tb >+ */ >+ private void addMenuButton(MPart part, ToolBar tb, MMenu menu) { >+ ToolItem ti = new ToolItem(tb, SWT.PUSH); >+ ti.setImage(getViewMenuImage()); >+ ti.setHotImage(null); >+ ti.setToolTipText("View Menu"); //$NON-NLS-1$ >+ ti.setData("theMenu", menu); //$NON-NLS-1$ >+ ti.setData("thePart", part); //$NON-NLS-1$ >+ >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ showMenu((ToolItem) e.widget); >+ } >+ }); >+ } >+ >+ /** >+ * @param item >+ */ >+ protected void showMenu(ToolItem item) { >+ // Create the UI for the menu >+ final MMenu menuModel = (MMenu) item.getData("theMenu"); //$NON-NLS-1$ >+ MPart part = (MPart) item.getData("thePart"); //$NON-NLS-1$ >+ Control ctrl = (Control) part.getWidget(); >+ Menu menu = (Menu) renderer.createGui(menuModel, ctrl.getShell(), >+ part.getContext()); >+ >+ // ...and Show it... >+ Rectangle ib = item.getBounds(); >+ Point displayAt = item.getParent().toDisplay(ib.x, ib.y + ib.height); >+ menu.setLocation(displayAt); >+ menu.setVisible(true); >+ >+ Display display = Display.getCurrent(); >+ while (!menu.isDisposed() && menu.isVisible()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ menu.dispose(); >+ } >+ >+ private Image getViewMenuImage() { >+ if (viewMenuImage == null) { >+ Display d = Display.getCurrent(); >+ >+ Image viewMenu = new Image(d, 16, 16); >+ Image viewMenuMask = new Image(d, 16, 16); >+ >+ Display display = Display.getCurrent(); >+ GC gc = new GC(viewMenu); >+ GC maskgc = new GC(viewMenuMask); >+ gc.setForeground(display >+ .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >+ gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); >+ >+ int[] shapeArray = new int[] { 6, 1, 15, 1, 11, 5, 10, 5 }; >+ gc.fillPolygon(shapeArray); >+ gc.drawPolygon(shapeArray); >+ >+ Color black = display.getSystemColor(SWT.COLOR_BLACK); >+ Color white = display.getSystemColor(SWT.COLOR_WHITE); >+ >+ maskgc.setBackground(black); >+ maskgc.fillRectangle(0, 0, 16, 16); >+ >+ maskgc.setBackground(white); >+ maskgc.setForeground(white); >+ maskgc.fillPolygon(shapeArray); >+ maskgc.drawPolygon(shapeArray); >+ gc.dispose(); >+ maskgc.dispose(); >+ >+ ImageData data = viewMenu.getImageData(); >+ data.transparentPixel = data.getPixel(0, 0); >+ >+ viewMenuImage = new Image(d, viewMenu.getImageData(), >+ viewMenuMask.getImageData()); >+ viewMenu.dispose(); >+ viewMenuMask.dispose(); >+ } >+ return viewMenuImage; >+ } >+ >+ private MMenu getViewMenu(MPart part) { >+ if (part.getMenus() == null) { >+ return null; >+ } >+ for (MMenu menu : part.getMenus()) { >+ if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >+ return menu; >+ } >+ } >+ return null; >+ } >+ >+ boolean hasOnlySeparators(ToolBar toolbar) { >+ ToolItem[] children = toolbar.getItems(); >+ for (ToolItem toolItem : children) { >+ if ((toolItem.getStyle() & SWT.SEPARATOR) == 0) { >+ return false; >+ } else if (toolItem.getControl() != null >+ && toolItem.getControl().getData(OWNING_ME) instanceof MToolControl) { >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ @Override >+ public void postProcess(MUIElement element) { >+ super.postProcess(element); >+ // disposeToolbarIfNecessary(element); >+ ToolBar tb = getToolbarFrom(element.getWidget()); >+ if (tb != null && !tb.isDisposed()) { >+ tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ tb.setVisible(true); >+ } >+ } >+ >+ public Object getUIContainer(MUIElement childElement) { >+ if (childElement.getWidget() instanceof ToolBar) { >+ return childElement.getWidget(); >+ } >+ >+ Object obj = super.getUIContainer(childElement); >+ if (obj instanceof ToolBar) { >+ return obj; >+ } >+ >+ if (obj instanceof Composite) { >+ Composite intermediate = (Composite) obj; >+ if (intermediate == null || intermediate.isDisposed()) { >+ return null; >+ } >+ ToolBar toolbar = getToolbarFrom(intermediate); >+ if (toolbar == null) { >+ toolbar = createToolbar(childElement.getParent(), intermediate); >+ } >+ return toolbar; >+ } >+ return null; >+ } >+ >+ @Override >+ public void disposeWidget(MUIElement element) { >+ ToolBar tb = getToolbarFrom(element.getWidget()); >+ tb.setVisible(false); >+ unbindWidget(element); >+ tb.setData(AbstractPartRenderer.OWNING_ME, element); >+ } >+ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) { >+ widget.dispose(); >+ } >+ ToolBar toolbar = (ToolBar) getUIContainer(child); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } >+ // disposeToolbarIfNecessary(parentElement); >+ } >+ >+ @Override >+ public void childRendered(MElementContainer<MUIElement> parentElement, >+ MUIElement element) { >+ super.childRendered(parentElement, element); >+ ToolBar toolbar = (ToolBar) getUIContainer(element); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } >+ } >+ >+ /** >+ * @param parentManager >+ * @param childME >+ */ >+ private void modelProcessSwitch(ToolBarManager parentManager, >+ MToolBarElement childME) { >+ if (childME instanceof MHandledToolItem) { >+ MHandledToolItem itemModel = (MHandledToolItem) childME; >+ processHandledItem(parentManager, itemModel); >+ } else if (childME instanceof MDirectToolItem) { >+ MDirectToolItem itemModel = (MDirectToolItem) childME; >+ processDirectItem(parentManager, itemModel); >+ } else if (childME instanceof MToolBarSeparator) { >+ MToolBarSeparator itemModel = (MToolBarSeparator) childME; >+ processSeparator(parentManager, itemModel); >+ } else if (childME instanceof MToolControl) { >+ MToolControl itemModel = (MToolControl) childME; >+ processToolControl(parentManager, itemModel); >+ } >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ */ >+ private void processSeparator(ToolBarManager parentManager, >+ MToolBarSeparator itemModel) { >+ AbstractGroupMarker marker = null; >+ if (itemModel.isVisible()) { >+ marker = new Separator(); >+ marker.setId(itemModel.getElementId()); >+ } else { >+ if (itemModel.getElementId() != null) { >+ marker = new GroupMarker(itemModel.getElementId()); >+ } >+ } >+ parentManager.add(marker); >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ */ >+ private void processToolControl(ToolBarManager parentManager, >+ MToolControl itemModel) { >+ final IEclipseContext lclContext = getContext(itemModel); >+ ToolControlContribution ci = ContextInjectionFactory.make( >+ ToolControlContribution.class, lclContext); >+ ci.setModel(itemModel); >+ parentManager.add(ci); >+ modelToContribution.put(itemModel, ci); >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ */ >+ private void processDirectItem(ToolBarManager parentManager, >+ MDirectToolItem itemModel) { >+ final IEclipseContext lclContext = getContext(itemModel); >+ DirectContributionItem ci = ContextInjectionFactory.make( >+ DirectContributionItem.class, lclContext); >+ ci.setModel(itemModel); >+ parentManager.add(ci); >+ modelToContribution.put(itemModel, ci); >+ } >+ >+ /** >+ * @param parentManager >+ * @param itemModel >+ */ >+ private void processHandledItem(ToolBarManager parentManager, >+ MHandledToolItem itemModel) { >+ final IEclipseContext lclContext = getContext(itemModel); >+ HandledContributionItem ci = ContextInjectionFactory.make( >+ HandledContributionItem.class, lclContext); >+ ci.setModel(itemModel); >+ parentManager.add(ci); >+ modelToContribution.put(itemModel, ci); >+ } >+ >+ public ToolBarManager getManager(MToolBar model) { >+ return modelToManager.get(model); >+ } >+ >+ public MToolBar getToolBarModel(ToolBarManager manager) { >+ return managerToModel.get(manager); >+ } >+ >+ public void linkModelToManager(MToolBar model, ToolBarManager manager) { >+ modelToManager.put(model, manager); >+ managerToModel.put(manager, model); >+ } >+ >+ public void clearModelToManager(MToolBar model, ToolBarManager manager) { >+ modelToManager.remove(model); >+ managerToModel.remove(manager); >+ } >+ >+ public IContributionItem getContribution(MToolBarElement element) { >+ return modelToContribution.get(element); >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java,v >retrieving revision 1.10 >diff -u -r1.10 ToolBarRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java 12 Oct 2010 16:17:56 -0000 1.10 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java 14 Oct 2010 18:20:40 -0000 >@@ -13,232 +13,52 @@ > import java.util.ArrayList; > import java.util.HashMap; > import java.util.HashSet; >-import java.util.List; >-import java.util.Map; >-import javax.annotation.PostConstruct; >-import javax.annotation.PreDestroy; >-import javax.inject.Inject; >-import org.eclipse.e4.core.contexts.ContextInjectionFactory; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.core.contexts.RunAndTrack; >-import org.eclipse.e4.core.services.events.IEventBroker; > 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.SideValue; >-import org.eclipse.e4.ui.model.application.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; >-import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; >-import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; >-import org.eclipse.e4.ui.model.application.ui.menu.MMenu; > 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.MToolBarElement; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; > import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; >-import org.eclipse.e4.ui.workbench.IPresentationEngine; >-import org.eclipse.e4.ui.workbench.UIEvents; >-import org.eclipse.e4.ui.workbench.modeling.EModelService; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >-import org.eclipse.emf.ecore.EObject; >-import org.eclipse.emf.ecore.util.EcoreUtil; >-import org.eclipse.jface.action.AbstractGroupMarker; >-import org.eclipse.jface.action.ContributionItem; >-import org.eclipse.jface.action.GroupMarker; >-import org.eclipse.jface.action.IContributionItem; >-import org.eclipse.jface.action.Separator; >-import org.eclipse.jface.action.ToolBarManager; > import org.eclipse.jface.layout.RowLayoutFactory; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.GC; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.graphics.ImageData; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.layout.RowLayout; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.ToolBar; > import org.eclipse.swt.widgets.ToolItem; > import org.eclipse.swt.widgets.Widget; >-import org.osgi.service.event.Event; >-import org.osgi.service.event.EventHandler; > > /** > * Create a contribute part. > */ > public class ToolBarRenderer extends SWTPartRenderer { >- >- private Map<MToolBar, ToolBarManager> modelToManager = new HashMap<MToolBar, ToolBarManager>(); >- private Map<ToolBarManager, MToolBar> managerToModel = new HashMap<ToolBarManager, MToolBar>(); >- >- private Map<MToolBarElement, IContributionItem> modelToContribution = new HashMap<MToolBarElement, IContributionItem>(); >- >- private ArrayList<ContributionRecord> contributionRecords = new ArrayList<ContributionRecord>(); >- >- // @Inject >- // private Logger logger; >- >- @Inject >- IPresentationEngine renderer; >- @Inject > private MApplication application; >- @Inject >- private EModelService modelService; >- >- @Inject >- IEventBroker eventBroker; >- private EventHandler itemUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MMenuItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >- return; >- >- MToolBarElement itemModel = (MToolBarElement) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- >- IContributionItem ici = getContribution(itemModel); >- if (ici == null) { >- return; >- } >- >- String attName = (String) event >- .getProperty(UIEvents.EventTags.ATTNAME); >- if (UIEvents.UILabel.LABEL.equals(attName)) { >- ici.update(); >- } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >- ici.update(); >- } else if (UIEvents.UILabel.TOOLTIP.equals(attName)) { >- ici.update(); >- } >- } >- }; >- >- private EventHandler toBeRenderedUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MMenuItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >- return; >- >- MToolBarElement itemModel = (MToolBarElement) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- String attName = (String) event >- .getProperty(UIEvents.EventTags.ATTNAME); >- if (UIEvents.UIElement.TOBERENDERED.equals(attName)) { >- Object obj = itemModel.getParent(); >- if (!(obj instanceof MToolBar)) { >- return; >- } >- ToolBarManager parent = getManager((MToolBar) obj); >- if (itemModel.isToBeRendered()) { >- if (parent != null) { >- modelProcessSwitch(parent, itemModel); >- parent.update(true); >- ToolBar tb = parent.getControl(); >- if (tb != null && !tb.isDisposed()) { >- tb.getShell().layout(new Control[] { tb }, >- SWT.DEFER); >- } >- } >- } else { >- IContributionItem ici = modelToContribution >- .remove(itemModel); >- if (ici != null && parent != null) { >- parent.remove(ici); >- } >- if (ici != null) { >- ici.dispose(); >- } >- } >- } else if (UIEvents.UIElement.VISIBLE.equals(attName)) { >- IContributionItem ici = getContribution(itemModel); >- if (ici == null) { >- return; >- } >- ici.setVisible(itemModel.isVisible()); >- ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici) >- .getParent(); >- if (parent != null) { >- parent.markDirty(); >- ToolBar tb = parent.getControl(); >- if (tb != null && !tb.isDisposed()) { >- tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >- } >- } >- } >- } >- }; >- >- private EventHandler selectionUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MToolItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >- return; >- >- MToolBarElement itemModel = (MToolBarElement) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = getContribution(itemModel); >- if (ici != null) { >- ici.update(); >- } >- } >- }; >- >- private EventHandler enabledUpdater = new EventHandler() { >- public void handleEvent(Event event) { >- // Ensure that this event is for a MMenuItem >- if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) >- return; >- >- MToolBarElement itemModel = (MToolBarElement) event >- .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = getContribution(itemModel); >- if (ici != null) { >- ici.update(); >- } >- } >- }; >- private Image viewMenuImage; >- >- @PostConstruct >- public void init() { >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >- itemUpdater); >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >- UIEvents.Item.SELECTED), selectionUpdater); >- eventBroker >- .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >- UIEvents.Item.ENABLED), enabledUpdater); >- eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC, >- UIEvents.UIElement.TOBERENDERED), toBeRenderedUpdater); >- >- } > >- @PreDestroy >- public void contextDisposed() { >- eventBroker.unsubscribe(itemUpdater); >- eventBroker.unsubscribe(selectionUpdater); >- eventBroker.unsubscribe(enabledUpdater); >- eventBroker.unsubscribe(toBeRenderedUpdater); >- } >+ HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup = new HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>>(); > > /* > * (non-Javadoc) > * > * @see >- * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget >- * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#init(org.eclipse >+ * .e4.core.contexts.IEclipseContext) > */ > @Override >+ public void init(IEclipseContext context) { >+ super.init(context); >+ application = context.get(MApplication.class); >+ } >+ > public Object createWidget(final MUIElement element, Object parent) { > if (!(element instanceof MToolBar) || !(parent instanceof Composite)) > return null; >@@ -246,170 +66,16 @@ > // HACK!! This should be done using a separate renderer > Composite intermediate = new Composite((Composite) parent, SWT.NONE); > createToolbar(element, intermediate); >- processContribution((MToolBar) element); >- >- return intermediate; >- } >- >- /** >- * @param element >- */ >- private void processContribution(MToolBar toolbarModel) { >- final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); >- ContributionsAnalyzer.gatherToolBarContributions(toolbarModel, >- application.getToolBarContributions(), >- toolbarModel.getElementId(), toContribute); >- generateContributions(toolbarModel, toContribute); >- } >- >- /** >- * @param toolbarModel >- * @param toContribute >- */ >- private void generateContributions(MToolBar toolbarModel, >- ArrayList<MToolBarContribution> toContribute) { >- HashSet<String> existingSeparatorNames = new HashSet<String>(); >- for (MToolBarElement child : toolbarModel.getChildren()) { >- String elementId = child.getElementId(); >- if (child instanceof MToolBarSeparator && elementId != null) { >- existingSeparatorNames.add(elementId); >- } >- } >- >- ToolBarManager manager = getManager(toolbarModel); >- boolean done = toContribute.size() == 0; >- while (!done) { >- ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>( >- toContribute); >- int retryCount = toContribute.size(); >- toContribute.clear(); >- >- for (final MToolBarContribution contribution : curList) { >- if (!processAddition(toolbarModel, manager, contribution, >- existingSeparatorNames)) { >- toContribute.add(contribution); >- } >- } >- // We're done if the retryList is now empty (everything done) or >- // if the list hasn't changed at all (no hope) >- done = (toContribute.size() == 0) >- || (toContribute.size() == retryCount); >- } >- } >- >- static class ContributionRecord { >- public ContributionRecord(MToolBar toolbarModel, >- MToolBarContribution contribution, ToolBarManager manager) { >- this.toolbarModel = toolbarModel; >- this.contribution = contribution; >- this.manager = manager; >- } >- >- MToolBar toolbarModel; >- MToolBarContribution contribution; >- ToolBarManager manager; >- ArrayList<MToolBarElement> generatedElements = new ArrayList<MToolBarElement>(); >- >- public void generate() { >- for (MToolBarElement element : contribution.getChildren()) { >- MToolBarElement copy = (MToolBarElement) EcoreUtil >- .copy((EObject) element); >- generatedElements.add(copy); >- } >- } >- >- public void updateVisibility(IEclipseContext context) { >- ExpressionContext exprContext = new ExpressionContext(context); >- boolean isVisible = ContributionsAnalyzer.isVisible(contribution, >- exprContext); >- for (MToolBarElement item : generatedElements) { >- item.setVisible(isVisible); >- } >- manager.markDirty(); >- } >- >- public void dispose() { >- for (MToolBarElement copy : generatedElements) { >- toolbarModel.getChildren().remove(copy); >- } >- } >- } >- >- /** >- * @param toolbarModel >- * @param manager >- * @param contribution >- * @param existingSeparatorNames >- * @return <code>true</code> if the contribution was successfuly processed >- */ >- private boolean processAddition(MToolBar toolbarModel, >- final ToolBarManager manager, MToolBarContribution contribution, >- HashSet<String> existingSeparatorNames) { >- int idx = getIndex(toolbarModel, contribution.getPositionInParent()); >- if (idx == -1) { >- return false; >- } >- final ContributionRecord record = new ContributionRecord(toolbarModel, >- contribution, manager); >- contributionRecords.add(record); >- record.generate(); >- for (MToolBarElement copy : record.generatedElements) { >- if (copy instanceof MToolBarSeparator >- && existingSeparatorNames.contains(copy.getElementId())) { >- // skip this, it's already there >- continue; >- } >- toolbarModel.getChildren().add(idx++, copy); >- if (copy instanceof MToolBarSeparator >- && copy.getElementId() != null) { >- existingSeparatorNames.add(copy.getElementId()); >+ intermediate.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ cleanUp((MToolBar) element); > } >- } >- if (contribution.getVisibleWhen() != null) { >- final IEclipseContext parentContext = modelService >- .getContainingContext(toolbarModel); >- parentContext.runAndTrack(new RunAndTrack() { >- @Override >- public boolean changed(IEclipseContext context) { >- record.updateVisibility(parentContext.getActiveLeaf()); >- manager.update(false); >- return true; >- } >- }); >- } >- >- return true; >- } >+ }); > >- private static int getIndex(MElementContainer<?> menuModel, >- String positionInParent) { >- String id = null; >- String modifier = null; >- if (positionInParent != null && positionInParent.length() > 0) { >- String[] array = positionInParent.split("="); //$NON-NLS-1$ >- modifier = array[0]; >- id = array[1]; >- } >- if (id == null) { >- return menuModel.getChildren().size(); >- } >- >- int idx = 0; >- int size = menuModel.getChildren().size(); >- while (idx < size) { >- if (id.equals(menuModel.getChildren().get(idx).getElementId())) { >- if ("after".equals(modifier)) { //$NON-NLS-1$ >- idx++; >- } >- return idx; >- } >- idx++; >- } >- return id.equals("additions") ? menuModel.getChildren().size() : -1; //$NON-NLS-1$ >+ return intermediate; > } > >- private ToolBar createToolbar(final MUIElement element, >- Composite intermediate) { >+ ToolBar createToolbar(final MUIElement element, Composite intermediate) { > int orientation = getOrientation(element); > RowLayout layout = RowLayoutFactory.fillDefaults().wrap(false) > .spacing(0).type(orientation).create(); >@@ -418,45 +84,11 @@ > intermediate.setLayout(layout); > // new Label(intermediate, (orientation == SWT.HORIZONTAL ? SWT.VERTICAL > // : SWT.HORIZONTAL) | SWT.SEPARATOR); >- > ToolBar separatorToolBar = new ToolBar(intermediate, orientation > | SWT.WRAP | SWT.FLAT | SWT.RIGHT); > new ToolItem(separatorToolBar, SWT.SEPARATOR); >- ToolBarManager manager = getManager((MToolBar) element); >- if (manager == null) { >- manager = new ToolBarManager(orientation | SWT.WRAP | SWT.FLAT >- | SWT.RIGHT); >- linkModelToManager((MToolBar) element, manager); >- } >- ToolBar bar = manager.createControl(intermediate); >- bar.setData(manager); >- bar.getShell().layout(new Control[] { bar }, SWT.DEFER); >- bar.addDisposeListener(new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- cleanUp((MToolBar) element); >- } >- }); >- return bar; >- } >- >- /** >- * @param element >- */ >- protected void cleanUp(MToolBar toolbarModel) { >- for (ContributionRecord record : contributionRecords >- .toArray(new ContributionRecord[contributionRecords.size()])) { >- if (record.toolbarModel == toolbarModel) { >- record.dispose(); >- contributionRecords.remove(record); >- for (MToolBarElement copy : record.generatedElements) { >- IContributionItem ici = modelToContribution.remove(copy); >- if (ici != null) { >- record.manager.remove(ici); >- } >- } >- record.generatedElements.clear(); >- } >- } >+ return new ToolBar(intermediate, orientation | SWT.WRAP | SWT.FLAT >+ | SWT.RIGHT); > } > > int getOrientation(final MUIElement element) { >@@ -471,170 +103,56 @@ > return SWT.HORIZONTAL; > } > >- /* >- * (non-Javadoc) >- * >- * @see >- * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents >- * (org.eclipse.e4.ui.model.application.ui.MElementContainer) >- */ >- @Override >- public void processContents(MElementContainer<MUIElement> container) { >- // I can either simply stop processing, or we can walk the model >- // ourselves like the "old" days >- // EMF gives us null lists if empty >- if (container == null) >- return; >- >- Object obj = container; >- ToolBarManager parentManager = getManager((MToolBar) obj); >- if (parentManager == null) { >- return; >- } >- // Process any contents of the newly created ME >- List<MUIElement> parts = container.getChildren(); >- if (parts != null) { >- MUIElement[] plist = parts.toArray(new MUIElement[parts.size()]); >- for (int i = 0; i < plist.length; i++) { >- MUIElement childME = plist[i]; >- modelProcessSwitch(parentManager, (MToolBarElement) childME); >- } >- } >- parentManager.update(false); >- >- ToolBar tb = getToolbarFrom(container.getWidget()); >- if (tb != null && ((EObject) container).eContainer() instanceof MPart) { >- MPart part = (MPart) ((EObject) container).eContainer(); >- MMenu viewMenu = getViewMenu(part); >- >- // View menu (if any) >- if (viewMenu != null) { >- addMenuButton(part, tb, viewMenu); >- } >- tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >+ public Object getUIContainer(MUIElement childElement) { >+ Composite intermediate = (Composite) super.getUIContainer(childElement); >+ if (intermediate == null || intermediate.isDisposed()) { >+ return null; > } >+ ToolBar toolbar = findToolbar(intermediate); >+ if (toolbar == null) { >+ toolbar = createToolbar(childElement.getParent(), intermediate); >+ } >+ return toolbar; > } > >- /** >- * @param widget >- * @return >- */ >- private ToolBar getToolbarFrom(Object widget) { >- if (widget instanceof ToolBar) { >- return (ToolBar) widget; >- } >- if (widget instanceof Composite) { >- Composite intermediate = (Composite) widget; >- if (!intermediate.isDisposed()) { >- Control[] children = intermediate.getChildren(); >- int length = children.length; >- if (length > 0 && children[length - 1] instanceof ToolBar) { >- return (ToolBar) children[length - 1]; >- } >+ ToolBar findToolbar(Composite intermediate) { >+ if (!intermediate.isDisposed()) { >+ Control[] children = intermediate.getChildren(); >+ int length = children.length; >+ if (length > 0 && children[length - 1] instanceof ToolBar) { >+ return (ToolBar) children[length - 1]; > } > } > return null; > } > >- /** >- * @param tb >- */ >- private void addMenuButton(MPart part, ToolBar tb, MMenu menu) { >- ToolItem ti = new ToolItem(tb, SWT.PUSH); >- ti.setImage(getViewMenuImage()); >- ti.setHotImage(null); >- ti.setToolTipText("View Menu"); //$NON-NLS-1$ >- ti.setData("theMenu", menu); //$NON-NLS-1$ >- ti.setData("thePart", part); //$NON-NLS-1$ >- >- ti.addSelectionListener(new SelectionListener() { >- public void widgetSelected(SelectionEvent e) { >- showMenu((ToolItem) e.widget); >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- showMenu((ToolItem) e.widget); >- } >- }); >- } >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); > >- /** >- * @param item >- */ >- protected void showMenu(ToolItem item) { >- // Create the UI for the menu >- final MMenu menuModel = (MMenu) item.getData("theMenu"); //$NON-NLS-1$ >- MPart part = (MPart) item.getData("thePart"); //$NON-NLS-1$ >- Control ctrl = (Control) part.getWidget(); >- Menu menu = (Menu) renderer.createGui(menuModel, ctrl.getShell(), >- part.getContext()); >- >- // ...and Show it... >- Rectangle ib = item.getBounds(); >- Point displayAt = item.getParent().toDisplay(ib.x, ib.y + ib.height); >- menu.setLocation(displayAt); >- menu.setVisible(true); >- >- Display display = Display.getCurrent(); >- while (!menu.isDisposed() && menu.isVisible()) { >- if (!display.readAndDispatch()) >- display.sleep(); >- } >- menu.dispose(); >- } >- >- private Image getViewMenuImage() { >- if (viewMenuImage == null) { >- Display d = Display.getCurrent(); >- >- Image viewMenu = new Image(d, 16, 16); >- Image viewMenuMask = new Image(d, 16, 16); >- >- Display display = Display.getCurrent(); >- GC gc = new GC(viewMenu); >- GC maskgc = new GC(viewMenuMask); >- gc.setForeground(display >- .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >- gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); >- >- int[] shapeArray = new int[] { 6, 1, 15, 1, 11, 5, 10, 5 }; >- gc.fillPolygon(shapeArray); >- gc.drawPolygon(shapeArray); >- >- Color black = display.getSystemColor(SWT.COLOR_BLACK); >- Color white = display.getSystemColor(SWT.COLOR_WHITE); >- >- maskgc.setBackground(black); >- maskgc.fillRectangle(0, 0, 16, 16); >- >- maskgc.setBackground(white); >- maskgc.setForeground(white); >- maskgc.fillPolygon(shapeArray); >- maskgc.drawPolygon(shapeArray); >- gc.dispose(); >- maskgc.dispose(); >- >- ImageData data = viewMenu.getImageData(); >- data.transparentPixel = data.getPixel(0, 0); >- >- viewMenuImage = new Image(d, viewMenu.getImageData(), >- viewMenuMask.getImageData()); >- viewMenu.dispose(); >- viewMenuMask.dispose(); >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) { >+ widget.dispose(); > } >- return viewMenuImage; >+ ToolBar toolbar = (ToolBar) getUIContainer(child); >+ if (toolbar != null && !toolbar.isDisposed()) { >+ toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >+ } >+ disposeToolbarIfNecessary(parentElement); > } > >- private MMenu getViewMenu(MPart part) { >- if (part.getMenus() == null) { >- return null; >- } >- for (MMenu menu : part.getMenus()) { >- if (menu.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >- return menu; >+ private void disposeToolbarIfNecessary(MUIElement element) { >+ Composite composite = (Composite) element.getWidget(); >+ ToolBar toolbar = findToolbar(composite); >+ if (toolbar != null && hasOnlySeparators(toolbar)) { >+ toolbar.dispose(); >+ if (composite.getChildren().length > 0) { >+ composite.getChildren()[0].dispose(); > } > } >- return null; > } > > boolean hasOnlySeparators(ToolBar toolbar) { >@@ -651,67 +169,6 @@ > } > > @Override >- public void postProcess(MUIElement element) { >- super.postProcess(element); >- // disposeToolbarIfNecessary(element); >- ToolBar tb = getToolbarFrom(element.getWidget()); >- if (tb != null && !tb.isDisposed()) { >- tb.getShell().layout(new Control[] { tb }, SWT.DEFER); >- tb.setVisible(true); >- } >- } >- >- public Object getUIContainer(MUIElement childElement) { >- if (childElement.getWidget() instanceof ToolBar) { >- return childElement.getWidget(); >- } >- >- Object obj = super.getUIContainer(childElement); >- if (obj instanceof ToolBar) { >- return obj; >- } >- >- if (obj instanceof Composite) { >- Composite intermediate = (Composite) obj; >- if (intermediate == null || intermediate.isDisposed()) { >- return null; >- } >- ToolBar toolbar = getToolbarFrom(intermediate); >- if (toolbar == null) { >- toolbar = createToolbar(childElement.getParent(), intermediate); >- } >- return toolbar; >- } >- return null; >- } >- >- @Override >- public void disposeWidget(MUIElement element) { >- ToolBar tb = getToolbarFrom(element.getWidget()); >- tb.setVisible(false); >- unbindWidget(element); >- tb.setData(AbstractPartRenderer.OWNING_ME, element); >- } >- >- @Override >- public void hideChild(MElementContainer<MUIElement> parentElement, >- MUIElement child) { >- super.hideChild(parentElement, child); >- >- // Since there's no place to 'store' a child that's not in a menu >- // we'll blow it away and re-create on an add >- Widget widget = (Widget) child.getWidget(); >- if (widget != null && !widget.isDisposed()) { >- widget.dispose(); >- } >- ToolBar toolbar = (ToolBar) getUIContainer(child); >- if (toolbar != null && !toolbar.isDisposed()) { >- toolbar.getShell().layout(new Control[] { toolbar }, SWT.DEFER); >- } >- // disposeToolbarIfNecessary(parentElement); >- } >- >- @Override > public void childRendered(MElementContainer<MUIElement> parentElement, > MUIElement element) { > super.childRendered(parentElement, element); >@@ -721,106 +178,98 @@ > } > } > >- /** >- * @param parentManager >- * @param childME >- */ >- private void modelProcessSwitch(ToolBarManager parentManager, >- MToolBarElement childME) { >- if (childME instanceof MHandledToolItem) { >- MHandledToolItem itemModel = (MHandledToolItem) childME; >- processHandledItem(parentManager, itemModel); >- } else if (childME instanceof MDirectToolItem) { >- MDirectToolItem itemModel = (MDirectToolItem) childME; >- processDirectItem(parentManager, itemModel); >- } else if (childME instanceof MToolBarSeparator) { >- MToolBarSeparator itemModel = (MToolBarSeparator) childME; >- processSeparator(parentManager, itemModel); >- } else if (childME instanceof MToolControl) { >- MToolControl itemModel = (MToolControl) childME; >- processToolControl(parentManager, itemModel); >- } >- } >- >- /** >- * @param parentManager >- * @param itemModel >- */ >- private void processSeparator(ToolBarManager parentManager, >- MToolBarSeparator itemModel) { >- AbstractGroupMarker marker = null; >- if (itemModel.isVisible()) { >- marker = new Separator(); >- marker.setId(itemModel.getElementId()); >- } else { >- if (itemModel.getElementId() != null) { >- marker = new GroupMarker(itemModel.getElementId()); >- } >- } >- parentManager.add(marker); >- } >- >- /** >- * @param parentManager >- * @param itemModel >- */ >- private void processToolControl(ToolBarManager parentManager, >- MToolControl itemModel) { >- final IEclipseContext lclContext = getContext(itemModel); >- ToolControlContribution ci = ContextInjectionFactory.make( >- ToolControlContribution.class, lclContext); >- ci.setModel(itemModel); >- parentManager.add(ci); >- modelToContribution.put(itemModel, ci); >- } >- >- /** >- * @param parentManager >- * @param itemModel >- */ >- private void processDirectItem(ToolBarManager parentManager, >- MDirectToolItem itemModel) { >- final IEclipseContext lclContext = getContext(itemModel); >- DirectContributionItem ci = ContextInjectionFactory.make( >- DirectContributionItem.class, lclContext); >- ci.setModel(itemModel); >- parentManager.add(ci); >- modelToContribution.put(itemModel, ci); >- } >- >- /** >- * @param parentManager >- * @param itemModel >- */ >- private void processHandledItem(ToolBarManager parentManager, >- MHandledToolItem itemModel) { >- final IEclipseContext lclContext = getContext(itemModel); >- HandledContributionItem ci = ContextInjectionFactory.make( >- HandledContributionItem.class, lclContext); >- ci.setModel(itemModel); >- parentManager.add(ci); >- modelToContribution.put(itemModel, ci); >+ @Override >+ public void processContents(MElementContainer<MUIElement> container) { >+ super.processContents(container); >+ IEclipseContext ctx = getContext(container); >+ ExpressionContext eContext = new ExpressionContext(ctx); >+ ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); >+ MElementContainer<?> toolbarObj = container; >+ MToolBar toolbarModel = (MToolBar) toolbarObj; >+ ContributionsAnalyzer.gatherToolBarContributions(toolbarModel, >+ application.getToolBarContributions(), >+ toolbarModel.getElementId(), toContribute, eContext); >+ addToolBarContributions(toolbarModel, toContribute, ctx, eContext, >+ pendingCleanup); > } > >- public ToolBarManager getManager(MToolBar model) { >- return modelToManager.get(model); >+ @Override >+ public void postProcess(MUIElement element) { >+ super.postProcess(element); >+ disposeToolbarIfNecessary(element); > } > >- public MToolBar getToolBarModel(ToolBarManager manager) { >- return managerToModel.get(manager); >- } >+ public static void addToolBarContributions( >+ final MToolBar toolbarModel, >+ ArrayList<MToolBarContribution> toContribute, >+ IEclipseContext ctx, >+ final ExpressionContext eContext, >+ HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup) { >+ HashSet<String> existingSeparatorNames = new HashSet<String>(); >+ for (MToolBarElement child : toolbarModel.getChildren()) { >+ String elementId = child.getElementId(); >+ if (child instanceof MToolBarSeparator && elementId != null) { >+ existingSeparatorNames.add(elementId); >+ } >+ } >+ boolean done = toContribute.size() == 0; >+ while (!done) { >+ ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>( >+ toContribute); >+ int retryCount = toContribute.size(); >+ toContribute.clear(); > >- public void linkModelToManager(MToolBar model, ToolBarManager manager) { >- modelToManager.put(model, manager); >- managerToModel.put(manager, model); >+ for (final MToolBarContribution contribution : curList) { >+ final ArrayList<MToolBarElement> toRemove = new ArrayList<MToolBarElement>(); >+ if (!ContributionsAnalyzer.processAddition(toolbarModel, >+ contribution, toRemove, existingSeparatorNames)) { >+ toContribute.add(contribution); >+ } else { >+ if (contribution.getVisibleWhen() != null) { >+ ctx.runAndTrack(new RunAndTrack() { >+ @Override >+ public boolean changed(IEclipseContext context) { >+ if (!toolbarModel.isToBeRendered() >+ || !toolbarModel.isVisible() >+ || toolbarModel.getWidget() == null) { >+ return false; >+ } >+ boolean rc = ContributionsAnalyzer.isVisible( >+ contribution, eContext); >+ for (MToolBarElement child : toRemove) { >+ child.setToBeRendered(rc); >+ } >+ return true; >+ } >+ }); >+ } >+ ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup >+ .get(toolbarModel); >+ if (lists == null) { >+ lists = new ArrayList<ArrayList<MToolBarElement>>(); >+ pendingCleanup.put(toolbarModel, lists); >+ } >+ lists.add(toRemove); >+ } >+ } >+ // We're done if the retryList is now empty (everything done) or >+ // if the list hasn't changed at all (no hope) >+ done = (toContribute.size() == 0) >+ || (toContribute.size() == retryCount); >+ } > } > >- public void clearModelToManager(MToolBar model, ToolBarManager manager) { >- modelToManager.remove(model); >- managerToModel.remove(manager); >+ protected void cleanUp(MToolBar element) { >+ ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup >+ .remove(element); >+ if (lists == null) { >+ return; >+ } >+ for (ArrayList<MToolBarElement> list : lists) { >+ for (MToolBarElement child : list) { >+ element.getChildren().remove(child); >+ } >+ } > } > >- public IContributionItem getContribution(MToolBarElement element) { >- return modelToContribution.get(element); >- } > } >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemRenderer.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemRenderer.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemRenderer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemRenderer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,424 @@ >+/******************************************************************************* >+ * Copyright (c) 2009, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.renderers.swt; >+ >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+import javax.annotation.PostConstruct; >+import javax.annotation.PreDestroy; >+import javax.inject.Inject; >+import org.eclipse.core.commands.ParameterizedCommand; >+import org.eclipse.core.commands.common.NotDefinedException; >+import org.eclipse.core.runtime.ISafeRunnable; >+import org.eclipse.core.runtime.SafeRunner; >+import org.eclipse.e4.core.commands.ECommandService; >+import org.eclipse.e4.core.commands.EHandlerService; >+import org.eclipse.e4.core.contexts.ContextInjectionFactory; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.di.annotations.Execute; >+import org.eclipse.e4.core.services.contributions.IContributionFactory; >+import org.eclipse.e4.core.services.events.IEventBroker; >+import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.bindings.EBindingService; >+import org.eclipse.e4.ui.internal.workbench.Activator; >+import org.eclipse.e4.ui.internal.workbench.Policy; >+import org.eclipse.e4.ui.model.application.MContribution; >+import org.eclipse.e4.ui.model.application.commands.MParameter; >+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.MUILabel; >+import org.eclipse.e4.ui.model.application.ui.menu.ItemType; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolItem; >+import org.eclipse.e4.ui.workbench.IPresentationEngine; >+import org.eclipse.e4.ui.workbench.UIEvents; >+import org.eclipse.jface.bindings.TriggerSequence; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Widget; >+import org.osgi.service.event.Event; >+import org.osgi.service.event.EventHandler; >+ >+/** >+ * Create a contribute part. >+ */ >+public class ToolItemRenderer extends SWTPartRenderer { >+ >+ @Inject >+ Logger logger; >+ @Inject >+ IEventBroker eventBroker; >+ >+ @Inject >+ private IPresentationEngine engine; >+ >+ private EventHandler itemUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolItem)) >+ return; >+ >+ MToolItem itemModel = (MToolItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ ToolItem toolItem = (ToolItem) itemModel.getWidget(); >+ >+ // No widget == nothing to update >+ if (toolItem == null) >+ return; >+ >+ String attName = (String) event >+ .getProperty(UIEvents.EventTags.ATTNAME); >+ if (UIEvents.UILabel.LABEL.equals(attName)) { >+ setItemText(itemModel, toolItem); >+ } else if (UIEvents.UILabel.ICONURI.equals(attName)) { >+ toolItem.setImage(getImage(itemModel)); >+ } else if (UIEvents.UILabel.TOOLTIP.equals(attName)) { >+ toolItem.setToolTipText(getToolTipText(itemModel)); >+ toolItem.setImage(getImage(itemModel)); >+ } >+ } >+ }; >+ >+ private EventHandler selectionUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolItem)) >+ return; >+ >+ MToolItem itemModel = (MToolItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ ToolItem toolItem = (ToolItem) itemModel.getWidget(); >+ if (toolItem != null) { >+ toolItem.setSelection(itemModel.isSelected()); >+ } >+ } >+ }; >+ >+ private EventHandler enabledUpdater = new EventHandler() { >+ public void handleEvent(Event event) { >+ // Ensure that this event is for a MToolItem >+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolItem)) >+ return; >+ >+ MToolItem itemModel = (MToolItem) event >+ .getProperty(UIEvents.EventTags.ELEMENT); >+ ToolItem toolItem = (ToolItem) itemModel.getWidget(); >+ if (toolItem != null) { >+ toolItem.setEnabled(itemModel.isEnabled()); >+ } >+ } >+ }; >+ >+ @PostConstruct >+ public void init() { >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UILabel.TOPIC), >+ itemUpdater); >+ eventBroker.subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.SELECTED), selectionUpdater); >+ eventBroker >+ .subscribe(UIEvents.buildTopic(UIEvents.Item.TOPIC, >+ UIEvents.Item.ENABLED), enabledUpdater); >+ } >+ >+ @PreDestroy >+ public void contextDisposed() { >+ eventBroker.unsubscribe(itemUpdater); >+ eventBroker.unsubscribe(selectionUpdater); >+ eventBroker.unsubscribe(enabledUpdater); >+ } >+ >+ private ParameterizedCommand generateParameterizedCommand( >+ final MHandledItem item, final IEclipseContext lclContext) { >+ ECommandService cmdService = (ECommandService) lclContext >+ .get(ECommandService.class.getName()); >+ Map<String, Object> parameters = null; >+ List<MParameter> modelParms = item.getParameters(); >+ if (modelParms != null && !modelParms.isEmpty()) { >+ parameters = new HashMap<String, Object>(); >+ for (MParameter mParm : modelParms) { >+ parameters.put(mParm.getName(), mParm.getValue()); >+ } >+ } >+ ParameterizedCommand cmd = cmdService.createCommand(item.getCommand() >+ .getElementId(), parameters); >+ item.setWbCommand(cmd); >+ return cmd; >+ } >+ >+ private void setItemText(MToolItem model, ToolItem item) { >+ String text = model.getLabel(); >+ if (model instanceof MHandledItem) { >+ MHandledItem handledItem = (MHandledItem) model; >+ IEclipseContext context = getContext(model); >+ EBindingService bs = (EBindingService) context >+ .get(EBindingService.class.getName()); >+ ParameterizedCommand cmd = handledItem.getWbCommand(); >+ if (cmd == null) { >+ cmd = generateParameterizedCommand(handledItem, context); >+ } >+ TriggerSequence sequence = bs.getBestSequenceFor(handledItem >+ .getWbCommand()); >+ if (sequence != null) { >+ text = text + '\t' + sequence.format(); >+ } >+ item.setText(text); >+ } else { >+ if (text == null) { >+ text = ""; //$NON-NLS-1$ >+ } >+ item.setText(text); >+ } >+ } >+ >+ private String getToolTipText(MItem item) { >+ String text = item.getTooltip(); >+ if (item instanceof MHandledItem) { >+ MHandledItem handledItem = (MHandledItem) item; >+ IEclipseContext context = getContext(item); >+ EBindingService bs = (EBindingService) context >+ .get(EBindingService.class.getName()); >+ ParameterizedCommand cmd = handledItem.getWbCommand(); >+ if (cmd == null) { >+ cmd = generateParameterizedCommand(handledItem, context); >+ } >+ TriggerSequence sequence = bs.getBestSequenceFor(handledItem >+ .getWbCommand()); >+ if (sequence != null) { >+ if (text == null) { >+ try { >+ text = cmd.getName(); >+ } catch (NotDefinedException e) { >+ return null; >+ } >+ } >+ text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$ >+ } >+ return text; >+ } >+ return text; >+ } >+ >+ public Object createWidget(final MUIElement element, Object parent) { >+ if (!(element instanceof MToolItem) || !(parent instanceof ToolBar)) >+ return null; >+ >+ MToolItem itemModel = (MToolItem) element; >+ >+ // determine the index at which we should create the new item >+ int addIndex = calcVisibleIndex(element); >+ >+ // OK, it's a real menu item, what kind? >+ MMenu menu = itemModel.getMenu(); >+ int flags = 0; >+ if (menu != null) { >+ flags |= SWT.DROP_DOWN; >+ } else if (itemModel.getType() == ItemType.PUSH) >+ flags |= SWT.PUSH; >+ else if (itemModel.getType() == ItemType.CHECK) >+ flags |= SWT.CHECK; >+ else if (itemModel.getType() == ItemType.RADIO) >+ flags |= SWT.RADIO; >+ >+ ToolItem newItem = new ToolItem((ToolBar) parent, flags, addIndex); >+ if (itemModel.getLabel() != null) >+ newItem.setText(itemModel.getLabel()); >+ >+ newItem.setToolTipText(getToolTipText(itemModel)); >+ >+ newItem.setImage(getImage((MUILabel) element)); >+ >+ newItem.setEnabled(itemModel.isEnabled()); >+ >+ newItem.setSelection(itemModel.isSelected()); >+ >+ return newItem; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#hideChild >+ * (org.eclipse.e4.ui.model.application.MElementContainer, >+ * org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hideChild(MElementContainer<MUIElement> parentElement, >+ MUIElement child) { >+ super.hideChild(parentElement, child); >+ >+ // Since there's no place to 'store' a child that's not in a menu >+ // we'll blow it away and re-create on an add >+ Widget widget = (Widget) child.getWidget(); >+ if (widget != null && !widget.isDisposed()) >+ widget.dispose(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#hookControllerLogic >+ * (org.eclipse.e4.ui.model.application.MUIElement) >+ */ >+ @Override >+ public void hookControllerLogic(MUIElement me) { >+ // If the item is a CHECK or RADIO update the model's state to match >+ if (me instanceof MItem) { >+ final MItem item = (MItem) me; >+ if (item.getType() == ItemType.CHECK >+ || item.getType() == ItemType.RADIO) { >+ ToolItem ti = (ToolItem) me.getWidget(); >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ item.setSelected(((ToolItem) e.widget).getSelection()); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ item.setSelected(((ToolItem) e.widget).getSelection()); >+ } >+ }); >+ } else if (me instanceof MToolItem) { >+ final MMenu mmenu = ((MToolItem) me).getMenu(); >+ if (mmenu != null) { >+ final ToolItem ti = (ToolItem) me.getWidget(); >+ ti.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ if (e.detail == SWT.ARROW) { >+ Menu menu = (Menu) engine.createGui(mmenu, ti >+ .getParent().getShell(), null); >+ >+ Rectangle itemBounds = ti.getBounds(); >+ Point displayAt = ti.getParent().toDisplay( >+ itemBounds.x, >+ itemBounds.y + itemBounds.height); >+ menu.setLocation(displayAt); >+ menu.setVisible(true); >+ >+ Display display = menu.getDisplay(); >+ while (menu.isVisible()) { >+ if (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+ } >+ }); >+ } >+ } >+ } >+ >+ // 'Execute' the operation if possible >+ if (me instanceof MContribution >+ && ((MContribution) me).getContributionURI() != null) { >+ final MToolItem item = (MToolItem) me; >+ final MContribution contrib = (MContribution) me; >+ final IEclipseContext lclContext = getContext(me); >+ ToolItem ti = (ToolItem) me.getWidget(); >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ if (contrib.getObject() == null) { >+ IContributionFactory cf = (IContributionFactory) lclContext >+ .get(IContributionFactory.class.getName()); >+ contrib.setObject(cf.create( >+ contrib.getContributionURI(), lclContext)); >+ } >+ lclContext.set(MItem.class.getName(), item); >+ ContextInjectionFactory.invoke(contrib.getObject(), >+ Execute.class, lclContext); >+ lclContext.remove(MItem.class.getName()); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ }); >+ } else if (me instanceof MHandledItem) { >+ final MHandledItem item = (MHandledItem) me; >+ final IEclipseContext lclContext = getContext(me); >+ final ToolItem ti = (ToolItem) me.getWidget(); >+ final Display display = ti.getDisplay(); >+ display.timerExec(500, new Runnable() { >+ boolean logged = false; >+ >+ public void run() { >+ if (ti.isDisposed()) { >+ return; >+ } >+ SafeRunner.run(new ISafeRunnable() { >+ public void run() throws Exception { >+ EHandlerService service = lclContext >+ .get(EHandlerService.class); >+ if (service == null) { >+ // no localized handler service >+ return; >+ } >+ ParameterizedCommand cmd = item.getWbCommand(); >+ if (cmd == null) { >+ cmd = generateParameterizedCommand(item, >+ lclContext); >+ } >+ if (cmd == null) { >+ return; >+ } >+ item.setEnabled(service.canExecute(cmd)); >+ } >+ >+ public void handleException(Throwable exception) { >+ if (!logged) { >+ logged = true; >+ logger.error( >+ exception, >+ "Internal error during tool item enablement updating, this is only logged once per tool item."); //$NON-NLS-1$ >+ } >+ } >+ }); >+ // repeat until disposed >+ display.timerExec(500, this); >+ } >+ }); >+ ti.addSelectionListener(new SelectionListener() { >+ public void widgetSelected(SelectionEvent e) { >+ if (e.detail != SWT.ARROW) { >+ EHandlerService service = (EHandlerService) lclContext >+ .get(EHandlerService.class.getName()); >+ ParameterizedCommand cmd = item.getWbCommand(); >+ if (cmd == null) { >+ cmd = generateParameterizedCommand(item, lclContext); >+ } >+ if (cmd == null) { >+ Activator.trace(Policy.DEBUG_MENUS, >+ "Failed to execute: " + item.getCommand(), //$NON-NLS-1$ >+ null); >+ return; >+ } >+ lclContext.set(MItem.class.getName(), item); >+ service.executeHandler(cmd); >+ lclContext.remove(MItem.class.getName()); >+ } >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ } >+ }); >+ } >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java,v >retrieving revision 1.4 >diff -u -r1.4 WorkbenchRendererFactory.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java 8 Oct 2010 12:03:07 -0000 1.4 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java 14 Oct 2010 18:20:41 -0000 >@@ -14,16 +14,27 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; > import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; >+import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; > import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; > import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolItem; > import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; > > public class WorkbenchRendererFactory implements IRendererFactory { > > private AreaRenderer areaRenderer; > private MenuRenderer menuRenderer; >+ private HandledMenuItemRenderer handledMenuItemRenderer; > private ToolBarRenderer toolbarRenderer; >+ private ToolItemRenderer toolItemRenderer; >+ private SeparatorRenderer separatorRenderer; > private ContributedPartRenderer contributedPartRenderer; > private ElementReferenceRenderer elementRefRenderer; > private PerspectiveStackRenderer perspStackRenderer; >@@ -35,6 +46,10 @@ > private WBWRenderer wbwRenderer; > > private IEclipseContext context; >+ private DirectMenuItemRenderer directMenuItemRenderer; >+ private RenderedMenuRenderer renderedMenuRenderer; >+ private RenderedMenuItemRenderer renderedMenuItemRenderer; >+ private RenderedToolBarRenderer renderedToolbarRenderer; > > public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) { > if (uiElement instanceof MArea) { >@@ -49,18 +64,61 @@ > initRenderer(contributedPartRenderer); > } > return contributedPartRenderer; >+ } else if (uiElement instanceof MHandledMenuItem) { >+ if (handledMenuItemRenderer == null) { >+ handledMenuItemRenderer = new HandledMenuItemRenderer(); >+ initRenderer(handledMenuItemRenderer); >+ } >+ return handledMenuItemRenderer; >+ } else if (uiElement instanceof MDirectMenuItem) { >+ if (directMenuItemRenderer == null) { >+ directMenuItemRenderer = new DirectMenuItemRenderer(); >+ initRenderer(directMenuItemRenderer); >+ } >+ return directMenuItemRenderer; >+ } else if (uiElement instanceof MRenderedMenu) { >+ if (renderedMenuRenderer == null) { >+ renderedMenuRenderer = new RenderedMenuRenderer(); >+ initRenderer(renderedMenuRenderer); >+ } >+ return renderedMenuRenderer; >+ } else if (uiElement instanceof MRenderedMenuItem) { >+ if (renderedMenuItemRenderer == null) { >+ renderedMenuItemRenderer = new RenderedMenuItemRenderer(); >+ initRenderer(renderedMenuItemRenderer); >+ } >+ return renderedMenuItemRenderer; > } else if (uiElement instanceof MMenu) { > if (menuRenderer == null) { > menuRenderer = new MenuRenderer(); > initRenderer(menuRenderer); > } > return menuRenderer; >+ } else if (uiElement instanceof MRenderedToolBar) { >+ if (renderedToolbarRenderer == null) { >+ renderedToolbarRenderer = new RenderedToolBarRenderer(); >+ initRenderer(renderedToolbarRenderer); >+ } >+ return renderedToolbarRenderer; > } else if (uiElement instanceof MToolBar) { > if (toolbarRenderer == null) { > toolbarRenderer = new ToolBarRenderer(); > initRenderer(toolbarRenderer); > } > return toolbarRenderer; >+ } else if (uiElement instanceof MToolItem) { >+ if (toolItemRenderer == null) { >+ toolItemRenderer = new ToolItemRenderer(); >+ initRenderer(toolItemRenderer); >+ } >+ return toolItemRenderer; >+ } else if (uiElement instanceof MMenuSeparator >+ || uiElement instanceof MToolBarSeparator) { >+ if (separatorRenderer == null) { >+ separatorRenderer = new SeparatorRenderer(); >+ initRenderer(separatorRenderer); >+ } >+ return separatorRenderer; > } else if (uiElement instanceof MPlaceholder) { > if (elementRefRenderer == null) { > elementRefRenderer = new ElementReferenceRenderer(); >#P org.eclipse.e4.ui.workbench.swt >Index: src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java,v >retrieving revision 1.46 >diff -u -r1.46 PartRenderingEngine.java >--- src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java 8 Oct 2010 12:03:05 -0000 1.46 >+++ src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java 14 Oct 2010 18:20:42 -0000 >@@ -50,7 +50,6 @@ > import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; > import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow; > 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.services.IStylingEngine; > import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.e4.ui.workbench.IResourceUtilities; >@@ -108,10 +107,8 @@ > .eContainer(); > } > >- boolean menuChild = parent instanceof MMenu; >- > // If the parent isn't displayed who cares? >- if (parent == null || parent.getWidget() == null || menuChild) >+ if (parent == null || parent.getWidget() == null) > return; > > if (changedElement.isToBeRendered()) { >@@ -203,10 +200,9 @@ > MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj; > boolean isApplication = changedObj instanceof MApplication; > >- boolean menuChild = changedObj instanceof MMenu; > // If the parent isn't in the UI then who cares? > AbstractPartRenderer renderer = getRendererFor(changedElement); >- if ((!isApplication && renderer == null) || menuChild) >+ if (!isApplication && renderer == null) > return; > > String eventType = (String) event >@@ -469,9 +465,8 @@ > Object newWidget = createWidget(element, parentWidget); > > // Remember that we've created the control >- AbstractPartRenderer renderer = getRendererFor(element); >- if (renderer != null) { >- // AbstractPartRenderer renderer = getRendererFor(element); >+ if (newWidget != null) { >+ AbstractPartRenderer renderer = getRendererFor(element); > > // Have the renderer hook up any widget specific listeners > renderer.hookControllerLogic(element); >Index: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java >diff -N src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,193 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.ui.workbench.swt.modeling; >+ >+import java.lang.reflect.Method; >+import java.util.HashMap; >+import javax.inject.Inject; >+import org.eclipse.core.runtime.ISafeRunnable; >+import org.eclipse.core.runtime.SafeRunner; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; >+import org.eclipse.e4.ui.internal.workbench.swt.Policy; >+import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator; >+import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >+import org.eclipse.e4.ui.workbench.IPresentationEngine; >+import org.eclipse.e4.ui.workbench.modeling.EModelService; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.Widget; >+ >+public class MenuManagerServiceFilter implements Listener { >+ public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$ >+ >+ private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context"; >+ >+ private static void trace(String msg, Widget menu, MMenu menuModel) { >+ WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": " >+ + menuModel, null); >+ } >+ >+ private static Method aboutToShow; >+ >+ public static Method getAboutToShow() { >+ if (aboutToShow == null) { >+ try { >+ aboutToShow = MenuManager.class >+ .getDeclaredMethod("handleAboutToShow"); >+ aboutToShow.setAccessible(true); >+ } catch (SecurityException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (NoSuchMethodException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ return aboutToShow; >+ } >+ >+ @Inject >+ private MApplication application; >+ >+ @Inject >+ private IPresentationEngine renderer; >+ >+ @Inject >+ private Logger logger; >+ >+ @Inject >+ EModelService modelService; >+ >+ private HashMap<Menu, Runnable> pendingCleanup = new HashMap<Menu, Runnable>(); >+ >+ public void handleEvent(final Event event) { >+ // wrap the handling in a SafeRunner so that exceptions do not prevent >+ // the menu from being shown >+ SafeRunner.run(new ISafeRunnable() { >+ public void handleException(Throwable e) { >+ if (e instanceof Error) { >+ // errors are deadly, we shouldn't ignore these >+ throw (Error) e; >+ } else { >+ // log exceptions otherwise >+ if (logger != null) { >+ logger.error(e); >+ } >+ } >+ } >+ >+ public void run() throws Exception { >+ safeHandleEvent(event); >+ } >+ }); >+ } >+ >+ private void safeHandleEvent(Event event) { >+ if (!(event.widget instanceof Menu)) { >+ return; >+ } >+ final Menu menu = (Menu) event.widget; >+ if (event.type == SWT.Dispose) { >+ trace("handleMenu.Dispose", menu, null); >+ cleanUp(menu); >+ } >+ Object obj = menu.getData(AbstractPartRenderer.OWNING_ME); >+ if (obj == null && menu.getParentItem() != null) { >+ obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME); >+ } >+ if (obj instanceof MPopupMenu) { >+ handleContextMenu(event, menu, (MPopupMenu) obj); >+ } else if (obj instanceof MMenu) { >+ handleMenu(event, menu, (MMenu) obj); >+ } >+ } >+ >+ private void handleMenu(final Event event, final Menu menu, >+ final MMenu menuModel) { >+ if ((menu.getStyle() & SWT.BAR) != 0) { >+ // don't process the menu bar, it's not fair :-) >+ return; >+ } >+ switch (event.type) { >+ case SWT.Show: >+ cleanUp(menu); >+ showMenu(event, menu, menuModel); >+ break; >+ case SWT.Hide: >+ // TODO we'll clean up on show >+ break; >+ } >+ } >+ >+ public void showMenu(final Event event, final Menu menu, >+ final MMenu menuModel) { >+ // System.err.println("showMenu: " + menuModel + "\n\t" + menu); >+ } >+ >+ private void handleContextMenu(final Event event, final Menu menu, >+ final MPopupMenu menuModel) { >+ switch (event.type) { >+ case SWT.Show: >+ cleanUp(menu); >+ showPopup(event, menu, menuModel); >+ break; >+ case SWT.Hide: >+ hidePopup(event, menu, menuModel); >+ break; >+ } >+ } >+ >+ public void hidePopup(Event event, Menu menu, MPopupMenu menuModel) { >+ // System.err.println("hidePopup: " + menuModel + "\n\t" + menu); >+ final IEclipseContext popupContext = menuModel.getContext(); >+ final IEclipseContext originalChild = (IEclipseContext) popupContext >+ .get(TMP_ORIGINAL_CONTEXT); >+ popupContext.remove(TMP_ORIGINAL_CONTEXT); >+ if (!menu.isDisposed()) { >+ menu.getDisplay().asyncExec(new Runnable() { >+ public void run() { >+ if (originalChild == null) { >+ popupContext.deactivate(); >+ } else { >+ originalChild.activate(); >+ } >+ } >+ }); >+ } >+ } >+ >+ public void showPopup(final Event event, final Menu menu, >+ final MPopupMenu menuModel) { >+ // System.err.println("showPopup: " + menuModel + "\n\t" + menu); >+ // we need some context foolery here >+ final IEclipseContext popupContext = menuModel.getContext(); >+ final IEclipseContext parentContext = popupContext.getParent(); >+ final IEclipseContext originalChild = parentContext.getActiveChild(); >+ popupContext.activate(); >+ popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild); >+ >+ } >+ >+ public void cleanUp(final Menu menu) { >+ // System.err.println("cleanUp: " + menu); >+ } >+ >+ public void dispose() { >+ // System.err.println("dispose"); >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java,v >retrieving revision 1.11 >diff -u -r1.11 MenuService.java >--- src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java 8 Oct 2010 12:03:05 -0000 1.11 >+++ src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java 14 Oct 2010 18:20:43 -0000 >@@ -13,13 +13,13 @@ > import javax.inject.Inject; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; >-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.menu.MMenu; > import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >-import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; >+import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Menu; > > public class MenuService implements EMenuService { >@@ -49,39 +49,20 @@ > if (mmenu.getWidget() != null) { > return false; > } >- // we need to delegate to the renderer so that it "processes" the >- // MenuManager correctly >- IRendererFactory rendererFactory = myPart.getContext().get( >- IRendererFactory.class); >- AbstractPartRenderer renderer = rendererFactory.getRenderer(mmenu, >- parentControl); >+ Menu menu = new Menu(parentControl); >+ parentControl.setMenu(menu); >+ mmenu.setWidget(menu); >+ menu.setData(AbstractPartRenderer.OWNING_ME, mmenu); > IEclipseContext popupContext = myPart.getContext().createChild( > "popup:" + mmenu.getElementId()); > mmenu.setContext(popupContext); >- Object widget = renderer.createWidget(mmenu, parentControl); >- if (!(widget instanceof Menu)) { >- return false; >- } >- renderer.bindWidget(mmenu, widget); >- renderer.hookControllerLogic(mmenu); >- >- // Process its internal structure through the renderer that created >- // it >- Object castObject = mmenu; >- renderer.processContents((MElementContainer<MUIElement>) castObject); >- >- // Allow a final chance to set up >- renderer.postProcess(mmenu); >- >- // Now that we have a widget let the parent (if any) know >- if (mmenu.getParent() instanceof MUIElement) { >- MElementContainer<MUIElement> parentElement = mmenu.getParent(); >- AbstractPartRenderer parentRenderer = rendererFactory.getRenderer( >- parentElement, null); >- if (parentRenderer != null) >- parentRenderer.childRendered(parentElement, mmenu); >- } >- >+ menu.addListener(SWT.Dispose, new Listener() { >+ public void handleEvent(Event event) { >+ mmenu.getContext().dispose(); >+ mmenu.setContext(null); >+ mmenu.setWidget(null); >+ } >+ }); > return true; > } > } >Index: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java,v >retrieving revision 1.29 >diff -u -r1.29 MenuServiceFilter.java >--- src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java 8 Oct 2010 12:03:05 -0000 1.29 >+++ src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java 14 Oct 2010 18:20:43 -0000 >@@ -10,26 +10,38 @@ > *******************************************************************************/ > package org.eclipse.e4.ui.workbench.swt.modeling; > >+import java.lang.reflect.InvocationTargetException; > import java.lang.reflect.Method; >+import java.util.ArrayList; > import java.util.HashMap; >+import java.util.List; > import javax.inject.Inject; >+import org.eclipse.core.commands.ParameterizedCommand; > import org.eclipse.core.runtime.ISafeRunnable; > import org.eclipse.core.runtime.SafeRunner; >+import org.eclipse.e4.core.commands.EHandlerService; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.core.services.log.Logger; >+import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer; > import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; > import org.eclipse.e4.ui.internal.workbench.swt.Policy; > import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator; > import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; > 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.MMenuElement; > import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu; > import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.e4.ui.workbench.modeling.EModelService; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; > import org.eclipse.swt.widgets.Widget; > > public class MenuServiceFilter implements Listener { >@@ -110,7 +122,9 @@ > if (obj == null && menu.getParentItem() != null) { > obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME); > } >- if (obj instanceof MPopupMenu) { >+ if (obj instanceof MRenderedMenu) { >+ handlerRenderedMenu(event, menu, (MRenderedMenu) obj); >+ } else if (obj instanceof MPopupMenu) { > handleContextMenu(event, menu, (MPopupMenu) obj); > } else if (obj instanceof MMenu) { > handleMenu(event, menu, (MMenu) obj); >@@ -125,10 +139,12 @@ > } > switch (event.type) { > case SWT.Show: >+ trace("handleMenu.Show", menu, menuModel); > cleanUp(menu); > showMenu(event, menu, menuModel); > break; > case SWT.Hide: >+ trace("handleMenu.Hide", menu, menuModel); > // TODO we'll clean up on show > break; > } >@@ -136,24 +152,57 @@ > > public void showMenu(final Event event, final Menu menu, > final MMenu menuModel) { >- // System.err.println("showMenu: " + menuModel + "\n\t" + menu); >+ final IEclipseContext parentContext = modelService >+ .getContainingContext(menuModel); >+ >+ final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >+ final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>(); >+ ExpressionContext eContext = new ExpressionContext(parentContext); >+ ContributionsAnalyzer.gatherMenuContributions(menuModel, >+ application.getMenuContributions(), menuModel.getElementId(), >+ toContribute, eContext, false); >+ if (menu.getItemCount() == 1) { >+ MenuItem item = menu.getItem(0); >+ if (NUL_MENU_ITEM.equals(item.getText())) { >+ item.dispose(); >+ } >+ } >+ ContributionsAnalyzer.addMenuContributions(menuModel, toContribute, >+ menuContributionsToRemove); >+ >+ // create a cleanup routine for the Hide or next Show >+ pendingCleanup.put(menu, new Runnable() { >+ public void run() { >+ if (!menu.isDisposed()) { >+ unrender(menuContributionsToRemove); >+ } >+ removeMenuContributions(menuModel, menuContributionsToRemove); >+ } >+ }); >+ render(menu, menuModel); >+ if (menu.getItemCount() == 0) { >+ MenuItem menuItem = new MenuItem(menu, SWT.PUSH); >+ menuItem.setText(NUL_MENU_ITEM); >+ menuItem.setEnabled(false); >+ } > } > > private void handleContextMenu(final Event event, final Menu menu, > final MPopupMenu menuModel) { > switch (event.type) { > case SWT.Show: >+ trace("handleContextMenu.Show", menu, menuModel); > cleanUp(menu); > showPopup(event, menu, menuModel); > break; > case SWT.Hide: >+ trace("handleContextMenu.Hide", menu, menuModel); > hidePopup(event, menu, menuModel); > break; > } > } > > public void hidePopup(Event event, Menu menu, MPopupMenu menuModel) { >- // System.err.println("hidePopup: " + menuModel + "\n\t" + menu); > final IEclipseContext popupContext = menuModel.getContext(); > final IEclipseContext originalChild = (IEclipseContext) popupContext > .get(TMP_ORIGINAL_CONTEXT); >@@ -181,13 +230,140 @@ > popupContext.activate(); > popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild); > >+ final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >+ final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>(); >+ ExpressionContext eContext = new ExpressionContext(popupContext); >+ ContributionsAnalyzer.gatherMenuContributions(menuModel, >+ application.getMenuContributions(), menuModel.getElementId(), >+ toContribute, eContext, true); >+ >+ for (String tag : menuModel.getTags()) { >+ if (tag.startsWith("popup:") && tag.length() > 6) { >+ ContributionsAnalyzer.gatherMenuContributions(menuModel, >+ application.getMenuContributions(), tag.substring(6), >+ toContribute, eContext, false); >+ } >+ } >+ ContributionsAnalyzer.addMenuContributions(menuModel, toContribute, >+ menuContributionsToRemove); >+ >+ // create a cleanup routine for the Hide or next Show >+ pendingCleanup.put(menu, new Runnable() { >+ public void run() { >+ if (!menu.isDisposed()) { >+ unrender(menuContributionsToRemove); >+ } >+ removeMenuContributions(menuModel, menuContributionsToRemove); >+ } >+ }); >+ render(menu, menuModel); >+ } >+ >+ private void render(final Menu menu, final MMenu menuModel) { >+ trace("render", menu, menuModel); >+ for (MMenuElement element : menuModel.getChildren()) { >+ renderer.createGui(element, menu, null); >+ if (element instanceof MHandledMenuItem) { >+ setEnabled((MHandledMenuItem) element); >+ } >+ } >+ } >+ >+ private void setEnabled(MHandledMenuItem item) { >+ if (!item.isToBeRendered() || !item.isVisible() >+ || item.getWidget() == null) { >+ return; >+ } >+ ParameterizedCommand cmd = item.getWbCommand(); >+ if (cmd == null) { >+ return; >+ } >+ final IEclipseContext lclContext = modelService >+ .getContainingContext(item); >+ EHandlerService service = lclContext.get(EHandlerService.class); >+ item.setEnabled(service.canExecute(cmd)); >+ } >+ >+ private void unrender(final List<MMenuElement> menuModel) { >+ trace("unrender", null, null); >+ for (MMenuElement element : menuModel) { >+ renderer.removeGui(element); >+ } >+ } >+ >+ private void removeMenuContributions(final MMenu menuModel, >+ final ArrayList<MMenuElement> menuContributionsToRemove) { >+ for (MMenuElement item : menuContributionsToRemove) { >+ trace("removeMenuContributions " + item, >+ (Widget) menuModel.getWidget(), menuModel); >+ menuModel.getChildren().remove(item); >+ } >+ } >+ >+ private void handlerRenderedMenu(final Event event, final Menu menu, >+ final MRenderedMenu menuModel) { >+ // Do nothing here for the moment, except process any cleanups >+ switch (event.type) { >+ case SWT.Show: >+ trace("handlerRenderedMenu.Show", menu, menuModel); >+ cleanUp(menu); >+ showRenderedMenu(event, menu, menuModel); >+ break; >+ case SWT.Hide: >+ trace("handlerRenderedMenu.Hide", menu, menuModel); >+ // TODO don't care >+ break; >+ } >+ } >+ >+ public void showRenderedMenu(final Event event, final Menu menu, >+ final MRenderedMenu menuModel) { >+ if (!(menuModel.getContributionManager() instanceof MenuManager)) { >+ return; >+ } >+ >+ MenuManager manager = (MenuManager) menuModel.getContributionManager(); >+ Method handleAboutToShow = getAboutToShow(); >+ try { >+ handleAboutToShow.invoke(manager); >+ } catch (IllegalArgumentException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (IllegalAccessException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (InvocationTargetException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ >+ if (menuModel.getChildren().size() == 1 >+ && menuModel.getChildren().get(0) instanceof MPopupMenu) { >+ showPopup(event, menu, (MPopupMenu) menuModel.getChildren().get(0)); >+ } else { >+ showMenu(event, menu, menuModel); >+ } >+ event.type = SWT.None; >+ event.doit = false; > } > > public void cleanUp(final Menu menu) { >- // System.err.println("cleanUp: " + menu); >+ trace("cleanUp", menu, null); >+ if (pendingCleanup.isEmpty()) { >+ return; >+ } >+ Runnable cleanUp = pendingCleanup.remove(menu); >+ if (cleanUp != null) { >+ trace("cleanUp.run()", menu, null); >+ cleanUp.run(); >+ } > } > > public void dispose() { >- // System.err.println("dispose"); >+ Menu[] keys = pendingCleanup.keySet().toArray( >+ new Menu[pendingCleanup.size()]); >+ for (Menu menu : keys) { >+ cleanUp(menu); >+ } > } > } >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java,v >retrieving revision 1.19 >diff -u -r1.19 ActionBars.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java 12 Oct 2010 16:17:57 -0000 1.19 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ActionBars.java 14 Oct 2010 18:20:44 -0000 >@@ -17,7 +17,7 @@ > import org.eclipse.e4.ui.model.application.ui.MUIElement; > import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; > import org.eclipse.e4.ui.model.application.ui.basic.MPart; >-import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.workbench.IPresentationEngine; > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.IToolBarManager; >@@ -84,18 +84,17 @@ > if (tbCtrl != null && !tbCtrl.isDisposed()) { > MUIElement tbModel = (MUIElement) tbCtrl > .getData(AbstractPartRenderer.OWNING_ME); >- if (tbModel instanceof MToolBar) { >+ if (tbModel instanceof MRenderedToolBar) { > // only force a rerender if the toolbar can be seen > if (isSelected(part)) { >- Object tbParent = tbCtrl.getParent(); > if (part.getContext() != null) { > IPresentationEngine renderer = part.getContext().get( > IPresentationEngine.class); > if (renderer != null) { > renderer.removeGui(tbModel); >- renderer.createGui(tbModel, tbParent, >+ renderer.createGui(tbModel, tbCtrl.getParent(), > part.getContext()); >- ((Control) tbModel.getWidget()).getParent().layout(); >+ tbCtrl.getParent().layout(); > } > } > } >Index: Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java,v >retrieving revision 1.33 >diff -u -r1.33 CompatibilityView.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 12 Oct 2010 16:17:57 -0000 1.33 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 14 Oct 2010 18:20:44 -0000 >@@ -12,17 +12,14 @@ > package org.eclipse.ui.internal.e4.compatibility; > > import javax.inject.Inject; >-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.ui.basic.MPart; > import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MRenderedToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; >-import org.eclipse.e4.ui.workbench.renderers.swt.MenuRenderer; > import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; >-import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarRenderer; >-import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.action.ToolBarManager; > import org.eclipse.swt.widgets.Composite; >@@ -78,19 +75,16 @@ > // dispose the tb, it will be re-created when the tab is shown > tb.dispose(); > >- IEclipseContext context = getModel().getContext(); >- IRendererFactory rendererFactory = context.get(IRendererFactory.class); >- > MenuManager mm = (MenuManager) actionBars.getMenuManager(); >- MMenu menu = null; >+ MRenderedMenu menu = null; > for (MMenu me : part.getMenus()) { >- if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >- menu = me; >+ if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU) && (me instanceof MRenderedMenu)) { >+ menu = (MRenderedMenu) me; > break; > } > } > if (menu == null) { >- menu = MenuFactoryImpl.eINSTANCE.createMenu(); >+ menu = MenuFactoryImpl.eINSTANCE.createRenderedMenu(); > menu.setElementId(part.getElementId()); > > menu.getTags().add(StackRenderer.TAG_VIEW_MENU); >@@ -98,21 +92,17 @@ > part.getMenus().add(menu); > > } >- AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent); >- if (apr instanceof MenuRenderer) { >- ((MenuRenderer) apr).linkModelToManager(menu, mm); >- } >+ menu.setContributionManager(mm); > > // Construct the toolbar (if necessary) > MToolBar toolbar = part.getToolbar(); > if (toolbar == null) { >- toolbar = MenuFactoryImpl.eINSTANCE.createToolBar(); >+ toolbar = MenuFactoryImpl.eINSTANCE.createRenderedToolBar(); > toolbar.setElementId(part.getElementId()); > part.setToolbar(toolbar); > } >- apr = rendererFactory.getRenderer(toolbar, parent); >- if (apr instanceof ToolBarRenderer) { >- ((ToolBarRenderer) apr).linkModelToManager(toolbar, tbm); >+ if (toolbar instanceof MRenderedToolBar) { >+ ((MRenderedToolBar) toolbar).setContributionManager(tbm); > } > } > }
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 325392
:
179140
|
180268
|
180514
| 180901 |
181172
|
181191
|
181226
|
182202
|
182509
|
182904
|
183010