/** * Add image to a widget or window * * @param parent * @param image * @throws JellyTagException */ protected void setImage(Object parent, Image image) throws GroovyException { if (parent instanceof Label) { Label label = (Label) parent; label.setImage(image); } else if (parent instanceof Button) { Button button = (Button) parent; button.setImage(image); } else if (parent instanceof Item) { Item item = (Item) parent; item.setImage(image); } else if (parent instanceof Decorations) { Decorations item = (Decorations) parent; item.setImage(image); } else if (parent instanceof Form) { Form form = (Form) parent; form.setBackgroundImage(image); } else if (parent instanceof ScrolledForm) { ScrolledForm form = (ScrolledForm) parent; form.setBackgroundImage(image); } else if (parent instanceof Window) { Window window = (Window) parent; window.getShell().setImage(image); } else { throw new GroovyException("This tag must be nested inside a <label>, <button> or <item> tag"); } }
/* * (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; }