org.eclipse.swt.widgets.Menu Java Examples

The following examples show how to use org.eclipse.swt.widgets.Menu. 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: MenuManager.java    From pmTrans with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: GuiMenuWidgets.java    From hop with Apache License 2.0 6 votes vote down vote up
public void createMenuWidgets( String root, Shell shell, Menu parent ) {
  // Find the GUI Elements for the given class...
  //
  GuiRegistry registry = GuiRegistry.getInstance();

  // Loop over the GUI elements and create menus all the way down...
  // We used the same ID for root and top level menu
  //
  List<GuiMenuItem> guiMenuItems = registry.findChildGuiMenuItems( root, root );
  if ( guiMenuItems.isEmpty()) {
    System.err.println( "Create menu widgets: no GUI menu items found for root: " + root);
    return;
  }

  // Sort by ID to get a stable UI
  //
  Collections.sort(guiMenuItems);

  for (GuiMenuItem guiMenuItem : guiMenuItems) {
    addMenuWidgets( root, shell, parent, guiMenuItem );
  }
}
 
Example #3
Source File: ProtocolEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example #4
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider createColumnGroupMenuItemProvider() {
	return new IMenuItemProvider() {

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

			columnStyleEditor.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new OpenCreateColumnGroupDialog(natTable.getShell()));
				}
			});
		}
	};
}
 
Example #5
Source File: ConnectionPopupMenuExtension.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object extension )
  throws KettleException {
  Menu popupMenu = null;

  Tree selectionTree = (Tree) extension;
  TreeSelection[] objects = spoonSupplier.get().getTreeObjects( selectionTree );
  TreeSelection object = objects[ 0 ];
  Object selection = object.getSelection();

  if ( selection == VFSConnectionDetails.class ) {
    popupMenu = createRootPopupMenu( selectionTree );
  } else if ( selection instanceof ConnectionTreeItem ) {
    vfsConnectionTreeItem = (ConnectionTreeItem) selection;
    popupMenu = createItemPopupMenu( selectionTree );
  }

  if ( popupMenu != null ) {
    ConstUI.displayMenu( popupMenu, selectionTree );
  } else {
    selectionTree.setMenu( null );
  }
}
 
Example #6
Source File: MainMenu.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param shell
 * @param controller
 * @param items
 */
public MainMenu(final Shell shell, final Controller controller, final List<MainMenuItem> items) {
    super(controller);

    // Create Menu
    this.menu = new Menu(shell, SWT.BAR);
    
    // Create items
    this.createItems(menu, items);

    // Set menu bar
    shell.setMenuBar(this.menu);
    
    // Enhance experience on OSX
    SWTUtil.fixOSXMenu(controller);
    
    // Initialize
    this.update(new ModelEvent(this, ModelPart.MODEL, null));
}
 
Example #7
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider renameColumnMenuItemProvider(final String label) {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
			menuItem.setText(label);
			menuItem.setEnabled(true);

			menuItem.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent event) {
					natTable.doCommand(new DisplayColumnRenameDialogCommand(natTable, getNatEventData(event).getColumnPosition()));
				}
			});
		}
	};
}
 
Example #8
Source File: AbstractPictureControl.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create the menu with "Delete", "Modify" Item.
 *
 * @param parent
 * @return
 */
protected Menu createMenu(Control parent) {
	Menu menu = new Menu(parent);

	// "Delete" menu item.
	deleteItem = new MenuItem(menu, SWT.NONE);
	deleteItem.setText(resources.getString(PICTURE_CONTROL_DELETE));
	deleteItem.addListener(SWT.Selection, e -> {
		// Delete the image.
		AbstractPictureControl.this.handleDeleteImage();
	});

	// "Modify" menu item.
	final MenuItem modifyItem = new MenuItem(menu, SWT.NONE);
	modifyItem.setText(resources.getString(PICTURE_CONTROL_MODIFY));
	modifyItem.addListener(SWT.Selection, e -> {
		// Modify the image.
		AbstractPictureControl.this.handleModifyImage();
	});
	return menu;
}
 
Example #9
Source File: LaunchConfigurationContent.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu() {
  MenuManager menuMgr = new MenuManager("#PopupMenu");
  menuMgr.setRemoveAllWhenShown(true);
  menuMgr.addMenuListener(new IMenuListener() {
    @Override
    public void menuAboutToShow(IMenuManager manager) {
      populateBrowserActions(launchConfiguration, manager);
      manager.add(new Separator());

      manager.add(new Action("&Copy") {
        @Override
        public void run() {
          copySelectionToClipboard();
        }
      });
    }
  });
  Menu menu = menuMgr.createContextMenu(viewer.getControl());
  viewer.getControl().setMenu(menu);
}
 
Example #10
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 #11
Source File: StartSessionWithProjects.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a menu entry which shares projects with the given Contacts. */
private MenuItem createProjectMenuItem(
    final Menu parentMenu, final int index, final IProject project, final List<JID> contacts) {

  final MenuItem menuItem = new MenuItem(parentMenu, SWT.NONE, index);

  menuItem.setText(workbenchLabelProvider.getText(project));
  menuItem.setImage(workbenchLabelProvider.getImage(project));

  menuItem.addSelectionListener(
      new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
          CollaborationUtils.startSession(
              Collections.<IResource>singletonList(project), contacts);
        }
      });

  return menuItem;
}
 
Example #12
Source File: EmbeddedEditorActions.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void initialize() {
	createFocusAndDisposeListeners();

	createActions();

	// create context menu
	MenuManager manager = new MenuManager(null, null);
	manager.setRemoveAllWhenShown(true);
	manager.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager mgr) {
			fillContextMenu(mgr);
		}
	});

	StyledText text = viewer.getTextWidget();
	Menu menu = manager.createContextMenu(text);
	text.setMenu(menu);
	
	List<ActionActivationCode> activationCodes = Lists.newArrayList();
	setActionActivationCode(activationCodes, ITextEditorActionConstants.SHIFT_RIGHT_TAB,'\t', -1, SWT.NONE);
	setActionActivationCode(activationCodes, ITextEditorActionConstants.SHIFT_LEFT, '\t', -1, SWT.SHIFT);
	viewer.getTextWidget().addVerifyKeyListener(new ActivationCodeTrigger(allActions, activationCodes));
}
 
Example #13
Source File: SWTUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the shell for the given widget. If the widget doesn't represent a SWT object that manage a shell,
 * <code>null</code> is returned.
 * 
 * @return the shell for the given widget
 */
public static Shell getShell(Widget widget)
{
	if (widget instanceof Control)
		return ((Control) widget).getShell();
	if (widget instanceof Caret)
		return ((Caret) widget).getParent().getShell();
	if (widget instanceof DragSource)
		return ((DragSource) widget).getControl().getShell();
	if (widget instanceof DropTarget)
		return ((DropTarget) widget).getControl().getShell();
	if (widget instanceof Menu)
		return ((Menu) widget).getParent().getShell();
	if (widget instanceof ScrollBar)
		return ((ScrollBar) widget).getParent().getShell();

	return null;
}
 
Example #14
Source File: RunConfigurationPopupMenuExtension.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object extension )
  throws KettleException {
  Menu popupMenu = null;

  Tree selectionTree = (Tree) extension;
  TreeSelection[] objects = spoonSupplier.get().getTreeObjects( selectionTree );
  TreeSelection object = objects[ 0 ];
  Object selection = object.getSelection();

  if ( selection == RunConfiguration.class ) {
    popupMenu = createRootPopupMenu( selectionTree );
  } else if ( selection instanceof String ) {
    runConfiguration = (String) selection;
    if ( runConfiguration.equalsIgnoreCase( DefaultRunConfigurationProvider.DEFAULT_CONFIG_NAME ) ) {
      return;
    }
    popupMenu = createItemPopupMenu( selectionTree );
  }

  if ( popupMenu != null ) {
    ConstUI.displayMenu( popupMenu, selectionTree );
  } else {
    selectionTree.setMenu( null );
  }
}
 
Example #15
Source File: AbstractMenuContributionItem.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("restriction")
protected MenuItem createMenu(Menu parent, String command, Optional<Image> image) {
    MenuItem item = new MenuItem(parent, SWT.NONE);
    ParameterizedCommand parameterizedCommand = createParametrizedCommand(command);
    try {
        item.setText(parameterizedCommand.getName());
    } catch (NotDefinedException e) {
        BonitaStudioLog.error(
                String.format("The command '%s' doesn't have any name defined.", parameterizedCommand.getId()), e);
        item.setText(parameterizedCommand.getId());
    }
    item.addListener(SWT.Selection, e -> {
        if (eHandlerService.canExecute(parameterizedCommand)) {
            eHandlerService.executeHandler(parameterizedCommand);
        } else {
            throw new RuntimeException(String.format("Can't execute command %s", parameterizedCommand.getId()));
        }
    });
    item.setEnabled(true);
    appendShortcut(parameterizedCommand, item);
    image.ifPresent(item::setImage);
    return item;
}
 
Example #16
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
private void hookContextMenu() {
	MenuManager menuMgr = new MenuManager("#PopupMenu");
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager manager) {
			IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
			if(s.getFirstElement() instanceof DocumentImpl) {
				fillContextMenu(manager);
			}
		}
	});
	Menu menu = menuMgr.createContextMenu(viewer.getControl());
	viewer.getControl().setMenu(menu);
	getSite().registerContextMenu(menuMgr, viewer);
}
 
Example #17
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider clearToggleFilterRowMenuItemProvider(final String menuLabel) {
	return new IMenuItemProvider() {

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

			menuItem.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new ToggleFilterRowCommand());
				}
			});
		}
	};
}
 
Example #18
Source File: OutputsMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void outputSubMenu(final Menu main, final IScope scope, final IOutputManager manager,
		final IDisplayOutput output) {
	final MenuItem item = new MenuItem(main, SWT.CASCADE);
	item.setText(output.getOriginalName());
	final Menu sub = new Menu(item);
	item.setMenu(sub);
	if (output.isOpen()) {
		// menuItem(sub, e -> output.close(), null, "Close");
		if (output.isPaused())
			menuItem(sub, e -> output.setPaused(false), null, "Resume");
		else
			menuItem(sub, e -> output.setPaused(true), null, "Pause");
		menuItem(sub, e -> output.update(), null, "Refresh");
		if (output.isSynchronized())
			menuItem(sub, e -> output.setSynchronized(false), null, "Unsynchronize");
		else
			menuItem(sub, e -> output.setSynchronized(true), null, "Synchronize");
	} else
		menuItem(sub, e -> manager.open(scope, output), null, "Reopen");

}
 
Example #19
Source File: StartSessionWithProjects.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void fill(final Menu menu, final int index) {
  final List<JID> contacts =
      SelectionRetrieverFactory.getSelectionRetriever(JID.class).getSelection();

  final IProject[] projects = getSortedWorkspaceProjects();

  if (projects.length == 0) {
    createNoProjectsMenuItem(menu, 0);
    return;
  }

  int idx;

  for (idx = 0; idx < projects.length; idx++)
    createProjectMenuItem(menu, idx, projects[idx], contacts);

  if (idx > 1) {
    new MenuItem(menu, SWT.SEPARATOR, idx++);
    createMultipleProjectMenuItem(menu, idx);
  }
}
 
Example #20
Source File: NatTableWrapper.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public void addContextMenu(String string, IWorkbenchPartSite iWorkbenchPartSite){
	
	MenuManager mgr = new MenuManager();
	Menu popupmenu = new PopupMenuBuilder(natTable, mgr).build();
	iWorkbenchPartSite.registerContextMenu(string, mgr, null);
	
	natTable.addConfiguration(new AbstractUiBindingConfiguration() {
		
		@Override
		public void configureUiBindings(UiBindingRegistry uiBindingRegistry){
			uiBindingRegistry.registerMouseDownBinding(
				new MouseEventMatcher(SWT.NONE, null, MouseEventMatcher.RIGHT_BUTTON),
				new PopupMenuAction(popupmenu));
		}
	});
}
 
Example #21
Source File: SWTUtil.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the shell for the given widget. If the widget doesn't represent
 * a SWT object that manage a shell, <code>null</code> is returned.
 * @param widget the widget
 *
 * @return the shell for the given widget
 */
public static Shell getShell(Widget widget) {
    if (widget instanceof Control) {
        return ((Control) widget).getShell();
    }
    if (widget instanceof Caret) {
        return ((Caret) widget).getParent().getShell();
    }
    if (widget instanceof DragSource) {
        return ((DragSource) widget).getControl().getShell();
    }
    if (widget instanceof DropTarget) {
        return ((DropTarget) widget).getControl().getShell();
    }
    if (widget instanceof Menu) {
        return ((Menu) widget).getParent().getShell();
    }
    if (widget instanceof ScrollBar) {
        return ((ScrollBar) widget).getParent().getShell();
    }

    return null;
}
 
Example #22
Source File: SwitchThemesPulldownContributionItem.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void fill(Menu menu, int index)
{
	IThemeManager manager = ThemePlugin.getDefault().getThemeManager();
	List<String> themeNames = new ArrayList<String>(manager.getThemeNames());
	// sort ignoring case
	Collections.sort(themeNames, new Comparator<String>()
	{
		public int compare(String o1, String o2)
		{
			return o1.compareToIgnoreCase(o2);
		}
	});
	for (String name : themeNames)
	{
		IContributionItem item = new SwitchThemeContributionItem(manager, name);
		item.fill(menu, menu.getItemCount());
	}
}
 
Example #23
Source File: VisualInterfaceEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void createContextMenuFor ( StructuredViewer viewer )
{
    MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) );
}
 
Example #24
Source File: DateChooser.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the header of the calendar. The header contains the label
 * displaying the current month and year, and the two buttons for navigation :
 * previous and next month.
 */
private void createHeader() {
	monthPanel = new Composite(this, SWT.NONE);
	GridLayoutFactory.fillDefaults().numColumns(3).spacing(HEADER_SPACING, 0).margins(HEADER_SPACING, 2).applyTo(monthPanel);
	GridDataFactory.fillDefaults().applyTo(monthPanel);
	monthPanel.addListener(SWT.MouseDown, listener);

	prevMonth = new Button(monthPanel, SWT.ARROW | SWT.LEFT | SWT.FLAT);
	prevMonth.addListener(SWT.MouseUp, listener);
	prevMonth.addListener(SWT.FocusIn, listener);

	currentMonth = new Label(monthPanel, SWT.CENTER);
	currentMonth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	currentMonth.addListener(SWT.MouseDown, listener);

	nextMonth = new Button(monthPanel, SWT.ARROW | SWT.RIGHT | SWT.FLAT);
	nextMonth.addListener(SWT.MouseUp, listener);
	nextMonth.addListener(SWT.FocusIn, listener);

	monthsMenu = new Menu(getShell(), SWT.POP_UP);
	currentMonth.setMenu(monthsMenu);
	for (int i = 0; i < 12; i++) {
		final MenuItem item = new MenuItem(monthsMenu, SWT.PUSH);
		item.addListener(SWT.Selection, listener);
		item.setData(new Integer(i));
	}
	monthsMenu.addListener(SWT.Show, listener);
}
 
Example #25
Source File: XtextStyledTextCellEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initContextMenu(Control control) {
	MenuManager menuManager = createMenuManager();
	Menu contextMenu = menuManager.createContextMenu(control);
	control.setMenu(contextMenu);
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider());
}
 
Example #26
Source File: OutlinePage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected void configureContextMenu() {
	MenuManager menuManager = new MenuManager(CONTEXT_MENU_ID, CONTEXT_MENU_ID);
	menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	menuManager.setRemoveAllWhenShown(true);
	
	Menu contextMenu = menuManager.createContextMenu(getTreeViewer().getTree());
	getTreeViewer().getTree().setMenu(contextMenu);
	getSite().registerContextMenu(MENU_ID, menuManager, getTreeViewer());
}
 
Example #27
Source File: PeersView.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
	
	if ( addPeersMenu( manager, columnName, menuThisColumn )){

		new MenuItem( menuThisColumn, SWT.SEPARATOR );
	}
}
 
Example #28
Source File: ContextActionUiTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the context menu item identified by the given labels.
 * When a context menu 'Compile' exists with the sub context menu 'All Invalids',
 * then the context menu 'All Invalids' is returned when giving the labels 'Compile' and 'All Invalids'.
 *
 * @param bot
 *          the {@link AbstractSWTBot} on which to infer the context menu
 * @param labels
 *          the labels on the context menus
 * @return the context menu item, {@code null} if the context menu item could not be found
 */
private static MenuItem getContextMenuItem(final AbstractSWTBot<? extends Control> bot, final String... labels) {
  return UIThreadRunnable.syncExec(new WidgetResult<MenuItem>() {
    @Override
    public MenuItem run() {
      MenuItem menuItem = null;
      Control control = bot.widget;

      // MenuDetectEvent
      Event event = new Event();
      control.notifyListeners(SWT.MenuDetect, event);
      if (event.doit) {
        Menu menu = control.getMenu();
        for (String text : labels) {
          Matcher<?> matcher = allOf(instanceOf(MenuItem.class), withMnemonic(text));
          menuItem = show(menu, matcher);
          if (menuItem != null) {
            menu = menuItem.getMenu();
          } else {
            hide(menu);
            break;
          }
        }
        return menuItem;
      } else {
        return null;
      }
    }
  });
}
 
Example #29
Source File: DataViewTreeViewerPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the context menu
 */
private void createContextMenus( )
{
	MenuManager menuManager = new ViewContextMenuProvider( getTreeViewer( ) );

	Menu menu = menuManager.createContextMenu( getTreeViewer( ).getControl( ) );

	getTreeViewer( ).getControl( ).setMenu( menu );
	getSite( ).registerContextMenu( "#Pop up", menuManager, //$NON-NLS-1$
			getSite( ).getSelectionProvider( ) );
}
 
Example #30
Source File: BlacklistedPeersPart.java    From offspring with MIT License 5 votes vote down vote up
@PostConstruct
public void postConstruct(Composite parent, INxtService nxt) {
  peerTableViewer = new PeerTableViewer(parent, nxt,
      PeerTable.TYPE_BLACKLISTED_PEERS);

  Menu contextMenu = new Menu(peerTableViewer.getTable());
  peerTableViewer.getTable().setMenu(contextMenu);

  MenuItem itemReply = new MenuItem(contextMenu, SWT.PUSH);
  itemReply.setText("Unblacklist");
  itemReply.addSelectionListener(new SelectionAdapter() {

    @Override
    public void widgetSelected(SelectionEvent e) {
      IStructuredSelection selection = (IStructuredSelection) peerTableViewer
          .getSelection();

      Iterator iter = selection.iterator();
      while (iter != null && iter.hasNext()) {
        Object element = iter.next();
        if (element instanceof Peer) {
          Peer peer = (Peer) element;
          peer.unBlacklist();
        }
      }
      peerTableViewer.refresh();
    }
  });
}