Java Code Examples for org.eclipse.swt.widgets.Menu#getItems()
The following examples show how to use
org.eclipse.swt.widgets.Menu#getItems() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropDownSelectionListener.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
/** * 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); } }); } }
Example 2
Source File: MenuBuildUtils.java From BiglyBT with GNU General Public License v2.0 | 6 votes |
/** * Adds a separator if the current last item isn't one already * @param menu */ public static void addSeparater( Menu menu ) { if ( menu.isDisposed() || menu.getItemCount() == 0 ){ return; } org.eclipse.swt.widgets.MenuItem[] items = menu.getItems(); if ( items[items.length-1].getStyle() != SWT.SEPARATOR ){ new org.eclipse.swt.widgets.MenuItem( menu, SWT.SEPARATOR ); } }
Example 3
Source File: SWTUtil.java From arx with Apache License 2.0 | 6 votes |
/** * Fixes the application menu on OSX. * @param controller */ public static void fixOSXMenu(final Controller controller) { // Check if we are on mac if (!isMac()) { return; } // Just disable all items in the system menu // TODO: Something like this could help: // https://stackoverflow.com/questions/32409679/capture-about-preferences-and-quit-menu-items // However, I had trouble unregistering the existing events for the items Menu systemMenu = Display.getCurrent().getSystemMenu(); for (MenuItem systemItem : systemMenu.getItems()) { systemItem.setEnabled(false); } }
Example 4
Source File: MainMenu.java From arx with Apache License 2.0 | 6 votes |
/** * Updates the menu * @param menu * @param model */ private void update(Menu menu, Model model) { // Check if (menu == null) return; // For each item for (final MenuItem item : menu.getItems()) { // Check group if (item.getData() instanceof MainMenuGroup) { MainMenuGroup group = (MainMenuGroup) item.getData(); item.setEnabled(group.isEnabled(model)); update(item.getMenu(), model); // Check item } else { MainMenuItem mItem = (MainMenuItem) item.getData(); item.setEnabled(mItem == null || mItem.isEnabled(model)); } } }
Example 5
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
public static void addCopyToClipMenu( final Menu menu, final String text ) { for ( MenuItem e: menu.getItems()){ if ( e.getData( MENU_ITEM_KEY ) != null ){ e.dispose(); } } MenuItem item = new MenuItem( menu,SWT.NONE ); item.setData( MENU_ITEM_KEY, "" ); 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()}); } }); }
Example 6
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
public static void addCopyToClipMenu( final Menu menu, final copyToClipProvider provider ) { for ( MenuItem e: menu.getItems()){ if ( e.getData( MENU_ITEM_KEY ) != null ){ e.dispose(); } } MenuItem item = new MenuItem( menu,SWT.NONE ); item.setData( MENU_ITEM_KEY, "" ); 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[] { provider.getText()}, new Transfer[] {TextTransfer.getInstance()}); } }); }
Example 7
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
public static void removeCopyToClipMenu( final Menu menu ) { for ( MenuItem e: menu.getItems()){ if ( e.getData( MENU_ITEM_KEY ) != null ){ e.dispose(); } } }
Example 8
Source File: ContextActionUiTestUtil.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Returns the menu item for the given matcher, or the lazy loading menu item if it is available. * * @param menu * the menu * @param matcher * the matcher * @return the menu item or {@code null} if none found */ private static MenuItem getMenuItem(final Menu menu, final Matcher<?> matcher) { final MenuItem[] items = menu.getItems(); for (final MenuItem menuItem : items) { if (matcher.matches(menuItem)) { return menuItem; } else if (ICE_CTX_LABEL_LOADING.equals(menuItem.getText())) { return menuItem; } } return null; }
Example 9
Source File: TLAEditor.java From tlaplus with MIT License | 5 votes |
private void removeMenuItemWithDisplayText(final String text, final Menu menu) { final MenuItem[] items = menu.getItems(); for (final MenuItem item : items) { final String menuItemText = item.getText(); if ((menuItemText != null) && menuItemText.startsWith(text)) { item.dispose(); return; } } }
Example 10
Source File: AnalysisToolComposite.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * Removes and disposes of all of the IAnalysisViews for a particular * DataSource. * * @param dataSource * The DataSource whose Views need to be removed. * @param factory * The factory used to generate the IAnalysisViews for the * DataSource. */ private void removeViews(DataSource dataSource, IAnalysisWidgetFactory factory) { logger.info("AnalysisToolComposite message: " + "Removing views for data source " + dataSource); // Get the list of available views. List<String> viewNames = factory.getAvailableViews(dataSource); // Disable the dataSource's view menu Item. (The dataSource // should *always* be a key in the map.) MenuItem dataSourceItem = dataSourceItems.get(dataSource); dataSourceItem.setEnabled(false); // Dispose of all MenuItems from the dataSource's view Menu. Menu dataSourceMenu = dataSourceItem.getMenu(); for (MenuItem item : dataSourceMenu.getItems()) { item.dispose(); } // Dispose of the ViewPart for each view. for (String viewName : viewNames) { logger.info( "AnalysisToolComposite message: Removing view " + viewName); ViewPart viewPart = viewPartMap.remove(dataSource + "-" + viewName); if (viewPart != null) { viewPart.dispose(); } } return; }
Example 11
Source File: Leistungscodes.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * enable or disable the items in the toolbar and in the popupmenu * * @param listDisplayToBeChanged */ private void enableDisableItems(){ ToolBar toolBar = (ToolBar) listDisplay.getData("toolbar"); //$NON-NLS-1$ org.eclipse.swt.widgets.List list = getListPart(listDisplay); Menu menu = list.getMenu(); boolean menuHasItems = menu.getItems().length > 0; int selIx = list.getSelectionIndex(); int maxIx = list.getItemCount(); // *** move up item boolean enabled = false; if (selIx > 0) enabled = true; toolBar.getItem(MOVEITEMUP).setEnabled(enabled); if (menuHasItems) menu.getItem(MOVEITEMUP).setEnabled(enabled); // *** move down item enabled = false; if (selIx < (maxIx - 1)) enabled = true; if (selIx == -1) enabled = false; toolBar.getItem(MOVEITEMDOWN).setEnabled(enabled); if (menuHasItems) menu.getItem(MOVEITEMDOWN).setEnabled(enabled); // *** delete and edit item enabled = true; if (selIx == -1) enabled = false; toolBar.getItem(DELETEITEM).setEnabled(enabled); toolBar.getItem(EDITITEM).setEnabled(enabled); if (menuHasItems) menu.getItem(DELETEITEM).setEnabled(enabled); if (menuHasItems) menu.getItem(EDITITEM).setEnabled(enabled); }