List of usage examples for org.eclipse.jface.action MenuManager getRemoveAllWhenShown
@Override
public boolean getRemoveAllWhenShown()
From source file:net.yatomiya.e4.ui.workbench.renderers.swt.MenuManagerRenderer.java
License:Open Source License
@Override public Object createWidget(MUIElement element, Object parent) { if (!(element instanceof MMenu)) return null; final MMenu menuModel = (MMenu) element; Menu newMenu = null;//from w w w . j a va 2s .c o m MenuManager menuManager = null; boolean menuBar = false; if (parent instanceof Decorations) { MUIElement container = (MUIElement) ((EObject) element).eContainer(); if (container instanceof MWindow) { menuManager = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } newMenu = menuManager.createMenuBar((Decorations) parent); ((Decorations) parent).setMenuBar(newMenu); newMenu.setData(menuManager); menuBar = true; } else { menuManager = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } 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 = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } newMenu = menuManager.createContextMenu((Control) parent); // we can't be sure this is the correct parent. // ((Control) parent).setMenu(newMenu); if (element instanceof MPopupMenu && element.isVisible()) { Object data = getUIContainer(element); if (data instanceof Control && parent.equals(data)) { ((Control) parent).setMenu(newMenu); } } newMenu.setData(menuManager); } if (menuManager != null && !menuManager.getRemoveAllWhenShown()) { processContributions(menuModel, menuModel.getElementId(), menuBar, menuModel instanceof MPopupMenu); } if (newMenu != null) { newMenu.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { cleanUp(menuModel); MenuManager manager = getManager(menuModel); if (manager != null) { manager.markDirty(); } } }); } return newMenu; }
From source file:org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.java
License:Open Source License
@Override public Object createWidget(MUIElement element, Object parent) { if (!(element instanceof MMenu)) return null; final MMenu menuModel = (MMenu) element; Menu newMenu = null;//from w ww. j a va 2 s. c om MenuManager menuManager = null; boolean menuBar = false; if (parent instanceof Decorations) { MUIElement container = (MUIElement) ((EObject) element).eContainer(); if (container instanceof MWindow) { menuManager = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } newMenu = menuManager.createMenuBar((Decorations) parent); ((Decorations) parent).setMenuBar(newMenu); newMenu.setData(menuManager); menuBar = true; } else { menuManager = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } 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 = getManager(menuModel); if (menuManager == null) { menuManager = new MenuManager(NO_LABEL, menuModel.getElementId()); linkModelToManager(menuModel, menuManager); } 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, menuModel instanceof MPopupMenu); } if (newMenu != null) { newMenu.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cleanUp(menuModel); } }); } return newMenu; }
From source file:org.eclipse.ui.internal.PopupMenuExtender.java
License:Open Source License
/** * Construct a new menu extender./* w w w . jav a 2s. c o m*/ * * @param id * the menu id * @param menu * the menu to extend * @param prov * the selection provider * @param part * the part to extend * @param context * the context to create the child popup menu context under * @param includeEditorInput * Whether the editor input should be included when adding object * contributions to this context menu. */ public PopupMenuExtender(final String id, final MenuManager menu, final ISelectionProvider prov, final IWorkbenchPart part, IEclipseContext context, final boolean includeEditorInput) { super(); this.menu = menu; this.selProvider = prov; this.part = part; this.context = context; this.modelPart = (MPart) part.getSite().getService(MPart.class); if (includeEditorInput) { bitSet |= INCLUDE_EDITOR_INPUT; } menu.addMenuListener(this); if (!menu.getRemoveAllWhenShown()) { menuWrapper = new SubMenuManager(menu); menuWrapper.setVisible(true); } createModelFor(id); addMenuId(id); Platform.getExtensionRegistry().addRegistryChangeListener(this); }