private void createModelFor(String id) { if (id == null) { id = getClass().getName() + '.' + System.identityHashCode(this); } menuModel = null; for (MMenu item : modelPart.getMenus()) { if (id.equals(item.getElementId()) && item instanceof MPopupMenu && item.getTags().contains(ContributionsAnalyzer.MC_POPUP)) { menuModel = (MPopupMenu) item; break; } } if (menuModel == null) { menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu(); menuModel.setElementId(id); menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP); modelPart.getMenus().add(menuModel); } IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); if (obj instanceof MenuManagerRenderer) { ((MenuManagerRenderer) obj).linkModelToManager(menuModel, menu); } registerE4Support(); cleanUpContributionCache(); }
private MMenu getPopupMenu(final MApplication inApplication, final EModelService inModel) { if (popupStyles == null) { final MPart lPart = (MPart) inModel.find(RelationsConstants.PART_INSPECTOR, inApplication); for (final MMenu lMenu : lPart.getMenus()) { if (RelationsConstants.POPUP_INSPECTOR.equals(lMenu.getElementId())) { popupStyles = lMenu; break; } } } return popupStyles; }
@Override public void disposeWidget(MUIElement element) { if (element instanceof MPart) { MPart part = (MPart) element; MToolBar toolBar = part.getToolbar(); if (toolBar != null) { Widget widget = (Widget) toolBar.getWidget(); if (widget != null) { unbindWidget(toolBar); widget.dispose(); } } for (MMenu menu : part.getMenus()) { engine.removeGui(menu); } } super.disposeWidget(element); }
private MPart createPart(MPartDescriptor descriptor) { if (descriptor == null) { return null; } MPart part = modelService.createModelElement(MPart.class); part.setElementId(descriptor.getElementId()); part.getMenus().addAll(EcoreUtil.copyAll(descriptor.getMenus())); if (descriptor.getToolbar() != null) { part.setToolbar((MToolBar) EcoreUtil.copy((EObject) descriptor.getToolbar())); } part.setContributorURI(descriptor.getContributorURI()); part.setCloseable(descriptor.isCloseable()); part.setContributionURI(descriptor.getContributionURI()); part.setLabel(descriptor.getLabel()); part.setIconURI(descriptor.getIconURI()); part.setTooltip(descriptor.getTooltip()); part.getHandlers().addAll(EcoreUtil.copyAll(descriptor.getHandlers())); part.getTags().addAll(descriptor.getTags()); part.getPersistedState().putAll(descriptor.getPersistedState()); part.getBindingContexts().addAll(descriptor.getBindingContexts()); return part; }
/** Dispose of the menu extender. Should only be called when the part is disposed. */ public void dispose() { clearStaticActions(); final IMenuService menuService = (IMenuService) part.getSite().getService(IMenuService.class); if (menuService != null) { menuService.releaseContributions(menu); } Platform.getExtensionRegistry().removeRegistryChangeListener(this); menu.removeMenuListener(this); if (menuModel != null) { // unlink ourselves from the renderer IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); if (obj instanceof MenuManagerRenderer) { MenuManagerRenderer renderer = (MenuManagerRenderer) obj; unlink(renderer, menuModel); renderer.clearModelToManager(menuModel, menu); } modelPart.getMenus().remove(menuModel); } }
private <T> void findElementsRecursive( MApplicationElement searchRoot, Class<T> clazz, Selector matcher, List<T> elements, int searchFlags) { Assert.isLegal(searchRoot != null); if (searchFlags == 0) { return; } // are *we* a match ? boolean classMatch = clazz == null ? true : clazz.isInstance(searchRoot); if (classMatch && matcher.select(searchRoot)) { if (!elements.contains(searchRoot)) { @SuppressWarnings("unchecked") T element = (T) searchRoot; elements.add(element); } } if (searchRoot instanceof MApplication && (searchFlags == ANYWHERE)) { MApplication app = (MApplication) searchRoot; List<MApplicationElement> children = new ArrayList<>(); if (clazz != null) { if (clazz.equals(MHandler.class)) { children.addAll(app.getHandlers()); } else if (clazz.equals(MCommand.class)) { children.addAll(app.getCommands()); } else if (clazz.equals(MBindingContext.class)) { children.addAll(app.getBindingContexts()); } else if (clazz.equals(MBindingTable.class) || clazz.equals(MKeyBinding.class)) { children.addAll(app.getBindingTables()); } // } else { only look for these if specifically asked. // children.addAll(app.getHandlers()); // children.addAll(app.getCommands()); // children.addAll(app.getBindingContexts()); // children.addAll(app.getBindingTables()); } for (MApplicationElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MBindingContext && (searchFlags == ANYWHERE)) { MBindingContext bindingContext = (MBindingContext) searchRoot; for (MBindingContext child : bindingContext.getChildren()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MBindingTable) { MBindingTable bindingTable = (MBindingTable) searchRoot; for (MKeyBinding child : bindingTable.getBindings()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } // Check regular containers if (searchRoot instanceof MElementContainer<?>) { /* * Bug 455281: If given a window with a primary perspective stack, * and we're not told to look outside of the perspectives (i.e., * searchFlags is missing OUTSIDE_PERSPECTIVE), then just search the * primary perspective stack instead. This ignores special areas * like the compat layer's stack holding the Help, CheatSheets, and * Intro. */ MElementContainer<?> searchContainer = (MElementContainer<?>) searchRoot; MPerspectiveStack primaryStack = null; if (searchRoot instanceof MWindow && (searchFlags & OUTSIDE_PERSPECTIVE) == 0 && (primaryStack = getPrimaryPerspectiveStack((MWindow) searchRoot)) != null) { searchContainer = primaryStack; } if (searchContainer instanceof MPerspectiveStack) { if ((searchFlags & IN_ANY_PERSPECTIVE) != 0) { // Search *all* the perspectives MElementContainer<? extends MUIElement> container = searchContainer; List<? extends MUIElement> children = container.getChildren(); for (MUIElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } else if ((searchFlags & IN_ACTIVE_PERSPECTIVE) != 0) { // Only search the currently active perspective, if any MPerspective active = ((MPerspectiveStack) searchContainer).getSelectedElement(); if (active != null) { findElementsRecursive(active, clazz, matcher, elements, searchFlags); } } else if ((searchFlags & IN_SHARED_AREA) != 0) { // Only recurse through the shared areas List<MArea> areas = findElements(searchContainer, null, MArea.class, null); for (MArea area : areas) { findElementsRecursive(area, clazz, matcher, elements, searchFlags); } } } else { @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) searchRoot; List<MUIElement> children = container.getChildren(); for (MUIElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } // Search Trim if (searchRoot instanceof MTrimmedWindow && (searchFlags & IN_TRIM) != 0) { MTrimmedWindow tw = (MTrimmedWindow) searchRoot; List<MTrimBar> bars = tw.getTrimBars(); for (MTrimBar bar : bars) { findElementsRecursive(bar, clazz, matcher, elements, searchFlags); } } // Search Detached Windows if (searchRoot instanceof MWindow) { MWindow window = (MWindow) searchRoot; for (MWindow dw : window.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } MMenu menu = window.getMainMenu(); if (menu != null && (searchFlags & IN_MAIN_MENU) != 0) { findElementsRecursive(menu, clazz, matcher, elements, searchFlags); } // Check for Handlers if (searchFlags == ANYWHERE && MHandler.class.equals(clazz)) { for (MHandler child : window.getHandlers()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } if (searchRoot instanceof MPerspective) { MPerspective persp = (MPerspective) searchRoot; for (MWindow dw : persp.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } } // Search shared elements if (searchRoot instanceof MPlaceholder) { MPlaceholder ph = (MPlaceholder) searchRoot; // Don't search in shared areas unless the flag is set if (ph.getRef() != null && (!(ph.getRef() instanceof MArea) || (searchFlags & IN_SHARED_AREA) != 0)) { findElementsRecursive(ph.getRef(), clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MPart && (searchFlags & IN_PART) != 0) { MPart part = (MPart) searchRoot; for (MMenu menu : part.getMenus()) { findElementsRecursive(menu, clazz, matcher, elements, searchFlags); } MToolBar toolBar = part.getToolbar(); if (toolBar != null) { findElementsRecursive(toolBar, clazz, matcher, elements, searchFlags); } if (MHandler.class.equals(clazz)) { for (MHandler child : part.getHandlers()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } }