/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.workbench.renderers.AbstractPartRenderer#getUIContainer * (org.eclipse.e4.ui.model.application.MUIElement) */ @Override public Object getUIContainer(MUIElement element) { if (!(element instanceof MMenuElement)) return null; if (element.getParent().getWidget() instanceof MenuItem) { MenuItem mi = (MenuItem) element.getParent().getWidget(); if (mi.getMenu() == null) { mi.setMenu(new Menu(mi)); } return mi.getMenu(); } return super.getUIContainer(element); }
public void testCreateMenu() { final MWindow window = createWindowWithOneViewAndMenu(); wb = new E4Workbench(window, appContext); Widget topWidget = (Widget) window.getWidget(); assertTrue(topWidget instanceof Shell); Shell shell = (Shell) topWidget; final Menu menuBar = shell.getMenuBar(); assertNotNull(menuBar); assertEquals(1, menuBar.getItemCount()); final MenuItem fileItem = menuBar.getItem(0); assertEquals("File", fileItem.getText()); final Menu fileMenu = fileItem.getMenu(); fileMenu.notifyListeners(SWT.Show, null); assertEquals(2, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); MMenu mainMenu = window.getMainMenu(); MMenu modelFileMenu = (MMenu) mainMenu.getChildren().get(0); final MMenuItem item2Model = (MMenuItem) modelFileMenu.getChildren().get(0); item2Model.setToBeRendered(false); fileMenu.notifyListeners(SWT.Show, null); assertEquals(1, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); item2Model.setToBeRendered(true); fileMenu.notifyListeners(SWT.Show, null); assertEquals(2, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); }
/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer#processContents * (org.eclipse.e4.ui.model.application.ui.MElementContainer) */ @Override public void processContents(MElementContainer<MUIElement> container) { if (container.getChildren().size() == 0) { Object obj = container.getWidget(); if (obj instanceof MenuItem) { MenuItem mi = (MenuItem) obj; if (mi.getMenu() == null) { mi.setMenu(new Menu(mi)); } Menu menu = mi.getMenu(); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(MenuManagerRendererFilter.NUL_MENU_ITEM); menuItem.setEnabled(false); } } super.processContents(container); Object obj = container.getWidget(); Object menuObj = container; if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0 && (menuObj instanceof MMenu)) { MMenu menuModel = (MMenu) menuObj; IEclipseContext ctx = getContext(container); ExpressionContext eContext = new ExpressionContext(ctx); ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>(); ContributionsAnalyzer.gatherMenuContributions( menuModel, application.getMenuContributions(), menuModel.getElementId(), toContribute, eContext, false); addMenuBarContributions(menuModel, toContribute, ctx, eContext); } }