Java Code Examples for org.eclipse.swt.events.MenuEvent

The following examples show how to use org.eclipse.swt.events.MenuEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: typescript.java   Source File: RefactorActionGroup.java    License: MIT License 6 votes vote down vote up
private void refactorMenuShown(IMenuManager refactorSubmenu) {
	// we know that we have an MenuManager since we created it in
	// addRefactorSubmenu.
	Menu menu = ((MenuManager) refactorSubmenu).getMenu();
	menu.addMenuListener(new MenuAdapter() {
		@Override
		public void menuHidden(MenuEvent e) {
			refactorMenuHidden();
		}
	});
	ITextSelection textSelection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
	// JavaTextSelection javaSelection= new
	// JavaTextSelection(getEditorInput(), getDocument(),
	// textSelection.getOffset(), textSelection.getLength());

	for (Iterator<SelectionDispatchAction> iter = fActions.iterator(); iter.hasNext();) {
		SelectionDispatchAction action = iter.next();
		action.update(textSelection);
	}
	refactorSubmenu.removeAll();
	if (fillRefactorMenu(refactorSubmenu) == 0)
		refactorSubmenu.add(fNoActionAvailable);
}
 
Example 2
private void refactorMenuShown(IMenuManager refactorSubmenu) {
	// we know that we have an MenuManager since we created it in
	// addRefactorSubmenu.
	Menu menu= ((MenuManager)refactorSubmenu).getMenu();
	menu.addMenuListener(new MenuAdapter() {
		@Override
		public void menuHidden(MenuEvent e) {
			refactorMenuHidden();
		}
	});
	ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
	JavaTextSelection javaSelection= new JavaTextSelection(getEditorInput(), getDocument(), textSelection.getOffset(), textSelection.getLength());

	for (Iterator<SelectionDispatchAction> iter= fActions.iterator(); iter.hasNext(); ) {
		SelectionDispatchAction action= iter.next();
		action.update(javaSelection);
	}
	refactorSubmenu.removeAll();
	if (fillRefactorMenu(refactorSubmenu) == 0)
		refactorSubmenu.add(fNoActionAvailable);
}
 
Example 3
protected void initMenu(Menu menu) {
	menu.addMenuListener(new MenuAdapter() {
		@Override
		public void menuShown(MenuEvent e) {
			Menu m= (Menu) e.widget;
			MenuItem[] items= m.getItems();
			for (int i= 0; i < items.length; i++) {
				items[i].dispose();
			}
			fillMenu(m);
		}
	});
}
 
Example 4
protected void initMenu() {
	fMenu.addMenuListener(new MenuAdapter() {
		@Override
		public void menuShown(MenuEvent e) {
			Menu m = (Menu)e.widget;
			MenuItem[] items = m.getItems();
			for (int i=0; i < items.length; i++) {
				items[i].dispose();
			}
			fillMenu(m);
		}
	});
}
 
Example 5
Source Project: XPagesExtensionLibrary   Source File: ToolbarAction.java    License: Apache License 2.0 5 votes vote down vote up
private void initMenu(Menu fMenu) {     
    fMenu.addMenuListener(new MenuAdapter() {
        public void menuShown(MenuEvent e) {                
            Menu m = (Menu) e.widget;
            MenuItem[] items = m.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }
            fillMenu(m);                
        }
    });
}
 
Example 6
Source Project: Rel   Source File: Commands.java    License: Apache License 2.0 5 votes vote down vote up
public static void linkCommand(Do command, AcceleratedMenuItem menuItem) {
	menuDoMapping.put(command, menuItem);
	menuItem.getParent().addMenuListener(new MenuAdapter() {
		@Override
		public void menuShown(MenuEvent arg0) {
			CommandActivator activator = getCommandActivator(command);
			if (activator != null && activator.isFullyEnabled()) {
				menuItem.setEnabled(true);
				// remove old listeners
				Listener[] oldListeners = menuItem.getListeners(SWT.Selection);
				for (Listener oldListener: oldListeners)
					menuItem.removeListener(SWT.Selection, oldListener);
				// handle CHECK and RADIO menu items
				if ((menuItem.getStyle() & (SWT.CHECK | SWT.RADIO)) != 0) {
					menuItem.setSelection(activator.getSelection());
					menuItem.addListener(SWT.Selection, e -> activator.setSelection(!activator.getSelection()));
				}
				// add new listener
				menuItem.addListener(SWT.Selection, e -> activator.click());
				// acquire the CommandActivator's tooltip
				menuItem.setToolTipText(activator.getToolTipText());
			} else
				menuItem.setEnabled(false);
		}
	});
	menuItem.setEnabled(false);
}
 
Example 7
Source Project: Rel   Source File: DBrowser.java    License: Apache License 2.0 5 votes vote down vote up
private static void createFileMenu(Menu bar) {	
	MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);			
	fileItem.setText("File");
	
	Menu menu = new Menu(fileItem);
	fileItem.setMenu(menu);
	
	if (hasLocalRel()) {
		new AcceleratedMenuItem(menu, "New database\tCtrl-n", SWT.MOD1 | 'n', "NewDBIcon", e -> Core.newDatabase());
		new AcceleratedMenuItem(menu, "New database from a backup", 0, "database_restore", e -> Core.restoreDatabase());
		new AcceleratedMenuItem(menu, "Open local database\tCtrl-l", SWT.MOD1 | 'l', "OpenDBLocalIcon", e -> Core.openLocalDatabase());
	}
	new AcceleratedMenuItem(menu, "Open remote database\tCtrl-r", SWT.MOD1 | 'r', "OpenDBRemoteIcon", e-> Core.openRemoteDatabase());
	
	MenuItem recentItem = new MenuItem(menu, SWT.CASCADE);
	recentItem.setText("Recently-opened databases");
	
	menu.addMenuListener(new MenuAdapter() {
		@Override
		public void menuShown(MenuEvent arg0) {
			Menu recentDatabases = new Menu(menu);
			recentItem.setMenu(recentDatabases);				
			String[] dbURLs = Core.getRecentlyUsedDatabaseList();
			if (dbURLs.length > 0) {
				int recentlyUsedCount = 0;
				for (String dbURL: dbURLs) {
					if (dbURL.startsWith("db:") && !hasLocalRel())
						continue;
					(new AcceleratedMenuItem(recentDatabases, "Open " + dbURL, 0, "OpenDBLocalIcon", e -> Core.openDatabase(dbURL))).setEnabled(Core.databaseMayExist(dbURL));
					if (++recentlyUsedCount >= 20)	// arbitrarily decide 20 is enough
						break;
				}
				new MenuItem(recentDatabases, SWT.SEPARATOR);
				new AcceleratedMenuItem(recentDatabases, "Clear this list...", 0, null, e -> Core.clearRecentlyUsedDatabaseList());
			}
		}
	});
	
	OSSpecific.addFileMenuItems(menu);
}
 
Example 8
public void menuShown(MenuEvent e) {
	if(!this.control.isIgnoreEvents()) {
		this.menuShowListener.onMenuShow(new UIMenuEvent(this.control));
	}
}
 
Example 9
public void menuHidden(MenuEvent e) {
	if(!this.control.isIgnoreEvents()) {
		this.menuHideListener.onMenuHide(new UIMenuEvent(this.control));
	}
}
 
Example 10
Source Project: BiglyBT   Source File: MenuBuildUtils.java    License: GNU General Public License v2.0 votes vote down vote up
public void buildMenu(Menu root_menu, MenuEvent menuEvent);