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 182202 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]
MenuManagerRenderer v07
menuOnly-v07.txt (text/plain), 100.84 KB, created by
Paul Webster
on 2010-11-02 09:08:22 EDT
(
hide
)
Description:
MenuManagerRenderer v07
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2010-11-02 09:08:22 EDT
Size:
100.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.ui.model.workbench >Index: model/UIElements.ecore >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.model.workbench/model/UIElements.ecore,v >retrieving revision 1.67 >diff -u -r1.67 UIElements.ecore >--- model/UIElements.ecore 22 Sep 2010 18:03:14 -0000 1.67 >+++ model/UIElements.ecore 2 Nov 2010 13:01:22 -0000 >@@ -310,6 +310,11 @@ > <eStructuralFeatures xsi:type="ecore:EAttribute" name="contributionItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject" > transient="true"/> > </eClassifiers> >+ <eClassifiers xsi:type="ecore:EClass" name="OpaqueMenuItem" eSuperTypes="#//ui/menu/MenuElement"> >+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="opaqueItem" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject" >+ transient="true"/> >+ </eClassifiers> >+ <eClassifiers xsi:type="ecore:EClass" name="OpaqueMenu" eSuperTypes="#//ui/menu/Menu"/> > </eSubpackages> > <eSubpackages name="basic" nsURI="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" > nsPrefix="basic"> >#P org.eclipse.e4.ui.tests >Index: UIAllTests.launch >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/tests/org.eclipse.e4.ui.tests/UIAllTests.launch,v >retrieving revision 1.6 >diff -u -r1.6 UIAllTests.launch >--- UIAllTests.launch 19 Jul 2010 15:22:51 -0000 1.6 >+++ UIAllTests.launch 2 Nov 2010 13:01:22 -0000 >@@ -27,7 +27,7 @@ > <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> > <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> > <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> >-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> >+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> > <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.e4.ui.tests.UIAllTests"/> > <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/> > <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="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.9 >diff -u -r1.9 MMenuItemTest.java >--- src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java 14 Oct 2010 18:21:17 -0000 1.9 >+++ src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java 2 Nov 2010 13:01:22 -0000 >@@ -34,11 +34,15 @@ > 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.impl.MenuFactoryImpl; >-import org.eclipse.e4.ui.workbench.renderers.swt.MenuRenderer; >+import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer; > 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; >@@ -82,6 +86,8 @@ > 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); >@@ -157,6 +163,8 @@ > 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); >@@ -212,6 +220,8 @@ > 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); >@@ -228,7 +238,6 @@ > MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand(); > > command.setElementId("commandId"); >- command.setCommandName("CommandForTest"); > > menuItem.setCommand(command); > menuItem.setType(ItemType.CHECK); >@@ -240,13 +249,16 @@ > 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); >@@ -255,7 +267,7 @@ > assertTrue(menuItemWidget.getSelection()); > } > >- public void XXXtestSubMenuCreation() throws Exception { >+ public void testSubMenuCreation() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -289,9 +301,20 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >+ MenuManagerRenderer 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 XXXtestTbrItem() throws Exception { >+ public void testTbrItem() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -326,11 +349,20 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- // MenuRenderer renderer = getRenderer(appContext, menuBar); >+ MenuManagerRenderer 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(2, fileManager.getSize()); > } > >- public void XXXtestInvisibleItem() throws Exception { >+ public void testInvisibleItem() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -365,11 +397,22 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >- // MenuRenderer renderer = getRenderer(appContext, menuBar); >+ MenuManagerRenderer 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()); >+ >+ assertEquals(false, fileManager.getItems()[2].isVisible()); > } > >- public void XXXtestMenuContribution() throws Exception { >+ public void testMenuContribution() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -404,9 +447,17 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >+ MenuManagerRenderer 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 XXXtestWithVisible() throws Exception { >+ public void testWithVisible() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -441,9 +492,59 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >+ MenuManagerRenderer 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 XXXtestMenuBarVisibility() throws Exception { >+ public void testMenuBarVisibility() throws Exception { > MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); > MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu(); > menuBar.setElementId("org.eclipse.ui.main.menu"); >@@ -478,6 +579,36 @@ > wb = new E4Workbench(window, appContext); > wb.createAndRunUI(window); > >+ MenuManagerRenderer 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) { >@@ -537,11 +668,12 @@ > application.getMenuContributions().add(mmc); > } > >- MenuRenderer getRenderer(IEclipseContext context, MUIElement element) { >+ private MenuManagerRenderer getRenderer(IEclipseContext context, >+ MUIElement element) { > IRendererFactory rendererFactory = context.get(IRendererFactory.class); > AbstractPartRenderer renderer = rendererFactory.getRenderer(element, > null); >- assertEquals(MenuRenderer.class, renderer.getClass()); >- return (MenuRenderer) renderer; >+ assertEquals(MenuManagerRenderer.class, renderer.getClass()); >+ return (MenuManagerRenderer) renderer; > } > } >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.45 >diff -u -r1.45 MWindowTest.java >--- src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java 14 Oct 2010 18:21:17 -0000 1.45 >+++ src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java 2 Nov 2010 13:01:22 -0000 >@@ -30,6 +30,7 @@ > 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; >@@ -230,6 +231,8 @@ > > 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.18 >diff -u -r1.18 ContributionsAnalyzer.java >--- src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java 14 Oct 2010 18:21:18 -0000 1.18 >+++ src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java 2 Nov 2010 13:01:23 -0000 >@@ -176,7 +176,7 @@ > return isVisible((MCoreExpression) contribution.getVisibleWhen(), eContext); > } > >- static boolean isVisible(MCoreExpression exp, ExpressionContext eContext) { >+ public static boolean isVisible(MCoreExpression exp, ExpressionContext eContext) { > Expression ref = null; > if (exp.getCoreExpression() instanceof Expression) { > ref = (Expression) exp.getCoreExpression(); >Index: src/org/eclipse/e4/ui/workbench/UIEvents.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/UIEvents.java,v >retrieving revision 1.5 >diff -u -r1.5 UIEvents.java >--- src/org/eclipse/e4/ui/workbench/UIEvents.java 15 Jul 2010 17:23:47 -0000 1.5 >+++ src/org/eclipse/e4/ui/workbench/UIEvents.java 2 Nov 2010 13:01:23 -0000 >@@ -219,6 +219,7 @@ > > public static interface UIElement { > public static final String TOPIC = UITopicBase + "/ui/UIElement"; //$NON-NLS-1$ >+ public static final String ACCESSIBILITYPHRASE = "accessibilityPhrase"; //$NON-NLS-1$ > public static final String CONTAINERDATA = "containerData"; //$NON-NLS-1$ > public static final String CURSHAREDREF = "curSharedRef"; //$NON-NLS-1$ > public static final String ONTOP = "onTop"; //$NON-NLS-1$ >@@ -272,6 +273,11 @@ > public static final String MNEMONICS = "mnemonics"; //$NON-NLS-1$ > } > >+ public static interface OpaqueMenuItem { >+ public static final String TOPIC = UITopicBase + "/menu/OpaqueMenuItem"; //$NON-NLS-1$ >+ public static final String OPAQUEITEM = "opaqueItem"; //$NON-NLS-1$ >+ } >+ > public static interface RenderedMenu { > public static final String TOPIC = UITopicBase + "/menu/RenderedMenu"; //$NON-NLS-1$ > public static final String CONTRIBUTIONMANAGER = "contributionManager"; //$NON-NLS-1$ >#P org.eclipse.e4.ui.workbench.renderers.swt >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.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/MenuManagerRenderer.java,v >retrieving revision 1.1 >diff -u -r1.1 MenuManagerRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java 14 Oct 2010 18:21:18 -0000 1.1 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java 2 Nov 2010 13:01:23 -0000 >@@ -25,9 +25,8 @@ > 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.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.MUILabel; >@@ -39,7 +38,10 @@ > 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.MOpaqueMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem; > import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.workbench.IResourceUtilities; > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >@@ -48,17 +50,18 @@ > 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.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.Display; > import org.eclipse.swt.widgets.Menu; > import org.osgi.service.event.Event; > import org.osgi.service.event.EventHandler; >@@ -72,7 +75,8 @@ > 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, IContributionItem> modelToContribution = new HashMap<MMenuElement, IContributionItem>(); >+ private Map<IContributionItem, MMenuElement> contributionToModel = new HashMap<IContributionItem, MMenuElement>(); > > private Map<MMenuElement, ContributionRecord> modelContributionToRecord = new HashMap<MMenuElement, ContributionRecord>(); > >@@ -126,8 +130,8 @@ > modelProcessSwitch(parent, itemModel); > } > } else { >- IContributionItem ici = modelToContribution >- .remove(itemModel); >+ IContributionItem ici = getContribution(itemModel); >+ clearModelToContribution(itemModel, ici); > if (ici != null && parent != null) { > parent.remove(ici); > } >@@ -145,13 +149,20 @@ > return; > } > manager.setVisible(menuModel.isVisible()); >+ if (manager.getParent() != null) { >+ manager.getParent().markDirty(); >+ } > } else if (element instanceof MMenuElement) { > MMenuElement itemModel = (MMenuElement) element; >- IContributionItem ici = getContribution(itemModel); >- if (ici == null) { >+ Object obj = getContribution(itemModel); >+ if (!(obj instanceof ContributionItem)) { > return; > } >- ici.setVisible(itemModel.isVisible()); >+ ContributionItem item = (ContributionItem) obj; >+ item.setVisible(itemModel.isVisible()); >+ if (item.getParent() != null) { >+ item.getParent().markDirty(); >+ } > } > } > } >@@ -165,7 +176,7 @@ > > MMenuItem itemModel = (MMenuItem) event > .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = modelToContribution.get(itemModel); >+ IContributionItem ici = getContribution(itemModel); > if (ici != null) { > ici.update(); > } >@@ -180,50 +191,14 @@ > > MMenuItem itemModel = (MMenuItem) event > .getProperty(UIEvents.EventTags.ELEMENT); >- IContributionItem ici = modelToContribution.get(itemModel); >+ IContributionItem ici = getContribution(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); >- } >- } >- } >- }; >+ private MenuManagerRendererFilter rendererFilter; > > @PostConstruct > public void init() { >@@ -237,6 +212,15 @@ > eventBroker.subscribe(UIEvents.buildTopic(UIEvents.UIElement.TOPIC), > toBeRenderedUpdater); > >+ context.set(MenuManagerRenderer.class, this); >+ Display display = context.get(Display.class); >+ rendererFilter = ContextInjectionFactory.make( >+ MenuManagerRendererFilter.class, context); >+ display.addFilter(SWT.Show, rendererFilter); >+ display.addFilter(SWT.Hide, rendererFilter); >+ display.addFilter(SWT.Dispose, rendererFilter); >+ context.set(MenuManagerRendererFilter.class, rendererFilter); >+ > } > > @PreDestroy >@@ -245,6 +229,19 @@ > eventBroker.unsubscribe(selectionUpdater); > eventBroker.unsubscribe(enabledUpdater); > eventBroker.unsubscribe(toBeRenderedUpdater); >+ >+ context.remove(MenuManagerRendererFilter.class); >+ Display display = context.get(Display.class); >+ if (display != null && !display.isDisposed() && rendererFilter != null) { >+ display.removeFilter(SWT.Show, rendererFilter); >+ display.removeFilter(SWT.Hide, rendererFilter); >+ display.removeFilter(SWT.Dispose, rendererFilter); >+ } >+ if (rendererFilter != null) { >+ ContextInjectionFactory.uninject(rendererFilter, context); >+ rendererFilter = null; >+ } >+ context.remove(MenuManagerRenderer.class); > } > > /* >@@ -261,50 +258,56 @@ > > final MMenu menuModel = (MMenu) element; > Menu newMenu = null; >+ MenuManager menuManager = 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, >+ menuManager = getManager(menuModel); >+ if (menuManager == null) { >+ menuManager = new MenuManager(NO_LABEL, > menuModel.getElementId()); >- linkModelToManager(menuModel, menuBarManager); >+ linkModelToManager(menuModel, menuManager); > } >- newMenu = menuBarManager.createMenuBar((Decorations) parent); >+ newMenu = menuManager.createMenuBar((Decorations) parent); > ((Decorations) parent).setMenuBar(newMenu); >- newMenu.setData(menuBarManager); >+ newMenu.setData(menuManager); > menuBar = true; > } else { >- MenuManager popupManager = getManager(menuModel); >- if (popupManager == null) { >- popupManager = new MenuManager(NO_LABEL, >+ menuManager = getManager(menuModel); >+ if (menuManager == null) { >+ menuManager = new MenuManager(NO_LABEL, > menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >+ linkModelToManager(menuModel, menuManager); > } >- newMenu = popupManager.createContextMenu((Control) parent); >- ((Control) parent).setMenu(newMenu); >- newMenu.setData(popupManager); >+ newMenu = menuManager.createContextMenu((Control) parent); >+ // we can't be sure this is the correct parent. >+ // ((Control) parent).setMenu(newMenu); >+ newMenu.setData(menuManager); > } > } 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$ >+ return null; > > } else if (parent instanceof Control) { >- MenuManager popupManager = getManager(menuModel); >- if (popupManager == null) { >- popupManager = new MenuManager(NO_LABEL, >+ menuManager = getManager(menuModel); >+ if (menuManager == null) { >+ menuManager = new MenuManager(NO_LABEL, > menuModel.getElementId()); >- linkModelToManager(menuModel, popupManager); >+ linkModelToManager(menuModel, menuManager); > } >- newMenu = popupManager.createContextMenu((Control) parent); >- ((Control) parent).setMenu(newMenu); >- newMenu.setData(popupManager); >+ newMenu = menuManager.createContextMenu((Control) parent); >+ // we can't be sure this is the correct parent. >+ // ((Control) parent).setMenu(newMenu); >+ newMenu.setData(menuManager); >+ } >+ if (!menuManager.getRemoveAllWhenShown()) { >+ processContributions(menuModel, menuBar); > } >- processContributions(menuModel, menuBar); > if (newMenu != null) { > newMenu.addDisposeListener(new DisposeListener() { > public void widgetDisposed(DisposeEvent e) { >@@ -318,7 +321,7 @@ > /** > * @param menuModel > */ >- protected void cleanUp(MMenu menuModel) { >+ public void cleanUp(MMenu menuModel) { > Collection<ContributionRecord> vals = modelContributionToRecord > .values(); > for (ContributionRecord record : vals >@@ -336,8 +339,8 @@ > copyManager.dispose(); > } > } else { >- IContributionItem ici = modelToContribution >- .remove(copy); >+ IContributionItem ici = getContribution(copy); >+ clearModelToContribution(copy, ici); > if (ici != null) { > record.manager.remove(ici); > } >@@ -352,7 +355,7 @@ > * @param menuModel > * @param menuBar > */ >- private void processContributions(MMenu menuModel, boolean menuBar) { >+ public void processContributions(MMenu menuModel, boolean menuBar) { > final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); > ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, > application.getMenuContributions(), menuModel.getElementId(), >@@ -500,7 +503,12 @@ > boolean isVisible = ContributionsAnalyzer.isVisible( > menuContribution, exprContext); > for (MMenuElement item : generatedElements) { >- item.setVisible(isVisible); >+ if (isVisible && item.getVisibleWhen() != null) { >+ MenuManagerRenderer.updateVisibility(manager, item, >+ exprContext); >+ } else { >+ item.setVisible(isVisible); >+ } > } > manager.markDirty(); > } >@@ -564,13 +572,16 @@ > * @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); >+ MenuManager menuManager = getManager(menuModel); >+ if (menuManager == null) { >+ String menuText = getText(menuModel); >+ ImageDescriptor desc = getImageDescriptor(menuModel); >+ 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) { >@@ -600,6 +611,8 @@ > } else if (childME instanceof MMenuSeparator) { > MMenuSeparator sep = (MMenuSeparator) childME; > processSeparator(menuManager, sep); >+ } else if (childME instanceof MOpaqueMenu) { >+ // I'm not sure what to do here. > } else if (childME instanceof MMenu) { > MMenu itemModel = (MMenu) childME; > processMenu(menuManager, itemModel); >@@ -632,13 +645,17 @@ > */ > void processDirectItem(MenuManager parentManager, > MDirectMenuItem itemModel, String id) { >+ IContributionItem ici = getContribution(itemModel); >+ if (ici != null) { >+ return; >+ } > 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); >+ linkModelToContribution(itemModel, ci); > } > > /** >@@ -647,13 +664,17 @@ > */ > void processHandledItem(MenuManager parentManager, > MHandledMenuItem itemModel) { >+ IContributionItem ici = getContribution(itemModel); >+ if (ici != null) { >+ return; >+ } > 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); >+ linkModelToContribution(itemModel, ci); > } > > private String getText(MMenu menuModel) { >@@ -686,18 +707,135 @@ > 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); > } >+ >+ public MMenuElement getMenuElement(IContributionItem item) { >+ return contributionToModel.get(item); >+ } >+ >+ public void linkModelToContribution(MMenuElement model, >+ IContributionItem item) { >+ modelToContribution.put(model, item); >+ contributionToModel.put(item, model); >+ } >+ >+ public void clearModelToContribution(MMenuElement model, >+ IContributionItem item) { >+ modelToContribution.remove(model); >+ contributionToModel.remove(item); >+ } >+ >+ public ContributionRecord getContributionRecord(MMenuElement element) { >+ return modelContributionToRecord.get(element); >+ } >+ >+ /** >+ * @param menuManager >+ * @param menuModel >+ */ >+ public void reconcileManagerToModel(MenuManager menuManager, MMenu menuModel) { >+ List<MMenuElement> modelChildren = menuModel.getChildren(); >+ >+ HashSet<MOpaqueMenuItem> oldModelItems = new HashSet<MOpaqueMenuItem>(); >+ HashSet<MOpaqueMenu> oldMenus = new HashSet<MOpaqueMenu>(); >+ for (MMenuElement itemModel : modelChildren) { >+ if (itemModel instanceof MOpaqueMenuItem) { >+ oldModelItems.add((MOpaqueMenuItem) itemModel); >+ } else if (itemModel instanceof MOpaqueMenu) { >+ oldMenus.add((MOpaqueMenu) itemModel); >+ } >+ } >+ >+ IContributionItem[] items = menuManager.getItems(); >+ for (int src = 0, dest = 0; src < items.length; src++, dest++) { >+ IContributionItem item = items[src]; >+ if (item instanceof MenuManager) { >+ MenuManager childManager = (MenuManager) item; >+ MMenu childModel = getMenuModel(childManager); >+ if (childModel == null) { >+ MMenu legacyModel = MenuFactoryImpl.eINSTANCE >+ .createOpaqueMenu(); >+ legacyModel.setElementId(childManager.getId()); >+ legacyModel.setVisible(childManager.isVisible()); >+ linkModelToManager(legacyModel, childManager); >+ modelChildren.add(dest, legacyModel); >+ } else { >+ if (childModel instanceof MOpaqueMenu) { >+ oldMenus.remove(childModel); >+ } >+ if (modelChildren.size() > dest) { >+ if (modelChildren.get(dest) != childModel) { >+ modelChildren.remove(childModel); >+ modelChildren.add(dest, childModel); >+ } >+ } else { >+ modelChildren.add(childModel); >+ } >+ } >+ } else { >+ MMenuElement menuElement = getMenuElement(item); >+ if (menuElement == null) { >+ MOpaqueMenuItem legacyItem = MenuFactoryImpl.eINSTANCE >+ .createOpaqueMenuItem(); >+ legacyItem.setElementId(item.getId()); >+ legacyItem.setVisible(item.isVisible()); >+ legacyItem.setOpaqueItem(item); >+ linkModelToContribution(legacyItem, item); >+ modelChildren.add(dest, legacyItem); >+ } else if (menuElement instanceof MOpaqueMenuItem) { >+ MOpaqueMenuItem legacyItem = (MOpaqueMenuItem) menuElement; >+ oldModelItems.remove(legacyItem); >+ if (modelChildren.size() > dest) { >+ if (modelChildren.get(dest) != legacyItem) { >+ modelChildren.remove(legacyItem); >+ modelChildren.add(dest, legacyItem); >+ } >+ } else { >+ modelChildren.add(legacyItem); >+ } >+ } >+ } >+ } >+ if (!oldModelItems.isEmpty()) { >+ modelChildren.removeAll(oldModelItems); >+ for (MOpaqueMenuItem model : oldModelItems) { >+ clearModelToContribution(model, >+ (IContributionItem) model.getOpaqueItem()); >+ } >+ } >+ if (!oldMenus.isEmpty()) { >+ modelChildren.removeAll(oldMenus); >+ for (MOpaqueMenu oldMenu : oldMenus) { >+ MenuManager oldManager = getManager(oldMenu); >+ clearModelToManager(oldMenu, oldManager); >+ } >+ } >+ } >+ >+ /** >+ * @param menuManager >+ * @param element >+ * @param evalContext >+ */ >+ public static void updateVisibility(MenuManager menuManager, >+ MMenuElement element, ExpressionContext evalContext) { >+ if (!(element.getVisibleWhen() instanceof MCoreExpression)) { >+ return; >+ } >+ boolean val = ContributionsAnalyzer.isVisible( >+ (MCoreExpression) element.getVisibleWhen(), evalContext); >+ if (val != element.isVisible()) { >+ element.setVisible(val); >+ menuManager.markDirty(); >+ } >+ } > } >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,418 @@ >+/******************************************************************************* >+ * 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.renderers.swt; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import java.util.HashMap; >+import java.util.HashSet; >+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.ContextInjectionFactory; >+import org.eclipse.e4.core.contexts.EclipseContextFactory; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.core.di.annotations.CanExecute; >+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.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.menu.MDirectMenuItem; >+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.MMenu; >+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.modeling.EModelService; >+import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.ContributionRecord; >+import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; >+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 MenuManagerRendererFilter implements Listener { >+ public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$ >+ >+ private static final String TMP_ORIGINAL_CONTEXT = "MenuServiceFilter.original.context"; //$NON-NLS-1$ >+ >+ private static void trace(String msg, Widget menu, MMenu menuModel) { >+ WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": " //$NON-NLS-1$ //$NON-NLS-2$ >+ + menuModel, null); >+ } >+ >+ private static Method aboutToShow; >+ >+ private static Method aboutToHide; >+ >+ public 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; >+ } >+ >+ public static Method getAboutToHide() { >+ if (aboutToHide == null) { >+ try { >+ aboutToHide = MenuManager.class >+ .getDeclaredMethod("handleAboutToHide"); //$NON-NLS-1$ >+ aboutToHide.setAccessible(true); >+ } catch (SecurityException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (NoSuchMethodException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ return aboutToHide; >+ } >+ >+ @Inject >+ private Logger logger; >+ >+ @Inject >+ private EModelService modelService; >+ >+ @Inject >+ private IRendererFactory rendererFactory; >+ >+ @Inject >+ private MenuManagerRenderer renderer; >+ >+ @Inject >+ private EHandlerService handlerService; >+ >+ private HashMap<Menu, Runnable> pendingCleanup = new HashMap<Menu, Runnable>(); >+ >+ private class SafeWrapper implements ISafeRunnable { >+ Event event; >+ >+ public void handleException(Throwable e) { >+ if (e instanceof Error) { >+ // errors are deadly, we shouldn't ignore these >+ throw (Error) e; >+ } >+ // log exceptions otherwise >+ if (logger != null) { >+ logger.error(e); >+ } >+ } >+ >+ public void run() throws Exception { >+ safeHandleEvent(event); >+ } >+ } >+ >+ private SafeWrapper safeWrapper = new SafeWrapper(); >+ >+ public void handleEvent(final Event event) { >+ // wrap the handling in a SafeRunner so that exceptions do not prevent >+ // the menu from being shown >+ safeWrapper.event = event; >+ SafeRunner.run(safeWrapper); >+ } >+ >+ private void safeHandleEvent(Event event) { >+ if (!(event.widget instanceof Menu)) { >+ return; >+ } >+ final Menu menu = (Menu) event.widget; >+ if ((menu.getStyle() & SWT.BAR) != 0) { >+ // don't process the menu bar, it's not fair :-) >+ return; >+ } >+ if (event.type == SWT.Dispose) { >+ trace("handleMenu.Dispose", menu, null); //$NON-NLS-1$ >+ cleanUp(menu, null, null); >+ return; >+ } >+ >+ // fill in all of the pieces >+ MMenu menuModel = null; >+ MenuManager menuManager = null; >+ Object obj = menu.getData(AbstractPartRenderer.OWNING_ME); >+ if (obj == null && menu.getParentItem() != null) { >+ obj = menu.getParentItem().getData(AbstractPartRenderer.OWNING_ME); >+ if (obj == null) { >+ // hack because MenuManager doesn't do a setData() >+ Object tmp = menu.getParentItem().getData(); >+ if (tmp instanceof MenuManager) { >+ MenuManager tmpManager = (MenuManager) tmp; >+ if (menu == tmpManager.getMenu()) { >+ // Eureka! We found a match, by golly! >+ menuManager = tmpManager; >+ obj = renderer.getMenuModel(tmpManager); >+ } >+ } >+ } >+ } >+ if (obj instanceof MMenu) { >+ menuModel = (MMenu) obj; >+ } >+ if (menuManager == null && menuModel != null) { >+ menuManager = renderer.getManager(menuModel); >+ } >+ >+ switch (event.type) { >+ case SWT.Show: >+ handleShow(event, menu, menuModel, menuManager); >+ break; >+ case SWT.Hide: >+ handleHide(event, menu, menuModel, menuManager); >+ break; >+ } >+ >+ } >+ >+ private void handleShow(final Event event, final Menu menu, >+ MMenu menuModel, MenuManager menuManager) { >+ if (menuModel != null && menuManager != null) { >+ cleanUp(menu, menuModel, menuManager); >+ } >+ if (menuModel instanceof MPopupMenu) { >+ showPopup(event, menu, (MPopupMenu) menuModel, menuManager); >+ } >+ if (menuModel != null) { >+ showMenu(event, menu, menuModel, menuManager); >+ } else { >+ trace("Incorrect menu model to work with " + menuManager, menu, menuModel); //$NON-NLS-1$ >+ } >+ } >+ >+ private void handleHide(final Event event, final Menu menu, >+ MMenu menuModel, MenuManager menuManager) { >+ if (menuModel instanceof MPopupMenu) { >+ hidePopup(event, menu, (MPopupMenu) menuModel, menuManager); >+ } >+ } >+ >+ public void showMenu(final Event event, final Menu menu, >+ final MMenu menuModel, MenuManager menuManager) { >+ AbstractPartRenderer obj = rendererFactory.getRenderer(menuModel, >+ menu.getParent()); >+ if (!(obj instanceof MenuManagerRenderer)) { >+ trace("Not the correct renderer: " + obj, menu, menuModel); //$NON-NLS-1$ >+ return; >+ } >+ MenuManagerRenderer renderer = (MenuManagerRenderer) obj; >+ if (menuModel.getWidget() == null) { >+ renderer.bindWidget(menuModel, menuManager.getMenu()); >+ } >+ >+ Method handleAboutToShow = getAboutToShow(); >+ try { >+ handleAboutToShow.invoke(menuManager); >+ } 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 (!menuManager.getRemoveAllWhenShown()) { >+ renderer.reconcileManagerToModel(menuManager, menuModel); >+ // this will make sure all model elements are represented in the >+ // menu itself. >+ // double cast because we're bad people >+ renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel)); >+ } >+ >+ final IEclipseContext evalContext; >+ if (menuModel instanceof MContext) { >+ evalContext = ((MContext) menuModel).getContext(); >+ } else { >+ evalContext = modelService.getContainingContext(menuModel); >+ } >+ updateElementVisibility(menuModel, renderer, menuManager, evalContext, >+ true); >+ >+ // last thing to do, kill the event and update the menu manager >+ event.type = SWT.None; >+ event.doit = false; >+ menuManager.update(false); >+ } >+ >+ /** >+ * @param menuModel >+ * @param renderer >+ * @param menuManager >+ * @param evalContext >+ */ >+ private void updateElementVisibility(final MMenu menuModel, >+ MenuManagerRenderer renderer, MenuManager menuManager, >+ final IEclipseContext evalContext, boolean recurse) { >+ final ExpressionContext exprContext = new ExpressionContext(evalContext); >+ HashSet<ContributionRecord> records = new HashSet<ContributionRecord>(); >+ for (MMenuElement element : menuModel.getChildren()) { >+ ContributionRecord record = renderer.getContributionRecord(element); >+ if (record != null) { >+ if (records.add(record)) { >+ record.updateVisibility(evalContext); >+ } >+ } else { >+ MenuManagerRenderer.updateVisibility(menuManager, element, >+ exprContext); >+ } >+ if (recurse && element.isVisible() && element instanceof MMenu) { >+ MMenu childMenu = (MMenu) element; >+ MenuManager childManager = renderer.getManager(childMenu); >+ if (childManager != null) { >+ updateElementVisibility(childMenu, renderer, childManager, >+ evalContext, false); >+ } >+ } >+ >+ if (element instanceof MHandledMenuItem) { >+ ParameterizedCommand cmd = ((MHandledMenuItem) element) >+ .getWbCommand(); >+ if (cmd != null) { >+ ((MHandledMenuItem) element).setEnabled(handlerService >+ .canExecute(cmd)); >+ } >+ } else if (element instanceof MDirectMenuItem) { >+ MDirectMenuItem contrib = (MDirectMenuItem) element; >+ if (contrib.getObject() != null) { >+ IEclipseContext staticContext = EclipseContextFactory >+ .create(); >+ staticContext.set(MItem.class, contrib); >+ Object rc = ContextInjectionFactory.invoke( >+ contrib.getObject(), CanExecute.class, evalContext, >+ staticContext, Boolean.TRUE); >+ if (rc instanceof Boolean) { >+ contrib.setEnabled((Boolean) rc); >+ } >+ } >+ } >+ } >+ } >+ >+ public void hidePopup(Event event, Menu menu, MPopupMenu menuModel, >+ MenuManager menuManager) { >+ 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, MenuManager menuManager) { >+ // 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); >+ } >+ >+ 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)); >+ } >+ >+ 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, null); >+ // } >+ event.type = SWT.None; >+ event.doit = false; >+ } >+ >+ public void cleanUp(final Menu menu, MMenu menuModel, >+ MenuManager menuManager) { >+ trace("cleanUp", menu, null); //$NON-NLS-1$ >+ if (pendingCleanup.isEmpty()) { >+ return; >+ } >+ Runnable cleanUp = pendingCleanup.remove(menu); >+ if (cleanUp != null) { >+ trace("cleanUp.run()", menu, null); //$NON-NLS-1$ >+ cleanUp.run(); >+ } >+ } >+ >+ public void dispose() { >+ Menu[] keys = pendingCleanup.keySet().toArray( >+ new Menu[pendingCleanup.size()]); >+ for (Menu menu : keys) { >+ cleanUp(menu, null, null); >+ } >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java >diff -N src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,182 @@ >+/******************************************************************************* >+ * 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.renderers.swt; >+ >+import java.lang.reflect.Method; >+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.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; >+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"; //$NON-NLS-1$ >+ >+ private static void trace(String msg, Widget menu, MMenu menuModel) { >+ WorkbenchSWTActivator.trace(Policy.MENUS, msg + ": " + menu + ": " //$NON-NLS-1$ //$NON-NLS-2$ >+ + menuModel, null); >+ } >+ >+ private static Method aboutToShow; >+ >+ public 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; >+ } >+ >+ @Inject >+ private Logger logger; >+ >+ @Inject >+ EModelService modelService; >+ >+ 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); //$NON-NLS-1$ >+ 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/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.10 >diff -u -r1.10 MenuRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 14 Oct 2010 18:21:18 -0000 1.10 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java 2 Nov 2010 13:01:23 -0000 >@@ -25,7 +25,6 @@ > import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; > import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >-import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.DisposeEvent; >@@ -102,7 +101,7 @@ > } > Menu menu = mi.getMenu(); > MenuItem menuItem = new MenuItem(menu, SWT.PUSH); >- menuItem.setText(MenuServiceFilter.NUL_MENU_ITEM); >+ menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM); > menuItem.setEnabled(false); > } > } >Index: src/org/eclipse/e4/ui/workbench/renderers/swt/SeparatorRenderer.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/SeparatorRenderer.java,v >retrieving revision 1.10 >diff -u -r1.10 SeparatorRenderer.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/SeparatorRenderer.java 14 Jul 2010 20:21:23 -0000 1.10 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/SeparatorRenderer.java 2 Nov 2010 13:01:23 -0000 >@@ -12,11 +12,8 @@ > > import java.util.List; > import org.eclipse.e4.ui.model.application.ui.MUIElement; >-import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator; > import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.widgets.Menu; >-import org.eclipse.swt.widgets.MenuItem; > import org.eclipse.swt.widgets.ToolBar; > import org.eclipse.swt.widgets.ToolItem; > import org.eclipse.swt.widgets.Widget; >@@ -41,21 +38,10 @@ > return null; > } > if (nextVisibleChild.isVisible() >- && (nextVisibleChild instanceof MMenuSeparator || nextVisibleChild instanceof MToolBarSeparator)) { >+ && (nextVisibleChild instanceof MToolBarSeparator)) { > return null; > } >- if (element instanceof MMenuSeparator) { >- Menu menu = null; >- Object widget = element.getParent().getWidget(); >- if (widget instanceof Menu) { >- menu = (Menu) widget; >- } else if (widget instanceof MenuItem) { >- menu = ((MenuItem) widget).getMenu(); >- } >- if (menu != null) { >- newSep = new MenuItem(menu, SWT.SEPARATOR, addIndex); >- } >- } else if (element instanceof MToolBarSeparator) { >+ if (element instanceof MToolBarSeparator) { > ToolBar tb = parent instanceof ToolBar ? (ToolBar) parent > : (ToolBar) element.getParent().getWidget(); > newSep = new ToolItem(tb, SWT.SEPARATOR, addIndex); >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.5 >diff -u -r1.5 WorkbenchRendererFactory.java >--- src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java 14 Oct 2010 18:21:18 -0000 1.5 >+++ src/org/eclipse/e4/ui/workbench/renderers/swt/WorkbenchRendererFactory.java 2 Nov 2010 13:01:23 -0000 >@@ -14,12 +14,8 @@ > 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; >@@ -30,8 +26,7 @@ > public class WorkbenchRendererFactory implements IRendererFactory { > > private AreaRenderer areaRenderer; >- private MenuRenderer menuRenderer; >- private HandledMenuItemRenderer handledMenuItemRenderer; >+ private MenuManagerRenderer menuRenderer; > private ToolBarRenderer toolbarRenderer; > private ToolItemRenderer toolItemRenderer; > private SeparatorRenderer separatorRenderer; >@@ -46,9 +41,6 @@ > 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) { >@@ -64,33 +56,9 @@ > 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(); >+ menuRenderer = new MenuManagerRenderer(); > initRenderer(menuRenderer); > } > return menuRenderer; >#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.52 >diff -u -r1.52 PartRenderingEngine.java >--- src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java 25 Oct 2010 17:25:59 -0000 1.52 >+++ src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java 2 Nov 2010 13:01:24 -0000 >@@ -52,6 +52,7 @@ > 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; >@@ -59,7 +60,6 @@ > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.EModelService; > import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; >-import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; > import org.eclipse.emf.ecore.impl.EObjectImpl; > import org.eclipse.equinox.app.IApplication; > import org.eclipse.equinox.app.IApplicationContext; >@@ -91,8 +91,6 @@ > > IRendererFactory curFactory = null; > >- MenuServiceFilter menuServiceFilter; >- > org.eclipse.swt.widgets.Listener keyListener; > > // Life Cycle handlers >@@ -109,8 +107,10 @@ > .eContainer(); > } > >+ boolean menuChild = parent instanceof MMenu; >+ > // If the parent isn't displayed who cares? >- if (parent == null || parent.getWidget() == null) >+ if (parent == null || parent.getWidget() == null || menuChild) > return; > > if (changedElement.isToBeRendered()) { >@@ -208,9 +208,10 @@ > 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) >+ if ((!isApplication && renderer == null) || menuChild) > return; > > String eventType = (String) event >@@ -688,7 +689,13 @@ > > public Object run(final MApplicationElement uiRoot, > final IEclipseContext runContext) { >- final Display display = Display.getDefault(); >+ final Display display; >+ if (runContext.get(Display.class) != null) { >+ display = runContext.get(Display.class); >+ } else { >+ display = Display.getDefault(); >+ runContext.set(Display.class, display); >+ } > Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { > > public void run() { >@@ -706,13 +713,6 @@ > display.addFilter(SWT.KeyDown, keyListener); > display.addFilter(SWT.Traverse, keyListener); > >- menuServiceFilter = ContextInjectionFactory.make( >- MenuServiceFilter.class, runContext); >- display.addFilter(SWT.Show, menuServiceFilter); >- display.addFilter(SWT.Hide, menuServiceFilter); >- display.addFilter(SWT.Dispose, menuServiceFilter); >- runContext.set(MenuServiceFilter.class, menuServiceFilter); >- > // Show the initial UI > > // Create a 'limbo' shell (used to host controls that shouldn't >@@ -845,17 +845,6 @@ > * why this is needed we should make this safe for multiple calls > */ > private void cleanUp() { >- if (menuServiceFilter != null) { >- Display display = Display.getDefault(); >- if (!display.isDisposed()) { >- display.removeFilter(SWT.Show, menuServiceFilter); >- display.removeFilter(SWT.Hide, menuServiceFilter); >- display.removeFilter(SWT.Dispose, menuServiceFilter); >- menuServiceFilter.dispose(); >- menuServiceFilter = null; >- appContext.remove(MenuServiceFilter.class); >- } >- } > if (keyListener != null) { > Display display = Display.getDefault(); > if (!display.isDisposed()) { >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 >--- src/org/eclipse/e4/ui/workbench/swt/modeling/MenuManagerServiceFilter.java 14 Oct 2010 18:21:19 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,193 +0,0 @@ >-/******************************************************************************* >- * 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.12 >diff -u -r1.12 MenuService.java >--- src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java 14 Oct 2010 18:21:19 -0000 1.12 >+++ src/org/eclipse/e4/ui/workbench/swt/modeling/MenuService.java 2 Nov 2010 13:01:24 -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.swt.SWT; >+import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; > 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 { >@@ -34,7 +34,10 @@ > for (MMenu mmenu : myPart.getMenus()) { > if (menuId.equals(mmenu.getElementId()) > && mmenu instanceof MPopupMenu) { >- if (registerMenu(parentControl, (MPopupMenu) mmenu)) { >+ Menu menu = registerMenu(parentControl, (MPopupMenu) mmenu, >+ myPart); >+ if (menu != null) { >+ parentControl.setMenu(menu); > return (MPopupMenu) mmenu; > } else { > return null; >@@ -44,25 +47,44 @@ > return null; > } > >- private boolean registerMenu(final Control parentControl, >- final MPopupMenu mmenu) { >+ public static Menu registerMenu(final Control parentControl, >+ final MPopupMenu mmenu, final MPart part) { > if (mmenu.getWidget() != null) { >- return false; >+ return (Menu) mmenu.getWidget(); > } >- Menu menu = new Menu(parentControl); >- parentControl.setMenu(menu); >- mmenu.setWidget(menu); >- menu.setData(AbstractPartRenderer.OWNING_ME, mmenu); >- IEclipseContext popupContext = myPart.getContext().createChild( >+ // we need to delegate to the renderer so that it "processes" the >+ // MenuManager correctly >+ IRendererFactory rendererFactory = part.getContext().get( >+ IRendererFactory.class); >+ AbstractPartRenderer renderer = rendererFactory.getRenderer(mmenu, >+ parentControl); >+ IEclipseContext popupContext = part.getContext().createChild( > "popup:" + mmenu.getElementId()); > mmenu.setContext(popupContext); >- menu.addListener(SWT.Dispose, new Listener() { >- public void handleEvent(Event event) { >- mmenu.getContext().dispose(); >- mmenu.setContext(null); >- mmenu.setWidget(null); >- } >- }); >- return true; >+ Object widget = renderer.createWidget(mmenu, parentControl); >+ if (!(widget instanceof Menu)) { >+ return null; >+ } >+ 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); >+ } >+ >+ return (Menu) widget; > } > } >Index: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java >diff -N src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java >--- src/org/eclipse/e4/ui/workbench/swt/modeling/MenuServiceFilter.java 14 Oct 2010 18:21:19 -0000 1.30 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,369 +0,0 @@ >-/******************************************************************************* >- * 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.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 { >- 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 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); >- } >- } >- >- 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: >- 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; >- } >- } >- >- public void showMenu(final Event event, final Menu menu, >- final MMenu menuModel) { >- 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) { >- 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); >- >- 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) { >- 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() { >- 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/PopupMenuExtender.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java,v >retrieving revision 1.8 >diff -u -r1.8 PopupMenuExtender.java >--- Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java 27 Oct 2010 18:46:46 -0000 1.8 >+++ Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java 2 Nov 2010 13:01:24 -0000 >@@ -24,20 +24,18 @@ > import org.eclipse.core.runtime.IRegistryChangeEvent; > import org.eclipse.core.runtime.IRegistryChangeListener; > import org.eclipse.core.runtime.Platform; >-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.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.model.application.ui.menu.impl.MenuFactoryImpl; >-import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; >+import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer; >+import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; >+import org.eclipse.e4.ui.workbench.swt.modeling.MenuService; > import org.eclipse.jface.action.ContributionManager; >-import org.eclipse.jface.action.GroupMarker; > import org.eclipse.jface.action.IContributionItem; > import org.eclipse.jface.action.IMenuListener2; > import org.eclipse.jface.action.IMenuManager; >@@ -51,7 +49,6 @@ > import org.eclipse.swt.widgets.Display; > import org.eclipse.ui.IEditorPart; > import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.IWorkbenchActionConstants; > import org.eclipse.ui.IWorkbenchPart; > import org.eclipse.ui.IWorkbenchPartSite; > import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; >@@ -93,8 +90,6 @@ > > private ArrayList actionContributionCache = new ArrayList(); > private ArrayList managerContributionCache = new ArrayList(); >- private ArrayList<MRenderedMenu> renderedMenuCache = new ArrayList<MRenderedMenu>(); >- private ArrayList<MRenderedMenu> lastRenderedMenuCache = new ArrayList<MRenderedMenu>(); > private boolean cleanupNeeded = false; > > private MPart modelPart; >@@ -159,35 +154,29 @@ > } > menuModel = null; > for (MMenu item : modelPart.getMenus()) { >- if (id.equals(item.getElementId()) && item instanceof MRenderedMenu >+ if (id.equals(item.getElementId()) && item instanceof MPopupMenu > && item.getTags().contains("popup")) { //$NON-NLS-1$ >- menuModel = (MRenderedMenu) item; >+ menuModel = (MPopupMenu) item; > break; > } > } > if (menuModel == null) { >- menuModel = MenuFactoryImpl.eINSTANCE.createRenderedMenu(); >+ menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu(); > menuModel.setElementId(id); > menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP); > modelPart.getMenus().add(menuModel); >- MPopupMenu popup = MenuFactoryImpl.eINSTANCE.createPopupMenu(); >- popup.setElementId(id); >- popup.getTags().add(ContributionsAnalyzer.MC_POPUP); >- menuModel.getChildren().add(popup); > } >- menuModel.setContributionManager(menu); >+ IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(menuModel, null); >+ if (obj instanceof MenuManagerRenderer) { >+ ((MenuManagerRenderer) obj).linkModelToManager(menuModel, menu); >+ } > registerE4Support(); > } > > private void registerE4Support() { > if (menuModel.getWidget() == null && menu.getMenu() != null) { >- menuModel.setWidget(menu.getMenu()); >- menu.getMenu().setData(AbstractPartRenderer.OWNING_ME, menuModel); >- MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0); >- IEclipseContext popupContext = modelPart.getContext().createChild( >- "popup:" + popup.getElementId()); //$NON-NLS-1$ >- popup.setContext(popupContext); >- >+ MenuService.registerMenu(menu.getMenu().getParent(), menuModel, modelPart); > } > } > // getMenuId() added by Dan Rubel (dan_rubel@instantiations.com) >@@ -227,7 +216,7 @@ > public final void addMenuId(final String menuId) { > bitSet &= ~STATIC_ACTION_READ; > if (menuModel != null) { >- List<String> tags = menuModel.getChildren().get(0).getTags(); >+ List<String> tags = menuModel.getTags(); > String tag = "popup:" + menuId; //$NON-NLS-1$ > if (!tags.contains(tag)) { > tags.add(tag); >@@ -388,103 +377,46 @@ > } > } > >+ addMenuContributions(mgr); >+ > readStaticActions(); > // test for additions removed to comply with menu contributions > if (menuWrapper != null) { > mgr = menuWrapper; > menuWrapper.removeAll(); > } >- addMenuContributions(mgr); > if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) { > addEditorActions(mgr); > } > addObjectActions(mgr); > addStaticActions(mgr); >- cleanUpContributionCache(); > } > > > /** >+ * well, this goes to the renderer. >+ * > * @param mgr > */ > private void addMenuContributions(IMenuManager mgr) { >- MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0); >- final IEclipseContext popupContext = popup.getContext(); >- final IEclipseContext parentContext = popupContext.getParent(); >- // final IEclipseContext originalChild = (IEclipseContext) parentContext >- // .getLocal(IContextConstants.ACTIVE_CHILD); >- // parentContext.set(IContextConstants.ACTIVE_CHILD, popupContext); >- // popupContext.set(TMP_ORIGINAL_CONTEXT, originalChild); >- MApplication application = parentContext.get(MApplication.class); >- >- final ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); >- // final ArrayList<MMenuElement> menuContributionsToRemove = new >- // ArrayList<MMenuElement>(); >- ExpressionContext eContext = new ExpressionContext(popupContext); >- ContributionsAnalyzer.gatherMenuContributions(popup, application.getMenuContributions(), >- popup.getElementId(), toContribute, eContext, true); >- >- for (String tag : popup.getTags()) { >- if (tag.startsWith("popup:") && tag.length() > 6) { //$NON-NLS-1$ >- ContributionsAnalyzer.gatherMenuContributions(popup, >- application.getMenuContributions(), tag.substring(6), toContribute, >- eContext, false); >- } >- } >- for (MMenuContribution contribution : toContribute) { >- String positionInParent = contribution.getPositionInParent(); >- 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) { >- continue; >- } >- IContributionItem item = mgr.find(id); >- if (item == null) { >- if (IWorkbenchActionConstants.MB_ADDITIONS.equals(id)) { >- mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); >- } else { >- continue; >- } >- } >- for (MMenuElement element : contribution.getChildren()) { >- if (element instanceof MMenu) { >- MMenu menu = (MMenu) element; >- if (mgr.find(menu.getElementId()) != null) { >- continue; >- } >- MenuManager submenu = new MenuManager(menu.getLabel(), menu.getElementId()); >- if (modifier.equals("before")) { //$NON-NLS-1$ >- mgr.insertBefore(id, submenu); >- } else { >- mgr.insertAfter(id, submenu); >- } >- MRenderedMenu renderedMenu = MenuFactoryImpl.eINSTANCE.createRenderedMenu(); >- renderedMenu.setElementId(menu.getElementId()); >- renderedMenu.getTags().add(ContributionsAnalyzer.MC_POPUP); >- renderedMenu.setContributionManager(submenu); >- popup.getChildren().add(renderedMenu); >- renderedMenuCache.add(renderedMenu); >- } >- } >+ IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(menuModel, null); >+ if (obj instanceof MenuManagerRenderer) { >+ MenuManagerRenderer renderer = (MenuManagerRenderer) obj; >+ renderer.reconcileManagerToModel(menu, menuModel); >+ renderer.processContributions(menuModel, false); >+ // double cast because we're bad people >+ renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel)); > } > } > >- private MRenderedMenu menuModel; >+ private MPopupMenu menuModel; > > /** > * Notifies the listener that the menu is about to be hidden. > */ > public final void menuAboutToHide(final IMenuManager mgr) { > gatherContributions(mgr); >- if (!renderedMenuCache.isEmpty()) { >- lastRenderedMenuCache = renderedMenuCache; >- renderedMenuCache = new ArrayList<MRenderedMenu>(); >- } > cleanupNeeded = true; > // Remove this menu as a visible menu. > final IWorkbenchPartSite site = part.getSite(); >@@ -539,11 +471,13 @@ > } > } > >- for (MRenderedMenu rmenu : lastRenderedMenuCache) { >- MPopupMenu popup = (MPopupMenu) menuModel.getChildren().get(0); >- popup.getChildren().remove(rmenu); >+ IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); >+ AbstractPartRenderer obj = factory.getRenderer(menuModel, null); >+ if (obj instanceof MenuManagerRenderer) { >+ MenuManagerRenderer renderer = (MenuManagerRenderer) obj; >+ renderer.cleanUp(menuModel); > } >- lastRenderedMenuCache.clear(); >+ > managerContributionCache.clear(); > > } >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.34 >diff -u -r1.34 CompatibilityView.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 14 Oct 2010 18:21:19 -0000 1.34 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityView.java 2 Nov 2010 13:01:24 -0000 >@@ -12,14 +12,17 @@ > 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.MenuManagerRenderer; > import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; >+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; >@@ -75,16 +78,19 @@ > // 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(); >- MRenderedMenu menu = null; >+ MMenu menu = null; > for (MMenu me : part.getMenus()) { >- if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU) && (me instanceof MRenderedMenu)) { >- menu = (MRenderedMenu) me; >+ if (me.getTags().contains(StackRenderer.TAG_VIEW_MENU)) { >+ menu = me; > break; > } > } > if (menu == null) { >- menu = MenuFactoryImpl.eINSTANCE.createRenderedMenu(); >+ menu = MenuFactoryImpl.eINSTANCE.createMenu(); > menu.setElementId(part.getElementId()); > > menu.getTags().add(StackRenderer.TAG_VIEW_MENU); >@@ -92,7 +98,10 @@ > part.getMenus().add(menu); > > } >- menu.setContributionManager(mm); >+ AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent); >+ if (apr instanceof MenuManagerRenderer) { >+ ((MenuManagerRenderer) apr).linkModelToManager(menu, mm); >+ } > > // Construct the toolbar (if necessary) > MToolBar toolbar = part.getToolbar();
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