public static boolean processAddition( final MMenu menuModel, final ArrayList<MMenuElement> menuContributionsToRemove, MMenuContribution menuContribution, final HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames) { int idx = getIndex(menuModel, menuContribution.getPositionInParent()); if (idx == -1) { return false; } for (MMenuElement item : menuContribution.getChildren()) { if (item instanceof MMenu && existingMenuIds.contains(item.getElementId())) { // skip this, it's already there continue; } else if (item instanceof MMenuSeparator && existingSeparatorNames.contains(item.getElementId())) { // skip this, it's already there continue; } MMenuElement copy = (MMenuElement) EcoreUtil.copy((EObject) item); if (DEBUG) { trace("addMenuContribution " + copy, menuModel.getWidget(), menuModel); // $NON-NLS-1$ } menuContributionsToRemove.add(copy); menuModel.getChildren().add(idx++, copy); if (copy instanceof MMenu && copy.getElementId() != null) { existingMenuIds.add(copy.getElementId()); } else if (copy instanceof MMenuSeparator && copy.getElementId() != null) { existingSeparatorNames.add(copy.getElementId()); } } return true; }
private void showStandaloneViewMenu( ExecutionEvent event, MPart model, MMenu menuModel, Composite partContainer) { Shell shell = partContainer.getShell(); Menu menu = (Menu) menuModel.getWidget(); if (menu == null) { IPresentationEngine engine = (IPresentationEngine) HandlerUtil.getVariable(event, IPresentationEngine.class.getName()); menu = (Menu) engine.createGui(menuModel, shell, model.getContext()); if (menu != null) { final Menu tmpMenu = menu; partContainer.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { tmpMenu.dispose(); } }); } } Display display = menu.getDisplay(); Point location = display.map(partContainer, null, partContainer.getLocation()); Point size = partContainer.getSize(); menu.setLocation(location.x + size.x, location.y); menu.setVisible(true); while (!menu.isDisposed() && menu.isVisible()) { if (!display.readAndDispatch()) display.sleep(); } if (!(menu.getData() instanceof MenuManager)) { menu.dispose(); } }