public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MHandledMenuItem) || !(parent instanceof Menu)) return null; MHandledMenuItem itemModel = (MHandledMenuItem) element; if (itemModel.getVisibleWhen() != null) { processVisible(itemModel); } if (!itemModel.isVisible()) { return null; } // determine the index at which we should create the new item int addIndex = calcVisibleIndex(element); // OK, it's a real menu item, what kind? int flags = 0; if (itemModel.getType() == ItemType.PUSH) flags = SWT.PUSH; else if (itemModel.getType() == ItemType.CHECK) flags = SWT.CHECK; else if (itemModel.getType() == ItemType.RADIO) flags = SWT.RADIO; ParameterizedCommand cmd = itemModel.getWbCommand(); if (cmd == null) { IEclipseContext lclContext = getContext(itemModel); cmd = generateParameterizedCommand(itemModel, lclContext); } MenuItem newItem = new MenuItem((Menu) parent, flags, addIndex); setItemText(itemModel, newItem); setEnabled(itemModel, newItem); newItem.setImage(getImage(itemModel)); newItem.setSelection(itemModel.isSelected()); return newItem; }
private void addResetItem(final Menu menu) { final MenuItem resetMenuItem = new MenuItem(menu, SWT.Activate); resetMenuItem.setText(WorkbenchMessages.PerspectiveBar_reset); final IWorkbenchWindow workbenchWindow = window.getContext().get(IWorkbenchWindow.class); workbenchWindow .getWorkbench() .getHelpSystem() .setHelp(resetMenuItem, IWorkbenchHelpContextIds.RESET_PERSPECTIVE_ACTION); resetMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (psTB.isDisposed()) return; IHandlerService handlerService = (IHandlerService) workbenchWindow.getService(IHandlerService.class); IStatus status = Status.OK_STATUS; try { handlerService.executeCommand( IWorkbenchCommandConstants.WINDOW_RESET_PERSPECTIVE, null); } catch (ExecutionException e) { status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e); } catch (NotDefinedException e) { status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e); } catch (NotEnabledException e) { status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e); } catch (NotHandledException e) { } if (!status.isOK()) StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG); } }); }
/** @see ContributionItem#fill(Menu, int) */ @Override public void fill(final Menu menu, int index) { RecentProjectsService rfs = (RecentProjectsService) PlatformUI.getWorkbench().getService(RecentProjectsService.class); RecentProjectsService.Entry[] entries = rfs.getRecentFiles(); if (entries == null || entries.length == 0) { return; } // add separator new MenuItem(menu, SWT.SEPARATOR, index); int i = entries.length; for (RecentProjectsService.Entry entry : entries) { String file = entry.getFile(); MenuItem mi = new MenuItem(menu, SWT.PUSH, index); String filename = FilenameUtils.getName(file); String shortened = shorten(file, MAX_LENGTH, filename.length()); String nr = String.valueOf(i); if (i <= 9) { // add mnemonic for the first 9 items nr = "&" + nr; // $NON-NLS-1$ } mi.setText(nr + " " + shortened); // $NON-NLS-1$ mi.setData(file); mi.addSelectionListener(new MenuItemSelectionListener(new File(file))); --i; } }
/* (non-Javadoc) * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu, int) */ public void fill(Menu parent, int index) { if (menuItem == null || menuItem.isDisposed()) { if (index >= 0) { menuItem = new MenuItem(parent, SWT.CASCADE, index); } else { menuItem = new MenuItem(parent, SWT.CASCADE); } String text = getMenuText(); if (text != null) { menuItem.setText(text); } if (image != null) { LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources()); menuItem.setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } if (!menuExist()) { menu = new Menu(parent); menu.setData(MANAGER_KEY, this); } menuItem.setMenu(menu); initializeMenu(); setDirty(true); } }
/* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.ui.dialogs.AbstractArraySelectionDialog#updateEnablement(org.eclipse.jface.viewers.TableViewer) */ @Override protected void updateEnablement(TableViewer viewer) { if (viewer.getTable().getSelectionCount() == 0) { viewer.getTable().setSelection(0); } Entry entry = getSelectedEntry(); // Adjust the OK button enablement Button okButton = getButton(IDialogConstants.OK_ID); SWTControlUtil.setEnabled( okButton, entry != null && entry.delegate.validate(entry.peerNode, entry.data)); if (menuExecute != null) { menuExecute.setEnabled(entry != null && entry.delegate.validate(entry.peerNode, entry.data)); } // Adjust the edit button enablement Button editButton = getButton(EDIT_ID); SWTControlUtil.setEnabled(editButton, entry != null); if (menuEdit != null) { menuEdit.setEnabled(entry != null); } // Adjust the copy button enablement Button copyButton = getButton(COPY_ID); SWTControlUtil.setEnabled(copyButton, entry != null); if (menuCopy != null) { menuCopy.setEnabled(entry != null); } if (menuRemove != null) { menuRemove.setEnabled(entry != null); } }
private void updateIcons() { if (this.widget instanceof MenuItem) { final MenuItem item = (MenuItem) this.widget; final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); try { item.setImage(this.icon == null ? null : m.createImage(this.icon)); } catch (final DeviceResourceException e) { this.icon = ImageDescriptor.getMissingImageDescriptor(); item.setImage(m.createImage(this.icon)); // as we replaced the failed icon, log the message once. StatusManager.getManager() .handle( new Status( IStatus.ERROR, SharedUIResources.PLUGIN_ID, "Failed to load image", e)); //$NON-NLS-1$ } disposeOldImages(); this.localResourceManager = m; } else if (this.widget instanceof ToolItem) { final ToolItem item = (ToolItem) this.widget; final LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); item.setDisabledImage(this.disabledIcon == null ? null : m.createImage(this.disabledIcon)); item.setHotImage(this.hoverIcon == null ? null : m.createImage(this.hoverIcon)); item.setImage(this.icon == null ? null : m.createImage(this.icon)); disposeOldImages(); this.localResourceManager = m; } }
@Override public void fill(final Menu parent, final int index) { if (this.widget != null || parent == null) { return; } // Menus don't support the pulldown style int tmpStyle = this.style; if (tmpStyle == STYLE_PULLDOWN) { tmpStyle = STYLE_PUSH; } MenuItem item = null; if (index >= 0) { item = new MenuItem(parent, tmpStyle, index); } else { item = new MenuItem(parent, tmpStyle); } item.setData(this); if (this.workbenchHelpSystem != null) { this.workbenchHelpSystem.setHelp(item, this.helpContextId); } item.addListener(SWT.Dispose, getItemListener()); item.addListener(SWT.Selection, getItemListener()); this.widget = item; update(null); updateIcons(); }
/** * Creates the menu item for the editor descriptor. * * @param menu the menu to add the item to * @param descriptor the editor descriptor, or null for the system editor * @param preferredEditor the descriptor of the preferred editor, or <code>null</code> */ private MenuItem createMenuItem( Menu menu, final IEditorDescriptor descriptor, final IEditorDescriptor preferredEditor) { // XXX: Would be better to use bold here, but SWT does not support it. final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); boolean isPreferred = preferredEditor != null && descriptor.getId().equals(preferredEditor.getId()); menuItem.setSelection(isPreferred); menuItem.setText(descriptor.getLabel()); Image image = getImage(descriptor); if (image != null) { menuItem.setImage(image); } Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: if (menuItem.getSelection()) { openEditor(descriptor, false); } break; } } }; menuItem.addListener(SWT.Selection, listener); return menuItem; }
private boolean isTopLevelMenu() { if (menu != null && !menu.isDisposed() && menuItem != null && !menuItem.isDisposed()) { Menu parentMenu = menuItem.getParent(); return parentMenu != null && ((parentMenu.getStyle() & SWT.BAR) == SWT.BAR); } return false; }
public void fill(Menu menu, int index) { if (getParent() instanceof MenuManager) { ((MenuManager) getParent()).addMenuListener(menuListener); } if (!dirty) { return; } if (currentManager != null && currentManager.getSize() > 0) { IMenuService service = (IMenuService) locator.getService(IMenuService.class); service.releaseContributions(currentManager); currentManager.removeAll(); } currentManager = new MenuManager(); fillMenu(currentManager); IContributionItem[] items = currentManager.getItems(); if (items.length == 0) { MenuItem item = new MenuItem(menu, SWT.NONE, index++); item.setText(NO_TARGETS_MSG); item.setEnabled(false); } else { for (int i = 0; i < items.length; i++) { if (items[i].isVisible()) { items[i].fill(menu, index++); } } } dirty = false; }
@Override public Menu getMenu(Control parent) { if (menu != null) { menu.dispose(); } Menu newMenu = new Menu(parent); List<String> preferenceConfigurations = PrologRuntimeUIPlugin.getDefault().getPreferenceConfigurations(); String defaultConfiguration = PrologRuntimeUIPlugin.getDefault() .getPreferenceStore() .getString(PrologRuntimeUI.PREF_CONFIGURATION); for (String preferenceConfiguration : preferenceConfigurations) { MenuItem item = new MenuItem(newMenu, SWT.NONE); item.setText(preferenceConfiguration.replaceAll("&", "&&")); if (preferenceConfiguration.equals(defaultConfiguration)) { item.setImage(ImageRepository.getImage(ImageRepository.NEW_PROCESS)); } final String configuration = preferenceConfiguration; item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { askForNameAndCreateProcess(configuration); } }); } menu = newMenu; return menu; }
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; }
/** * Creates the Other... menu item * * @param menu the menu to add the item to */ private void createOtherMenuItem(final Menu menu) { final IFileRevision fileResource = getFileRevision(); if (fileResource == null) { return; } new MenuItem(menu, SWT.SEPARATOR); final MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_Other); Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: EditorSelectionDialog dialog = new EditorSelectionDialog(menu.getShell()); dialog.setMessage( NLS.bind( TeamUIMessages.LocalHistoryPage_OpenWithMenu_OtherDialogDescription, fileResource.getName())); if (dialog.open() == Window.OK) { IEditorDescriptor editor = dialog.getSelectedEditor(); if (editor != null) { openEditor(editor, editor.isOpenExternal()); } } break; } } }; menuItem.addListener(SWT.Selection, listener); }
// only used at the constructor private void addMenuOptions() { final MenuItem addElementMenuItem = new MenuItem(this, SWT.NONE); addElementMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { TreeItem[] selected = tree.getSelection(); TreeItem item; if (selected.length > 0) { TreeItem parent = selected[0].getParentItem(); System.out.println("Insert Before - " + selected[0].getText()); if (parent == null) { int index = tree.indexOf(selected[0]); item = setml.createNode(tree, index + 1); } else { int index = parent.indexOf(selected[0]); item = setml.createNode_state(parent, index + 1); } } else { System.out.println("Insert Before - nothing selected. Insert at beggining"); item = setml.createNode(tree, 0); } item.setText("abv"); } }); addElementMenuItem.setText("Add New"); }
protected void populateSubMenus( Menu subMenu, final Object node, ITreeContentProvider provider, final boolean isRunTo) { if (provider.hasChildren(node)) { /* * this is a submenu mark */ MenuItem header = new MenuItem(subMenu, SWT.CASCADE); header.setText(node.toString()); Menu newSubMenu = new Menu(header); header.setMenu(newSubMenu); for (Object child : provider.getChildren(node)) populateSubMenus(newSubMenu, child, provider, isRunTo); } else { /** lone item, this is a runner. */ ITimeBasedAction action = new TimeBasedAction(this, node, isRunTo); action.setText( String.format("%s %s", isRunTo ? "Skip to " : "Run for ", _labelProvider.getText(node))); _allActions.add(action); ActionContributionItem aci = new ActionContributionItem(action); aci.fill(subMenu, -1); } }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, * int) */ public void fill(Menu parent, int index) { if (command == null) { return; } if (widget != null || parent == null) { return; } // Menus don't support the pulldown style int tmpStyle = style; if (tmpStyle == STYLE_PULLDOWN) tmpStyle = STYLE_PUSH; MenuItem item = null; if (index >= 0) { item = new MenuItem(parent, tmpStyle, index); } else { item = new MenuItem(parent, tmpStyle); } item.setData(this); item.addListener(SWT.Dispose, getItemListener()); item.addListener(SWT.Selection, getItemListener()); widget = item; update(null); }
public void testCreateMenu() { final MWindow window = createWindowWithOneViewAndMenu(); wb = new E4Workbench(window, appContext); Widget topWidget = (Widget) window.getWidget(); assertTrue(topWidget instanceof Shell); Shell shell = (Shell) topWidget; final Menu menuBar = shell.getMenuBar(); assertNotNull(menuBar); assertEquals(1, menuBar.getItemCount()); final MenuItem fileItem = menuBar.getItem(0); assertEquals("File", fileItem.getText()); final Menu fileMenu = fileItem.getMenu(); fileMenu.notifyListeners(SWT.Show, null); assertEquals(2, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); MMenu mainMenu = window.getMainMenu(); MMenu modelFileMenu = (MMenu) mainMenu.getChildren().get(0); final MMenuItem item2Model = (MMenuItem) modelFileMenu.getChildren().get(0); item2Model.setToBeRendered(false); fileMenu.notifyListeners(SWT.Show, null); assertEquals(1, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); item2Model.setToBeRendered(true); fileMenu.notifyListeners(SWT.Show, null); assertEquals(2, fileMenu.getItemCount()); fileMenu.notifyListeners(SWT.Hide, null); }
public MenuItem getPurchaseOrderMenu() { if (purchaseOrderMenu == null) { purchaseOrderMenu = new MenuItem(this, SWT.CASCADE); purchaseOrderMenu.setText("&po manager"); purchaseOrderMenu.setMenu(getPurchaseOrder()); } return purchaseOrderMenu; }
/** * @param menu the containing menu * @param menuItemId * @return the menu item with {@code menuItemId} or null if not found */ private MenuItem findMenuItemById(Menu menu, int menuItemId) { for (MenuItem mi : menu.getItems()) { if (mi.getID() == menuItemId) { return mi; } } return null; }
public MenuItem getHelpMenu() { if (helpMenu == null) { helpMenu = new MenuItem(this, SWT.CASCADE); helpMenu.setText("&help"); helpMenu.setMenu(getHelp()); } return helpMenu; }
public MenuItem getReportsMenu() { if (reportsMenu == null) { reportsMenu = new MenuItem(this, SWT.CASCADE); reportsMenu.setText("&reports"); reportsMenu.setMenu(getReports()); } return reportsMenu; }
void createMenuBar() { org.eclipse.swt.widgets.Menu bar = new org.eclipse.swt.widgets.Menu(shell, SWT.BAR); shell.setMenuBar(bar); org.eclipse.swt.widgets.MenuItem fileItem = new org.eclipse.swt.widgets.MenuItem(bar, SWT.CASCADE); fileItem.setText(resources.getString("File_menuitem")); fileItem.setMenu(createFileMenu()); }
public MenuItem getCatalogsMenu() { if (catalogsMenu == null) { catalogsMenu = new MenuItem(this, SWT.CASCADE); catalogsMenu.setText("&catalogs"); catalogsMenu.setMenu(getCatalogs()); } return catalogsMenu; }
@Override public void widgetSelected(SelectionEvent e) { clipSelection(); int selectionLen = Math.abs(e.y - e.x); cutItem.setEnabled(!readOnly && selectionLen > 0); copyItem.setEnabled(selectionLen > 0); pasteItem.setEnabled(!readOnly); }
private static Menu createMenu(final Menu parentMenu, final String label, String imagePath) { MenuItem newElementMenuIten = new MenuItem(parentMenu, SWT.CASCADE); newElementMenuIten.setImage(ImageProvider.createImage(imagePath)); newElementMenuIten.setText(I18N.i18n(label)); Menu newElementMenu = new Menu(parentMenu); newElementMenuIten.setMenu(newElementMenu); return newElementMenu; }
@Override public void dispose() { endCharCaret.dispose(); cutItem.dispose(); copyItem.dispose(); pasteItem.dispose(); selectAllItem.dispose(); contextMenu.dispose(); }
@Test public void testModelMenuTextSetAfterViewerSetContentsEqualsText() { createWazaabiMenu(false); org.eclipse.swt.widgets.MenuItem swtItem = (org.eclipse.swt.widgets.MenuItem) SWTUtils.getWidget(viewer, subMenu); Assert.assertEquals(SUB_TEXT, swtItem.getText()); }
private void testPreserveControlProperties(Scale scale) { // bound Rectangle rectangle = new Rectangle(10, 10, 10, 10); scale.setBounds(rectangle); Fixture.preserveWidgets(); IWidgetAdapter adapter = WidgetUtil.getAdapter(scale); assertEquals(rectangle, adapter.getPreserved(Props.BOUNDS)); Fixture.clearPreserved(); // enabled Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(Boolean.TRUE, adapter.getPreserved(Props.ENABLED)); Fixture.clearPreserved(); scale.setEnabled(false); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(Boolean.FALSE, adapter.getPreserved(Props.ENABLED)); Fixture.clearPreserved(); scale.setEnabled(true); // visible Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(Boolean.TRUE, adapter.getPreserved(Props.VISIBLE)); Fixture.clearPreserved(); scale.setVisible(false); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(Boolean.FALSE, adapter.getPreserved(Props.VISIBLE)); Fixture.clearPreserved(); // menu Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(null, adapter.getPreserved(Props.MENU)); Fixture.clearPreserved(); Menu menu = new Menu(scale); MenuItem item = new MenuItem(menu, SWT.NONE); item.setText("1 Item"); scale.setMenu(menu); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(menu, adapter.getPreserved(Props.MENU)); Fixture.clearPreserved(); // foreground background font Color background = Graphics.getColor(122, 33, 203); scale.setBackground(background); Color foreground = Graphics.getColor(211, 178, 211); scale.setForeground(foreground); Font font = Graphics.getFont("font", 12, SWT.BOLD); scale.setFont(font); Fixture.preserveWidgets(); adapter = WidgetUtil.getAdapter(scale); assertEquals(background, adapter.getPreserved(Props.BACKGROUND)); assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND)); assertEquals(font, adapter.getPreserved(Props.FONT)); Fixture.clearPreserved(); }
void releaseChildren_pp(boolean destroy) { MenuItem[] items = getItems(); for (int i = 0; i < items.length; i++) { MenuItem item = items[i]; if (item != null && !item.isDisposed()) { item.release(false); } } super.releaseChildren_pp(destroy); }
// restarts maze and window buttons (after win) private void restart() { shell.removeKeyListener(keyListener); shell.removeMouseWheelListener(mouseWheelListener); generateMenuItem.setEnabled(true); loadMenuItem.setEnabled(true); loadRemoteMenuItem.setEnabled(true); saveMenuItem.setEnabled(false); solveMenuItem.setEnabled(false); }