Java Code Examples for org.eclipse.jface.action.MenuManager#createContextMenu()

The following examples show how to use org.eclipse.jface.action.MenuManager#createContextMenu() . 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: ItemEditor.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 2
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
private void createPopupMenu() {
	removeHistoryItemAction = new RemoveHistoryItemAction();
	removeHistoryActionContributionItem = new ActionContributionItem(
			removeHistoryItemAction);

	contextMenuManager = new MenuManager();
	contextMenuManager.setRemoveAllWhenShown(true);
	contextMenuManager.addMenuListener(new IMenuListener() {
		
		public void menuAboutToShow(IMenuManager manager) {
			fillContextMenu(manager);
		}
	});

	final Table table = list.getTable();
	Menu menu= contextMenuManager.createContextMenu(table);
	table.setMenu(menu);
}
 
Example 3
Source File: SecurityEditor.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: IndexView.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * hookContextMenu
 */
private void hookContextMenu()
{
	MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$

	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(new IMenuListener()
	{
		public void menuAboutToShow(IMenuManager manager)
		{
			fillContextMenu(manager);
		}
	});

	// Create menu.
	Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
	treeViewer.getControl().setMenu(menu);

	// Register menu for extension.
	getSite().registerContextMenu(menuMgr, treeViewer);
}
 
Example 5
Source File: MarkerStatsView.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds the actions to the tableviewer context menu.
 *
 * @param actions
 *          a collection of IAction objets
 */
private void hookContextMenu(final Collection<Object> actions, StructuredViewer viewer) {
  MenuManager menuMgr = new MenuManager();
  menuMgr.setRemoveAllWhenShown(true);
  menuMgr.addMenuListener(new IMenuListener() {
    @Override
    public void menuAboutToShow(IMenuManager manager) {
      for (Iterator<Object> iter = actions.iterator(); iter.hasNext();) {
        Object item = iter.next();
        if (item instanceof IContributionItem) {
          manager.add((IContributionItem) item);
        } else if (item instanceof IAction) {
          manager.add((IAction) item);
        }
      }
      manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    }
  });
  Menu menu = menuMgr.createContextMenu(viewer.getControl());
  viewer.getControl().setMenu(menu);

  getSite().registerContextMenu(menuMgr, viewer);
}
 
Example 6
Source File: DeploymentEditor.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 7
Source File: ChartEditor.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 NOT
 */
protected void createContextMenuFor ( final StructuredViewer viewer )
{
    final MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$
    contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$
    contextMenu.setRemoveAllWhenShown ( true );
    contextMenu.addMenuListener ( this );
    final Menu menu = contextMenu.createContextMenu ( viewer.getControl () );
    viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) );

    final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
    final Transfer[] transfers = new Transfer[] {
            LocalTransfer.getInstance (),
            LocalSelectionTransfer.getTransfer (),
            FileTransfer.getInstance (),
            ItemTransfer.getInstance ()
    };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new DropAdapterExtension ( this.editingDomain, viewer ) );
}
 
Example 8
Source File: MonitorsViewTable.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected void hookContextMenu ( final Control control, final ISelectionProvider selectionProvider, final IViewSite viewSite )
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( control );
    control.setMenu ( menu );
    viewSite.registerContextMenu ( menuMgr, selectionProvider );
}
 
Example 9
Source File: SinkView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            SinkView.this.fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, viewer);
}
 
Example 10
Source File: EventQueryView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void hookContextMenu ()
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu", VIEW_ID );
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
    this.viewer.getControl ().setMenu ( menu );
    getSite ().registerContextMenu ( menuMgr, this.viewer );
}
 
Example 11
Source File: ChartControllerView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void hookContextMenu ( final IViewSite viewSite )
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
    this.viewer.getControl ().setMenu ( menu );
    viewSite.registerContextMenu ( menuMgr, this.viewer );
}
 
Example 12
Source File: ConstUI.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void displayMenu( XulMenupopup xulMenuPopup, Control control ) {

    MenuManager menuMgr = (MenuManager) xulMenuPopup.getManagedObject();
    Menu menu = menuMgr.createContextMenu( control );
    menuMgr.updateAll( true );
    displayMenu( menu, control );
  }
 
Example 13
Source File: RealTimeListViewer.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void hookContextMenu ( final IViewSite viewSite )
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( this.viewer.getControl () );
    this.viewer.getControl ().setMenu ( menu );
    viewSite.registerContextMenu ( menuMgr, this.viewer );
}
 
Example 14
Source File: CodeRecommendationResultsView.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void createContextMenu(Viewer viewer) {
	MenuManager contextMenu = new MenuManager("#ViewerMenu"); //$NON-NLS-1$
	contextMenu.setRemoveAllWhenShown(true);
	contextMenu.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager mgr) {
			fillContextMenu(mgr);
		}
	});

	Menu menu = contextMenu.createContextMenu(viewer.getControl());
	viewer.getControl().setMenu(menu);
}
 
Example 15
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 16
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initContextMenu(Control control) {
	MenuManager menuManager = new FilteringMenuManager();
	Menu contextMenu = menuManager.createContextMenu(control);
	control.setMenu(contextMenu);
	IWorkbenchPartSite site = editorPart.getSite();
	if (site != null)
		site.registerContextMenu("org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapterContextMenu",
				menuManager, site.getSelectionProvider());
}
 
Example 17
Source File: JUnitStatusContributionItem.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private void attachContextMenu( Control control ) {
  MenuManager menuManager = new MenuManager();
  menuManager.add( new ActivateJUnitViewOnFailureAction() );
  menuManager.add( new Separator() );
  menuManager.add( new CloseJUnitStatusAction( getWorkbenchWindow().getWorkbench() ) );
  Menu contextMenu = menuManager.createContextMenu( control );
  control.setMenu( contextMenu );
}
 
Example 18
Source File: SinkView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attaches a contextmenu listener to the tree
 */
void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) {
    MenuManager menuMgr = new MenuManager();
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(menuListener);
    Menu menu = menuMgr.createContextMenu(getControl());
    getControl().setMenu(menu);
    viewSite.registerContextMenu(popupId, menuMgr, this);
}
 
Example 19
Source File: N4IDEXpectView.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
	fillLayout.marginHeight = 5;
	fillLayout.marginWidth = 5;
	parent.setLayout(fillLayout);

	// main container
	container = new Composite(parent, SWT.BORDER);
	container.setLayout(new FillLayout());

	// create container for stack trace data
	Composite stacktraceDataContainer = new Composite(parent, SWT.BORDER);

	FormLayout formLayout = new FormLayout();
	formLayout.marginHeight = 5;
	formLayout.marginWidth = 5;
	formLayout.spacing = 5;
	stacktraceDataContainer.setLayout(formLayout);

	Composite stackLabelContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackLabelContainer.setLayout(new GridLayout());

	FormData stackLabelFormData = new FormData();
	stackLabelFormData.top = new FormAttachment(0);
	stackLabelFormData.left = new FormAttachment(0);
	stackLabelFormData.right = new FormAttachment(100);
	stackLabelFormData.bottom = new FormAttachment(20);
	stackLabelContainer.setLayoutData(stackLabelFormData);

	Composite stackTraceContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackTraceContainer.setLayout(new FillLayout());

	FormData stackTraceFormData = new FormData();
	stackTraceFormData.top = new FormAttachment(stackLabelContainer);
	stackTraceFormData.left = new FormAttachment(0);
	stackTraceFormData.right = new FormAttachment(100);
	stackTraceFormData.bottom = new FormAttachment(100);
	stackTraceContainer.setLayoutData(stackTraceFormData);

	// Create viewer for test tree in main container
	testTreeViewer = new TreeViewer(container);
	testTreeViewer.setContentProvider(new XpectContentProvider());
	testTreeViewer.setLabelProvider(new XpectLabelProvider(this.testsExecutionStatus));
	testTreeViewer.setInput(null);

	// create stack trace label
	stacktraceLabel = new Label(stackLabelContainer, SWT.SHADOW_OUT);
	FontData fontData = stacktraceLabel.getFont().getFontData()[0];
	Display display = Display.getCurrent();
	// may be null if outside the UI thread
	if (display == null)
		display = Display.getDefault();
	Font font = new Font(display, new FontData(fontData.getName(), fontData
			.getHeight(), SWT.BOLD));
	// Make stack trace label bold
	stacktraceLabel.setFont(font);

	stacktraceLabel.setText(NO_TRACE_MSG);

	// create stack trace console
	MessageConsole messageConsole = new MessageConsole("trace", null);
	stacktraceConsole = new TraceConsole(messageConsole);
	stacktraceConsoleViewer = new TextConsoleViewer(stackTraceContainer, messageConsole);

	// context menu
	getSite().setSelectionProvider(testTreeViewer);
	MenuManager contextMenu = new MenuManager();
	contextMenu.setRemoveAllWhenShown(true);
	getSite().registerContextMenu(contextMenu, testTreeViewer);
	Control control = testTreeViewer.getControl();
	Menu menu = contextMenu.createContextMenu(control);
	control.setMenu(menu);
	activateContext();

	createSelectionActions();

}
 
Example 20
Source File: LegendTable.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param parent
 * @param style
 */
public LegendTable(Composite parent, int style) {
	
	super(parent, style);
	this.setLayout(new GridLayout(1, false));
	editors = new LinkedList<TableEditor>();
	buttons = new LinkedList<Button>();
	tblLegend = new Table(this, SWT.DOUBLE_BUFFERED );
	tblLegend.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	tblLegend.setHeaderVisible(false);
	tblLegend.setLinesVisible(true);
	tblLegend.setEnabled(true);
	tblLegend.addKeyListener(this);
	{
		TableColumn tblclmnColour = new TableColumn(tblLegend, SWT.NONE);
		tblclmnColour.setWidth(82);
		tblclmnColour.setResizable(false);
		tblclmnColour.setText("Colour");
	}
	{
		TableColumn tblclmnDescription = new TableColumn(tblLegend, SWT.NONE);
		tblclmnDescription.setWidth(250);
		tblclmnDescription.setResizable(true);
		tblclmnDescription.setText("Description");
	}
	if (isRequireActiveButton()) {
		TableColumn tblclmnVisible = new TableColumn(tblLegend, SWT.NONE);
		tblclmnVisible.setWidth(80);
		tblclmnVisible.setResizable(false);
		tblclmnVisible.setText("Visible");
	}
	// The headers have to be visible to resize the column. Sometimes people
	// use long dataset names, therefore need to resize the legend to see
	// what's plotted. We add a right click action to the table to show headers
	// which then allow it to be resized. There may be an easier way to do this.
	final MenuManager man = new MenuManager();
	man.add(new Action("Resizable", IAction.AS_CHECK_BOX) {
		private boolean show = false;
		 @Override
		public void run() {
			show = !show;
			tblLegend.setHeaderVisible(show);
		}
	});
	final Menu menu = man.createContextMenu(tblLegend);
	tblLegend.setMenu(menu);
}