public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MMenu)) return null; final MMenu menuModel = (MMenu) element; Menu newMenu = null; if (parent instanceof Decorations) { MUIElement container = (MUIElement) ((EObject) element).eContainer(); if (container instanceof MWindow) { newMenu = new Menu((Decorations) parent, SWT.BAR); newMenu.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { cleanUp(menuModel); } }); } else { newMenu = new Menu((Decorations) parent, SWT.POP_UP); } } else if (parent instanceof Menu) { int addIndex = calcVisibleIndex(menuModel); MenuItem newItem = new MenuItem((Menu) parent, SWT.CASCADE, addIndex); setItemText(menuModel, newItem); newItem.setImage(getImage(menuModel)); newItem.setEnabled(menuModel.isEnabled()); return newItem; } else if (parent instanceof Control) { newMenu = new Menu((Control) parent); } return newMenu; }
/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) */ @Override public Object createWidget(MUIElement element, Object parent) { if (!(element instanceof MMenu)) return null; 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 = 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; }