private void buildContextMenu(MouseEvent e) { Point point = new Point(e.x, e.y); TreeItem treeItem = getTree().getItem(point); Menu menu = new Menu((Control)e.getSource()); Iterator<MenuMaker> i = menuMakers.iterator(); int cpt = 0; while(i.hasNext()) { i.next().makeMenu(this, treeItem, e, menu); if (i.hasNext() && menu.getItemCount() != cpt) { new MenuItem(menu, SWT.SEPARATOR); cpt = menu.getItemCount(); } } if (menu.getItemCount() > 0) { menu.setVisible(true); } else { menu.dispose(); } }
/** * Construct the DropDownSelectionListener with the specific menu to be used. */ public DropDownSelectionListener(Menu menu) { this.menu = menu; MenuItem[] menuItems = menu.getItems(); for (int i=0; i<menuItems.length; i++) { /* * Add a menu selection listener so that the menu is hidden * when the user selects an item from the drop down menu. */ menuItems[i].addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setMenuVisible(false); } }); } }
private SWTBotShell showPreferenceDialogMAC() { final IWorkbench workbench = PlatformUI.getWorkbench(); workbench.getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { Menu appMenu = workbench.getDisplay().getSystemMenu(); for (MenuItem item : appMenu.getItems()) { if (item.getText().startsWith("Preferences")) { Event event = new Event(); event.time = (int) System.currentTimeMillis(); event.widget = item; event.display = workbench.getDisplay(); item.setSelection(true); item.notifyListeners(SWT.Selection, event); break; } } } } }); return getPreferenceDialog() ; }
public static void addCopyToClipMenu( final Menu menu, final String text ) { MenuItem item = new MenuItem( menu,SWT.NONE ); String msg_text_id= "label.copy.to.clipboard"; item.setText( MessageText.getString( msg_text_id )); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent arg0) { new Clipboard(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()}); } }); }
protected void openPopupMenu(NodeType[] availableTypes, final AvroNode targetNode, final AvroContext context) { Shell shell = Display.getCurrent().getActiveShell(); final Menu menu = new Menu(shell, SWT.POP_UP); for (NodeType availableType : availableTypes) { final NodeType type = availableType; MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText(type.getDisplayLabel()); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { menu.dispose(); IEditCommand cmd = context.getService(IEditCommandFactory.class) .createAddElementCommand(targetNode, type, getNotifications()); context.getService(ICommandExecutor.class).execute(cmd); } }); } Point location = MouseInfo.getPointerInfo().getLocation(); int x = location.x; int y = location.y; menu.setLocation(x, y); menu.setVisible(true); }
public void widgetSelected(SelectionEvent event) { System.out.println("You selected " + ((MenuItem) event.widget).getText()); System.out.println("You selected cont.1 " + EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText())); // System.out.println("You selected cont.2 " + EnumUtils.indexOf(EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText()))); //Storage.getInstance().getTranscriptMetadata().setStatus(EnumUtils.fromString(EditStatus.class, ((MenuItem) event.widget).getText())); // Storage.getInstance().saveTranscript(Storage.getInstance().getCurrentDocumentCollectionId(), null); // Storage.getInstance().setLatestTranscriptAsCurrent(); /* * change status: */ String tmp = ((MenuItem) event.widget).getText(); changeVersionStatus(tmp); gallery.redraw(); gallery.deselectAll(); }
private Menu createNewWorkItemMenu(final Shell shell, final TeamExplorerContext context) { final WorkItemClient client = context.getServer().getConnection().getWorkItemClient(); final Project project = client.getProjects().get(context.getCurrentProjectInfo().getName()); final Menu menu = new Menu(shell, SWT.POP_UP); for (final WorkItemType workItemType : project.getVisibleWorkItemTypes()) { final MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(workItemType.getName()); menuItem.setData(workItemType); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { final WorkItem workItem = client.newWorkItem(workItemType); WorkItemEditorHelper.openEditor(context.getServer(), workItem); } }); } return menu; }
protected Menu getSubActionMenu(final Control parent) { if (subActionMenu != null) { return subActionMenu; } subActionMenu = new Menu(parent); for (final Iterator<IAction> it = subActions.iterator(); it.hasNext();) { final IAction subAction = it.next(); final ActionContributionItem aci = new ActionContributionItem(subAction); aci.fill(subActionMenu, -1); final MenuItem menuItem = subActionMenu.getItem(subActionMenu.getItemCount() - 1); menuItem.addSelectionListener(menuItemSelectionListener); } return subActionMenu; }
/** * Clicks on the {@link MenuItem}. * * @param menuItem * the {@link MenuItem} to click on */ private static void click(final MenuItem menuItem) { final Event event = new Event(); event.time = (int) System.currentTimeMillis(); event.widget = menuItem; event.display = menuItem.getDisplay(); event.type = SWT.Selection; UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() { @Override public void run() { if (SWTUtils.hasStyle(menuItem, SWT.CHECK) || SWTUtils.hasStyle(menuItem, SWT.RADIO)) { menuItem.setSelection(!menuItem.getSelection()); } menuItem.notifyListeners(SWT.Selection, event); } }); }
@Override public void fill(Menu menu, int index) { final IProject project = getSelectedProject(); final boolean exists = AddBuilder.hasBuilder(project); MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index); menuItem.setText((exists ? "Remove" : "Add") + " Layered Builder"); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { G.reset(); if (exists) { RemoveBuilder.removeBuilder(project); } else { AddBuilder.addBuilder(project); } Activator.getDefault().getAnalysis().removeWarnings(1000); } }); }
private void createMenuItem(Menu parent, final TableColumn column) { final MenuItem itemName = new MenuItem(parent, SWT.CHECK); itemName.setText(column.getText()); itemName.setSelection(column.getResizable()); itemName.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (itemName.getSelection()) { column.setWidth(150); column.setResizable(true); } else { column.setWidth(0); column.setResizable(false); } } }); }
public void updateTypes(){ MenuItem[] items = this.newCollection.getItems(); for(int i = 0;i < items.length; i ++){ items[i].dispose(); } Iterator<TGBrowserFactory> bookTypes = TGBrowserManager.getInstance(getBrowser().getContext()).getFactories(); while(bookTypes.hasNext()){ final TGBrowserFactory bookType = (TGBrowserFactory)bookTypes.next(); MenuItem item = new MenuItem(this.newCollection,SWT.PUSH); item.setText(bookType.getName()); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { newCollection( bookType.getType()); } }); } }
public void createMenu(TGToolBar toolBar, ToolItem item) { Rectangle rect = item.getBounds(); Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y)); Menu menu = new Menu(item.getParent().getShell()); TGCustomChordManager customChordManager = TuxGuitar.getInstance().getCustomChordManager(); for(int i = 0; i < customChordManager.countChords(); i++){ TGChord chord = TuxGuitar.getInstance().getCustomChordManager().getChord(i); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(chord.getName()); menuItem.addSelectionListener(this.createInsertChordAction(toolBar, chord)); } menu.setLocation(pt.x, pt.y + rect.height); menu.setVisible(true); }
private void createMenuItem(Menu menu, BookmarkId selectedBookmarkId, BookmarkNumber bookmarkNumber) { Optional<BookmarkId> bookmarkId = numberedBookmarks.getBookmark(bookmarkNumber); final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); menuItem.setSelection(bookmarkId.isPresent() ? bookmarkId.get().equals(selectedBookmarkId) : false); menuItem.setText(getText(bookmarkId)); menuItem.setAccelerator('0' + bookmarkNumber.getNumber()); Image image = getImage(bookmarkNumber, bookmarkId); if (image != null) { menuItem.setImage(image); } Listener listener = new Listener() { @Override public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: if (menuItem.getSelection()) { bookmarksService.addNumberedBookmark(selectedBookmarkId, bookmarkNumber); } break; } } }; menuItem.addListener(SWT.Selection, listener); }
private MenuItem addMenuItem(Menu menu, String text, int accelerator, Object data, SelectionListener listener) { MenuItem item = new MenuItem(menu, SWT.NONE); item.setText(text); item.addSelectionListener(listener); if (accelerator != SWT.NONE) item.setAccelerator(accelerator); item.setData(data); return item; }
private void createRecentAudiosMenu() { for (MenuItem mi : recentAudiosM.getItems()) mi.dispose(); CacheList<File> audioFilesCache = pmTrans.getRecentAudios(); for (int i = 0; i < audioFilesCache.size(); i++) addMenuItem(recentAudiosM, audioFilesCache.get(i).getName(), SWT.NONE, audioFilesCache.get(i), new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { pmTrans.openAudioFile((File) ((MenuItem) e .getSource()).getData()); } }); }
private void createRecentTextsMenu() { for (MenuItem mi : recentTextsM.getItems()) mi.dispose(); CacheList<File> textFilesCache = pmTrans.getRecentTrasncriptions(); for (int i = 0; i < textFilesCache.size(); i++) addMenuItem(recentTextsM, textFilesCache.get(i).getName(), SWT.NONE, textFilesCache.get(i), new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { pmTrans.openTranscriptionFile((File) ((MenuItem) e .getSource()).getData()); } }); }
private MenuItem addConfigurableMenuItem(Menu menu, final String orgText, final String acceleratorKey, SelectionListener listener) { char accelerator = Config.getInstance().getString(acceleratorKey) .toUpperCase().charAt(0); int acc = SWT.MOD1 + (accelerator == ' ' ? SWT.SPACE : accelerator); String text = orgText + " \t Ctrl+" + (accelerator == ' ' ? "[space]" : accelerator); final MenuItem item = addMenuItem(menu, text, acc, listener); Config.getInstance().addPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { if (arg0.getProperty().equals(acceleratorKey)) updateAccelerator(item, orgText, Config .getInstance().getString(acceleratorKey) .toUpperCase().charAt(0)); } }); return item; }
private MenuItem addMenuItem(Menu menu, String text, SelectionListener listener) { MenuItem item = new MenuItem(menu, SWT.NONE); item.setText(text); item.addSelectionListener(listener); return item; }
private MenuItem addMenuItem(Menu menu, String text, int accelerator, SelectionListener listener) { MenuItem item = addMenuItem(menu, text, listener); if (accelerator != SWT.NONE) item.setAccelerator(accelerator); return item; }
private MenuItem addMenuItem(Menu menu, String text, int accelerator, SelectionListener listener, Image icon) { MenuItem item = addMenuItem(menu, text, accelerator, listener); item.setImage(icon); return item; }
private void updateAccelerator(MenuItem item, String itemText, char newAccelerator) { itemText += " \t Ctrl+" + (newAccelerator == ' ' ? "[space]" : newAccelerator); int acc = SWT.MOD1 + (newAccelerator == ' ' ? SWT.SPACE : newAccelerator); item.setText(itemText); item.setAccelerator(acc); }
@Override public void fill ( final org.eclipse.swt.widgets.Menu menu, final int index ) { final MenuItem item = new MenuItem ( menu, SWT.NONE, index ); final Profile profile = getProfile (); final String name = this.definition.getName () == null ? "<unnamed>" : this.definition.getName (); String profileName = profile != null ? profile.getName () : "default"; if ( profileName == null ) { profileName = "<unnamed>"; } item.setText ( String.format ( "Run %s (%s)", name, profileName ) ); item.addSelectionListener ( new SelectionAdapter () { @Override public void widgetSelected ( final SelectionEvent evt ) { try { run ( name ); } catch ( final Exception e ) { logger.warn ( "Failed to run", e ); StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK ); } } } ); }
private void dialogBuild(ToolItem buildModeItem, MenuItem menuItem) { MobileBuilderBuildMode newBuildMode = (MobileBuilderBuildMode) menuItem.getData(); if (dialogBuild(newBuildMode)) { buildModeItem.setImage(menuItem.getImage()); buildModeItem.setToolTipText("Rebuild in: " + buildMode.label() + "\n" + buildMode.description()); try { JSONObject device = new JSONObject(FileUtils.readFileToString(devicePref, "UTF-8")); device.put("buildMode", buildMode.name()); FileUtils.write(devicePref, device.toString(4), "UTF-8"); } catch (Exception ex) { Engine.logStudio.debug("Cannot save build mode", ex); } } }
@Override public void fill(Menu menu, int index) { final MenuItem menuItem = new MenuItem(menu, SWT.NONE, index); menuItem.setText("Convert existing JPF Projects to new format"); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { run(); } }); }
public void asyncPrint(final List<MenuItem> list) { UIThreadRunnable.asyncExec(bot.getDisplay(), new VoidResult() { public void run() { for (MenuItem menuItem : list) { System.out.println(menuItem.getText()); } } }); }
@Override public void fill(Menu menu, int index) { super.fill(menu, index); int i = index; // FIXME y this works on Sirius editor? try { String filePath = ""; IFile selectedFile = AlloyParseUtil.getSelectedFile(); if (selectedFile == null) { editor = Activator.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); editor.doSave(new NullProgressMonitor()); filePath = ((FileEditorInput) editor.getEditorInput()).getPath().toOSString(); } else { filePath = selectedFile.getRawLocation().toOSString(); } alloyExecuter.parse(filePath); final ConstList<Command> allCommands = alloyExecuter.getRunCommands(); if (allCommands.size() > 0) { for (final Command com : allCommands) { final MenuItem menuItem = new MenuItem(menu, SWT.PUSH, i++); menuItem.setText(com.toString()); menuItem.setData("command", com); menuItem.addSelectionListener(this); } } } catch (Exception e) { // e.printStackTrace(); return; } }
@Override public void fillMenu( String sColumnName, Menu menu ) { fillMenu( menu, tv, shell, null ); new MenuItem (menu, SWT.SEPARATOR); }
@Override public void addThisColumnSubMenu( String sColumnName, Menu menuThisColumn) { if ( addPeersMenu( null, sColumnName, menuThisColumn )){ new MenuItem( menuThisColumn, SWT.SEPARATOR ); } }
/** * <p> * Sets the keyboard accelerator for a SWT MenuItem. * </p> * <p> * There is a specific order of accelerator setting in consideration with different platforms and localizations. Specifically:<br /> * <ol> * <li>If a localized keybinding value exists for the current locale and platform, it is used</li> * <li>If the above is not found, this method looks for a keybinding value for the current locale without platform specificity</li> * <li>If the above is not found, this method looks for a keybinding value for the default locale and the currently running platform</li> * <li>If the above is not found, this method looks for a keybinding value for the default locale without platform specificity</li> * <li>If the above is not found, no accelerator is set for the MenuItem</li> * </ol> * </p> * @param menu SWT MenuItem * @param localizationKey The MenuItem's localization key for the localization resource bundle */ public static void setAccelerator(final MenuItem menu, String localizationKey) { localizationKey += ".keybinding"; final String platformSpecificKey = localizationKey + getPlatformKeySuffix(); // first, check for platform-specific, localization-specific binding if(MessageText.keyExists(platformSpecificKey)) { setAccelerator(menu, parseKeyBinding(MessageText.getString(platformSpecificKey))); } else if(MessageText.keyExists(localizationKey)) // platform-independent, localization-specific binding { setAccelerator(menu, parseKeyBinding(MessageText.getString(localizationKey))); } else if(!MessageText.isCurrentLocale(MessageText.LOCALE_DEFAULT)) { // default locale // platform-specific first if(MessageText.keyExistsForDefaultLocale(platformSpecificKey)) { setAccelerator(menu, parseKeyBinding(MessageText.getDefaultLocaleString(platformSpecificKey))); } else if(MessageText.keyExistsForDefaultLocale(localizationKey)) { // default locale, platform-independent setAccelerator(menu, parseKeyBinding(MessageText.getDefaultLocaleString(localizationKey))); } } }
/** * Helper method to set a keyboard accelerator for a MenuItem. If kbInfo is SWT.NONE, no accelerator will be set. * @param menu SWT MenuItem * @param kbInfo KeyBindingInfo object, which contains the SWT accelerator value and its display name */ private static void setAccelerator(final MenuItem menu, final KeyBindingInfo kbInfo) { if ( menu.isDisposed()){ return; } if(kbInfo.accelerator != SWT.NONE) { menu.setAccelerator(kbInfo.accelerator); // SWT on OS X now uses native drawing if(!Constants.isOSX && !menu.getText().endsWith(kbInfo.name)) menu.setText(menu.getText() + kbInfo.name); } }
@Override protected void addMenuItems( Menu menu ) { new MenuItem( menu, SWT.SEPARATOR ); MenuItem mi_reset = new MenuItem( menu, SWT.PUSH ); mi_reset.setText( MessageText.getString( "label.clear.history" )); mi_reset.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { try{ this_mon.enter(); nbValues = 0; currentPosition = 0; for ( int i=0;i<all_values.length;i++ ){ all_values[i] = new int[all_values[i].length]; } }finally{ this_mon.exit(); } refresh( true ); } }); }
protected void openPopupMenu(List<DragAndDropPolicy.Action> availableActions, final AvroNode sourceNode, final AvroNode targetNode, final TargetPosition position) { Shell shell = Display.getCurrent().getActiveShell(); final Menu menu = new Menu(shell, SWT.POP_UP); for (DragAndDropPolicy.Action availableAction : availableActions) { final DragAndDropPolicy.Action action = availableAction; MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText(action.getLabel()); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { menu.dispose(); IEditCommand cmd = context.getService(IEditCommandFactory.class) .createDnDElementCommand(action, sourceNode, targetNode, position, Notifications.NOT_REF); if (cmd != null) { context.getService(ICommandExecutor.class).execute(cmd); } } }); } java.awt.Point location = MouseInfo.getPointerInfo().getLocation(); int x = location.x; int y = location.y; menu.setLocation(x, y); menu.setVisible(true); }
/** * Shows the provided {@link Menu} and returns the {@link MenuItem} matching the given {@link Matcher} criteria. * * @param menu * the {@link Menu} to show * @param matcher * the {@link Matcher} to use to find the {@link MenuItem} * @return * the {@link MenuItem} matching the given {@link Matcher} criteria */ private static MenuItem show(final Menu menu, final Matcher<?> matcher) { if (menu != null) { menu.notifyListeners(SWT.Show, new Event()); MenuItem item = null; final long start = System.currentTimeMillis(); while ((item = getMenuItem(menu, matcher)) != null) { if (ICE_CTX_LABEL_LOADING.equals(item.getText())) { try { while (Display.getDefault().readAndDispatch()) { // Allow Lazy Loading items to modify the menu } Thread.sleep(SWTBotPreferences.PLAYBACK_DELAY); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } } else { return item; } if (System.currentTimeMillis() - start > SWTBotPreferences.TIMEOUT) { return null; } } menu.notifyListeners(SWT.Hide, new Event()); return item; } return null; }
public Swt_popup_itm(Menu menu, int swt_type) { this.menu = menu; itm = new MenuItem(menu, swt_type); switch (swt_type) { case SWT.CASCADE: this.tid = Gfui_mnu_itm_.Tid_grp; break; case SWT.CHECK: this.tid = Gfui_mnu_itm_.Tid_chk; break; case SWT.RADIO: this.tid = Gfui_mnu_itm_.Tid_rdo; break; default: throw Err_.new_unhandled(swt_type); } }
public void setDefaultToolItem(final MenuItem menuItem) { Check.notNull(menuItem, "menuItem"); //$NON-NLS-1$ toolItem.setImage(menuItem.getImage()); if (menuItem.getData(TOOLTIP_TEXT_WIDGET_DATA_KEY) != null) { toolItem.setToolTipText((String) menuItem.getData(TOOLTIP_TEXT_WIDGET_DATA_KEY)); } else { toolItem.setToolTipText(""); //$NON-NLS-1$ } // Remember this menu item for future invocations lastSelectedMenuItem = menuItem; }