org.eclipse.swt.widgets.MenuItem Java Examples

The following examples show how to use org.eclipse.swt.widgets.MenuItem. 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: XViewerTextWidget.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public Menu getDefaultMenu() {
   Menu menu = new Menu(sText.getShell());
   MenuItem cut = new MenuItem(menu, SWT.NONE);
   cut.setText(XViewerText.get("menu.cut")); //$NON-NLS-1$
   cut.addListener(SWT.Selection, e-> {
         sText.cut();
         sText.redraw();
   });
   MenuItem copy = new MenuItem(menu, SWT.NONE);
   copy.setText(XViewerText.get("menu.copy")); //$NON-NLS-1$
   copy.addListener(SWT.Selection, e-> sText.copy());

   MenuItem paste = new MenuItem(menu, SWT.NONE);
   paste.setText(XViewerText.get("menu.paste")); //$NON-NLS-1$
   paste.addListener(SWT.Selection, e->  {
         sText.paste();
         sText.redraw();
   });
   return menu;
}
 
Example #2
Source File: GitRepositoriesPreferencePage.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Control createContents(Composite parent) {
	final Composite fieldEditorParent = (Composite) super.createContents(parent);

	final GitRepositoryPreferencePageView view = new GitRepositoryPreferencePageView(fieldEditorParent, SWT.NONE);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(view);
	tableViewer = view.getTableViewer();
	tableViewer.setContentProvider(new ArrayContentProvider());
	view.getColumnRepository().setLabelProvider(new RepositoryColumnLabelProvider());
	view.getColumnLocalPath().setLabelProvider(new LocalPathColumnLabelProvider());
	view.getColumnMemory().setLabelProvider(new MemoryColumnLabelProvider());
	tableViewer.setInput(getGitRepositoryPaths(configuration.getGitRepositoryFolder()));

	final MenuItem item = view.getMenuItemGoToRepository();
	item.setEnabled(!tableViewer.getSelection().isEmpty());
	item.addListener(SWT.Selection, e -> openRepositoryOnSelection(tableViewer));
	tableViewer.addSelectionChangedListener(e -> item.setEnabled(!e.getSelection().isEmpty()));

	return fieldEditorParent;
}
 
Example #3
Source File: GamlReferenceMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void installSubMenuIn(final Menu menu) {
	final MenuItem builtInItem = new MenuItem(menu, SWT.CASCADE);
	builtInItem.setText(getTitle());
	builtInItem.setImage(getImage());
	mainMenu = new Menu(builtInItem);
	builtInItem.setMenu(mainMenu);
	mainMenu.addListener(SWT.Show, e -> {
		if (mainMenu.getItemCount() > 0) {
			for (final MenuItem item : mainMenu.getItems()) {
				item.dispose();
			}
		}
		fillMenu();
	});

}
 
Example #4
Source File: ContextMenuHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
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() {
          menuItem.notifyListeners(SWT.Selection, event);
        }
      });
}
 
Example #5
Source File: EncodingLabel.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void createDetectorMenuItem(final String prefValue, String label) {

		final MenuItem menuItem = new MenuItem(popupMenu, SWT.RADIO);
		menuItem.setText(format("Detector: " + label));
		menuItem.setSelection(prefValue.equals(pref(PREF_DETECTOR)));
		menuItem.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				boolean sel = ((MenuItem) e.widget).getSelection();
				if (sel && !prefValue.equals(pref(PREF_DETECTOR))) {
					Activator.getDefault().getPreferenceStore().setValue(PREF_DETECTOR, prefValue);
					agent.getDocument().refresh();
				}
			}
		});
	}
 
Example #6
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider ungroupColumnsMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
			columnStyleEditor.setText("Ungroup columns");
			columnStyleEditor.setEnabled(true);

			columnStyleEditor.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new UngroupColumnCommand());
				}
			});
		}
	};
}
 
Example #7
Source File: DeleteSpecHandlerTest.java    From tlaplus with MIT License 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
	RCPTestSetupHelper.beforeClass();
	
	// Force shell activation to counter, no active Shell when running SWTBot tests in Xvfb/Xvnc
	// see https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb
	Display.getDefault().syncExec(new Runnable() {
		public void run() {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
		}
	});
	
	bot = new SWTWorkbenchBot();

	// Wait for the Toolbox shell to be available
	final Matcher<Shell> withText = withText("TLA+ Toolbox");
	bot.waitUntil(Conditions.waitForShell(withText), 30000);
	
	// Wait for the Toolbox UI to be fully started.
	final Matcher<MenuItem> withMnemonic = WidgetMatcherFactory.withMnemonic("File");
	final Matcher<MenuItem> matcher = WidgetMatcherFactory.allOf(WidgetMatcherFactory.widgetOfType(MenuItem.class),
			withMnemonic);
	bot.waitUntil(Conditions.waitForMenu(bot.shell("TLA+ Toolbox"), matcher), 30000);
}
 
Example #8
Source File: JframeApp.java    From jframe with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
protected Menu createMenuBar() {
    Menu bar = new Menu(shell, SWT.BAR);
    // file
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText("&File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    MenuItem item = new MenuItem(submenu, SWT.PUSH);
    item.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {

        }
    });
    item.setText("Select &All\tCtrl+A");
    item.setAccelerator(SWT.MOD1 + 'A');
    // edit
    MenuItem editItem = new MenuItem(bar, SWT.CASCADE);
    editItem.setText("&Edit");
    // search
    MenuItem searchItem = new MenuItem(bar, SWT.CASCADE);
    searchItem.setText("&Search");
    return bar;
}
 
Example #9
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static MenuItem cascadingAgentMenuItem(final Menu parent, final IAgent agent, final String title,
		final MenuAction... actions) {
	final MenuItem result = new MenuItem(parent, SWT.CASCADE);
	result.setText(title);
	Image image;
	if (agent instanceof SimulationAgent) {
		final SimulationAgent sim = (SimulationAgent) agent;
		image = GamaIcons.createTempRoundColorIcon(GamaColors.get(sim.getColor()));
	} else {
		image = GamaIcons.create(IGamaIcons.MENU_AGENT).image();
	}
	result.setImage(image);
	final Menu agentMenu = new Menu(result);
	result.setMenu(agentMenu);
	createMenuForAgent(agentMenu, agent, agent instanceof ITopLevelAgent, true, actions);
	return result;
}
 
Example #10
Source File: MenuItemProviders.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider categoriesBasedColumnChooserMenuItemProvider(final String menuLabel) {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem columnChooser = new MenuItem(popupMenu, SWT.PUSH);
			columnChooser.setText(menuLabel);
			columnChooser.setImage(GUIHelper.getImage("column_categories_chooser"));
			columnChooser.setEnabled(true);

			columnChooser.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new ChooseColumnsFromCategoriesCommand(natTable));
				}
			});
		}
	};
}
 
Example #11
Source File: ExpressionCellEditor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showMenu( )
{
	if ( menu != null )
	{
		Rectangle size = button.getBounds( );
		menu.setLocation( button.toDisplay( new Point( 0, size.height - 1 ) ) );

		for ( int i = 0; i < menu.getItemCount( ); i++ )
		{
			MenuItem item = menu.getItem( i );
			if ( item.getData( ).equals( getExpressionType( ) ) )
				item.setSelection( true );
			else
				item.setSelection( false );
		}
		menu.setVisible( true );
	}
}
 
Example #12
Source File: MenuItemProviders.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider columnChooserMenuItemProvider(final String menuLabel) {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem columnChooser = new MenuItem(popupMenu, SWT.PUSH);
			columnChooser.setText(menuLabel);
			columnChooser.setImage(GUIHelper.getImage("column_chooser"));
			columnChooser.setEnabled(true);

			columnChooser.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new DisplayColumnChooserCommand(natTable));
				}
			});
		}
	};
}
 
Example #13
Source File: AnalysisToolComposite.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the current View to the first available view for the specified
 * DataSource.
 * 
 * @param dataSource
 *            The DataSource whose first available View will be displayed.
 */
public void setToFirstView(DataSource dataSource) {
	// Get the view menu's MenuItem associated with this data source.
	MenuItem dataSourceItem = dataSourceItems.get(dataSource);

	// Only proceed if the item exists.
	if (dataSourceItem != null) {

		// Get the Menu of views for this data source.
		Menu menu = dataSourceItem.getMenu();

		// Only proceed if the menu actually has items.
		if (menu.getItemCount() > 0) {

			// Get the view name of the first item.
			String viewName = menu.getItem(0).getText();

			// Set the active view.
			setActiveView(dataSource + "-" + viewName);
		}
	}

	return;
}
 
Example #14
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider autoResizeColumnMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
			autoResizeColumns.setText("Auto resize column");
			autoResizeColumns.setImage(GUIHelper.getImage("auto_resize"));
			autoResizeColumns.setEnabled(true);

			autoResizeColumns.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent event) {
					int columnPosition = getNatEventData(event).getColumnPosition();
					natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable)));
				}
			});
		}
	};
}
 
Example #15
Source File: MenuItemProviders.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider showAllColumnMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, Menu popupMenu) {
			MenuItem showAllColumns = new MenuItem(popupMenu, SWT.PUSH);
			showAllColumns.setText("Show all columns");
			showAllColumns.setImage(GUIHelper.getImage("show_column"));
			showAllColumns.setEnabled(true);

			showAllColumns.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new ShowAllColumnsCommand());
				}
			});
		}
	};
}
 
Example #16
Source File: ClassSelectionButton.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void populateMenuItems( )
{
	for ( int i = 0; i < menu.getItemCount( ); i++ )
	{
		menu.getItem( i ).dispose( );
		i--;
	}

	String[] types = this.provider.getMenuItems( );
	for ( int i = 0; i < types.length; i++ )
	{
		MenuItem item = new MenuItem( menu, SWT.PUSH );
		item.setText( provider.getMenuItemText( types[i] ) );
		item.setData( types[i] );
		item.setImage( this.provider.getMenuItemImage( types[i] ) );
		item.addSelectionListener( listener );
	}

	if ( menu.getItemCount( ) <= 0 )
	{
		button.setDropDownMenu( null );
	}

	button.setText( provider.getButtonText( ) );
	refresh( );
}
 
Example #17
Source File: ContextMenuHelper.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if the context menu item matching the text nodes is enabled.
 *
 * @param bot a SWTBot class that wraps a {@link Widget} which extends {@link Control}. E.g.
 *     {@link SWTBotTree}.
 * @param nodes the nodes of the context menu e.g New, Class
 * @return <tt>true</tt> if the context menu item is enabled, <tt>false</tt> otherwise
 * @throws WidgetNotFoundException if the widget is not found.
 */
public static boolean isContextMenuEnabled(
    final AbstractSWTBot<? extends Control> bot, final String... nodes) {

  final MenuItem menuItem = getMenuItemWithRegEx(bot, quote(nodes));
  // show
  if (menuItem == null) {
    throw new WidgetNotFoundException("could not find menu: " + Arrays.asList(nodes));
  }

  return UIThreadRunnable.syncExec(
      new BoolResult() {
        @Override
        public Boolean run() {
          boolean enabled = menuItem.isEnabled();
          hide(menuItem.getParent());
          return enabled;
        }
      });
}
 
Example #18
Source File: EncodingLabel.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void createSettingMenu() {

		createSettingMenuItem(PREF_AUTODETECT_CHANGE, "Autodetect: Set Automatically");
		createSettingMenuItem(PREF_AUTODETECT_WARN, "Autodetect: Show Warning");
		createSettingMenuItem(PREF_DISABLE_DISCOURAGED_OPERATION, "Autodetect: Disable Discouraged Operations");
		new MenuItem(popupMenu, SWT.SEPARATOR);
	}
 
Example #19
Source File: WidgetTask.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public static void setMenuName(final MenuItem item, final String text) {
	Display.getDefault().syncExec(
			new Runnable() {
				public void run() {
					item.setText(text);
				}
			}
	);
}
 
Example #20
Source File: MenuManager.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());
					}
				});
}
 
Example #21
Source File: RenameSpecHandlerTest.java    From tlaplus with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	super.setUp();
	
	// create a dummy spec "ToBeRenamedSpec"
	SWTBotMenu fileMenu = bot.menu("File");
	SWTBotMenu openSpecMenu = fileMenu.menu("Open Spec");
	SWTBotMenu addNewSpecMenu = openSpecMenu.menu("Add New Spec...");
	addNewSpecMenu.click();
	
	String path = System.getProperty("java.io.tmpdir") + File.separator + "RSHTest"
			+ System.currentTimeMillis();
	path += File.separator + TEST_SPEC + TLA_SUFFIX;

	bot.textWithLabel("Root-module file:").setText(path);
	bot.button("Finish").click();

	final String specName = getSpecName(new File(path));
	bot.waitUntil(Conditions.waitForMenu(bot.activeShell(), WithText.<MenuItem> withText(specName)));
	
	// create a new dummy model
	final SWTBotMenu modelMenu = bot.menu("TLC Model Checker");
	final SWTBotMenu newModelMenu = modelMenu.menu("New Model...");
	newModelMenu.click();
	bot.button("OK").click();
	bot.waitUntil(new ModelEditorOpenCondition(TEST_MODEL));
	
	// save and close model editor
	SWTBotEditor activeEditor = bot.activeEditor();
	activeEditor.saveAndClose();
	
	checkSpecAndModelExistenceAPI(TEST_SPEC, TEST_MODEL);
}
 
Example #22
Source File: ReviewMarkerMenuContribution.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void fill(Menu menu, int index) {
  MenuItem submenuItem = new MenuItem(menu, SWT.CASCADE, index);
  submenuItem.setText("&Appraise Review Comments");
  Menu submenu = new Menu(menu);
  submenuItem.setMenu(submenu);
  for (IMarker marker : markers) {
    MenuItem menuItem = new MenuItem(submenu, SWT.CHECK);
    menuItem.setText(marker.getAttribute(IMarker.MESSAGE, ""));
    menuItem.addSelectionListener(createDynamicSelectionListener(marker));
  }
}
 
Example #23
Source File: OutputsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void managementSubMenu(final Menu main, final IScope scope, final IOutputManager manager) {
	if (Iterables.isEmpty(manager.getDisplayOutputs()))
		return;
	final MenuItem item = new MenuItem(main, SWT.CASCADE);
	item.setText(manager.toString());
	final Menu sub = new Menu(item);
	item.setMenu(sub);
	for (final IDisplayOutput output : manager.getDisplayOutputs()) {
		outputSubMenu(sub, scope, manager, output);
	}
}
 
Example #24
Source File: ListProcessContributionItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IContributionItem createContributionItem(AbstractProcess process) {
    return new ContributionItem() {

        @Override
        public void fill(Menu menu, int index) {
            MenuItem item = new MenuItem(menu, SWT.PUSH);
            item.setText(String.format("%s (%s)", process.getName(), process.getVersion()));
            item.addListener(SWT.Selection, createSelectionListener(process));
        }
    };
}
 
Example #25
Source File: MenuManager.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #26
Source File: SeverityClassificationPulldownAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reset menu items so they are unchecked.
 *
 * @param enable
 *            true if menu items should be enabled, false if they should be
 *            disabled
 */
private void resetMenuItems(boolean enable) {
    for (int i = 0; i < severityItemList.length; ++i) {
        MenuItem menuItem = severityItemList[i];
        menuItem.setEnabled(enable);
        menuItem.setSelection(false);
    }
}
 
Example #27
Source File: ClassSelectionButton.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void widgetSelected( SelectionEvent e )
{
	Widget widget = e.widget;
	if ( widget instanceof MenuItem )
	{
		String exprType = (String) widget.getData( );
		provider.handleSelectionEvent( exprType );
		refresh( );
	}
	if ( widget instanceof MenuButton )
	{
		provider.handleSelectionEvent( ( (MenuButtonProvider) provider ).getDefaultOptionType( ) );
	}
}
 
Example #28
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 removeCopyToClipMenu(
final Menu					menu )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }	
 }
 
Example #29
Source File: PluginsMenuHelper.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
private static void
sort(
	com.biglybt.pif.ui.menus.MenuItem[] plugin_items )
{
	Arrays.sort(
		plugin_items,
		(o1, o2) -> ( alpha_comparator.compare( o1.getText(), o2.getText())));
}
 
Example #30
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
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()});
		  }
	  });
 }