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

The following examples show how to use org.eclipse.jface.action.MenuManager#addMenuListener() . 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: ComponentEditor.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 2
Source File: SearchScopeActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void fillContextMenu(IMenuManager menu) {
	MenuManager javaSearchMM = new MenuManager(CallHierarchyMessages.SearchScopeActionGroup_searchScope,
			IContextMenuConstants.GROUP_SEARCH);
	javaSearchMM.setRemoveAllWhenShown(true);

	javaSearchMM.addMenuListener(new IMenuListener() {
		/* (non-Javadoc)
		 * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
		 */
		public void menuAboutToShow(IMenuManager manager) {
			fillSearchActions(manager);
		}
	});

	fillSearchActions(javaSearchMM);
	menu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, javaSearchMM);
}
 
Example 3
Source File: ChartConfiguratorView.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 -->
 */
protected void createContextMenuFor ( final StructuredViewer viewer )
{
    final MenuManager contextMenu = new MenuManager ( "#PopUp" );
    contextMenu.add ( new Separator ( "additions" ) );
    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 () };
    viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) );
    viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( this.editingDomain, viewer ) );
}
 
Example 4
Source File: RecipeEditor.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 5
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 6
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 7
Source File: RefactorActionGroup.java    From typescript.java with MIT License 6 votes vote down vote up
private void addRefactorSubmenu(IMenuManager menu) {
	MenuManager refactorSubmenu = new MenuManager(RefactoringMessages.RefactorMenu_label, MENU_ID);
	// refactorSubmenu.setActionDefinitionId(QUICK_MENU_ID);
	if (fEditor != null) {
		// final ITypeRoot element= getEditorInput();
		// if (element != null && ActionUtil.isOnBuildPath(element)) {
		refactorSubmenu.addMenuListener(new IMenuListener() {
			@Override
			public void menuAboutToShow(IMenuManager manager) {
				refactorMenuShown(manager);
			}
		});
		refactorSubmenu.add(fNoActionAvailable);
		menu.appendToGroup(fGroupName, refactorSubmenu);
		// }
	} else {
		ISelection selection = fSelectionProvider.getSelection();
		for (Iterator<SelectionDispatchAction> iter = fActions.iterator(); iter.hasNext();) {
			iter.next().update(selection);
		}
		if (fillRefactorMenu(refactorSubmenu) > 0)
			menu.appendToGroup(fGroupName, refactorSubmenu);
	}
}
 
Example 8
Source File: TestResultsView.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void hookContextMenu() {
	final MenuManager menuMgr = new MenuManager("#PopupMenu");
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager manager) {
			TestResultsView.this.fillContextMenu(manager);
		}
	});
	Menu menu = menuMgr.createContextMenu(testTreeViewer.getControl());
	testTreeViewer.getControl().setMenu(menu);
	getSite().registerContextMenu(menuMgr, testTreeViewer);
}
 
Example 9
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void createContextMenu() {
	MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$
	menuManager.setRemoveAllWhenShown(true);
	menuManager.addMenuListener(this);
	Menu contextMenu= menuManager.createContextMenu(fViewer.getControl());
	fViewer.getControl().setMenu(contextMenu);
	getSite().registerContextMenu(menuManager, fViewer);
}
 
Example 10
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the basic sequence diagram menu
 */
protected void hookContextMenu() {
    fMenuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    fMenuMgr.setRemoveAllWhenShown(true);
    fMenuMgr.addMenuListener(this::fillContextMenu);
    Menu menu = fMenuMgr.createContextMenu(fSdWidget.getViewControl());
    fSdWidget.getViewControl().setMenu(menu);
    getSite().registerContextMenu(fMenuMgr, fSdWidget.getSelectionProvider());
}
 
Example 11
Source File: SarosView.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
protected void addMenuStartSeparator(MenuManager menuManager) {
  menuManager.addMenuListener(
      new IMenuListener() {
        @Override
        public void menuAboutToShow(IMenuManager manager) {
          Separator menuStart = new Separator("menustart");
          menuStart.setVisible(false);
          manager.add(menuStart);
        }
      });
}
 
Example 12
Source File: AbstractFindbugsView.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {
        @Override
        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(getRootControl());
    getRootControl().setMenu(menu);
    // TODO
    // getSite().registerContextMenu(menuMgr, viewer);
}
 
Example 13
Source File: EipEditor.java    From eip-designer with Apache License 2.0 5 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");
     contextMenu.add(new Separator("additions"));
     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 14
Source File: CoreEditor.java    From ifml-editor with MIT License 5 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");
	contextMenu.add(new Separator("additions"));
	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 15
Source File: SourceView.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 16
Source File: LapseView.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 17
Source File: AbstractSegmentsStatisticsViewer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param parent
 *            the parent composite
 * @param dataProviderId
 *            the data provider extension point ID.
 * @since 3.0
 */
public AbstractSegmentsStatisticsViewer(Composite parent, @Nullable String dataProviderId) {
    super(parent, false);
    setLabelProvider(new SegmentStoreStatisticsLabelProvider());
    fTablePopupMenuManager = new MenuManager();
    fTablePopupMenuManager.setRemoveAllWhenShown(true);
    fTablePopupMenuManager.addMenuListener(manager -> {
        TreeViewer viewer = getTreeViewer();
        ISelection selection = viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection sel = (IStructuredSelection) selection;
            if (manager != null) {
                appendToTablePopupMenu(manager, sel);
            }
        }
    });
    Menu tablePopup = fTablePopupMenuManager.createContextMenu(getTreeViewer().getTree());
    Tree tree = getTreeViewer().getTree();
    tree.setMenu(tablePopup);
    tree.addDisposeListener(e -> {
        if (fModule != null) {
            fModule.dispose();
        }
    });

    fProviderId = dataProviderId;
}
 
Example 18
Source File: EditTemplateDialog.java    From typescript.java with MIT License 4 votes vote down vote up
private void initializeActions() {
	TextViewerAction action = new TextViewerAction(fPatternEditor, ITextOperationTarget.UNDO);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_undo);
	fGlobalActions.put(ITextEditorActionConstants.UNDO, action);

	action = new TextViewerAction(fPatternEditor, ITextOperationTarget.CUT);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_cut);
	fGlobalActions.put(ITextEditorActionConstants.CUT, action);

	action = new TextViewerAction(fPatternEditor, ITextOperationTarget.COPY);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_copy);
	fGlobalActions.put(ITextEditorActionConstants.COPY, action);

	action = new TextViewerAction(fPatternEditor, ITextOperationTarget.PASTE);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_paste);
	fGlobalActions.put(ITextEditorActionConstants.PASTE, action);

	action = new TextViewerAction(fPatternEditor, ITextOperationTarget.SELECT_ALL);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_select_all);
	fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, action);

	action = new TextViewerAction(fPatternEditor, ISourceViewer.CONTENTASSIST_PROPOSALS);
	action.setText(JSDTTypeScriptUIMessages.EditTemplateDialog_content_assist);
	fGlobalActions.put("ContentAssistProposal", action); //$NON-NLS-1$

	fSelectionActions.add(ITextEditorActionConstants.CUT);
	fSelectionActions.add(ITextEditorActionConstants.COPY);
	fSelectionActions.add(ITextEditorActionConstants.PASTE);

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

	StyledText text = fPatternEditor.getTextWidget();
	Menu menu = manager.createContextMenu(text);
	text.setMenu(menu);
}
 
Example 19
Source File: CodeElementStatisticsComposite.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private void createContent(){
	setLayout(new GridLayout(1, false));
	
	title = new Label(this, SWT.NONE);
	title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
	
	viewer = new TableViewer(this,
		SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
	viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	
	viewer.setContentProvider(ArrayContentProvider.getInstance());
	viewer.setLabelProvider(new LabelProvider() {
		@Override
		public String getText(Object element){
			if (element instanceof PersistentObject) {
				return ((PersistentObject) element).getLabel();
			} else if (element instanceof Identifiable) {
				return ((Identifiable) element).getLabel();
			}
			return super.getText(element);
		}
	});
	
	MenuManager menu = new MenuManager();
	menu.setRemoveAllWhenShown(true);
	menu.addMenuListener(new IMenuListener() {
		public void menuAboutToShow(IMenuManager manager){
			manager.add(new ClearStatisticAction());
		}
	});
	viewer.getControl().setMenu(menu.createContextMenu(viewer.getControl()));
	viewer.addDoubleClickListener(new IDoubleClickListener() {
		@Override
		public void doubleClick(DoubleClickEvent event){
			IStructuredSelection selection = viewer.getStructuredSelection();
			if (selection != null && !selection.isEmpty()) {
				ICodeSelectorTarget target =
					CodeSelectorHandler.getInstance().getCodeSelectorTarget();
				if (target != null) {
					for (Object selected : selection.toList()) {
						target.codeSelected(selected);
					}
				}
			}
		}
	});
	new GenericObjectDragSource(viewer);
}
 
Example 20
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	final PerformanceStats stats= PerformanceStats.getStats(PERF_CREATE_PART_CONTROL, this);
	stats.startRun();

	fViewer= createViewer(parent);
	fViewer.setUseHashlookup(true);

	initDragAndDrop();

	setProviders();

	JavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);


	MenuManager menuMgr= new MenuManager("#PopupMenu"); //$NON-NLS-1$
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(this);
	fContextMenu= menuMgr.createContextMenu(fViewer.getTree());
	fViewer.getTree().setMenu(fContextMenu);

	// Register viewer with site. This must be done before making the actions.
	IWorkbenchPartSite site= getSite();
	site.registerContextMenu(menuMgr, fViewer);
	site.setSelectionProvider(fViewer);

	makeActions(); // call before registering for selection changes

	// Set input after filter and sorter has been set. This avoids resorting and refiltering.
	restoreFilterAndSorter();
	fViewer.setInput(findInputElement());
	initFrameActions();
	initKeyListener();

	fViewer.addDoubleClickListener(new IDoubleClickListener() {
		public void doubleClick(DoubleClickEvent event) {
			fActionSet.handleDoubleClick(event);
		}
	});

	fOpenAndLinkWithEditorHelper= new OpenAndLinkWithEditorHelper(fViewer) {
		@Override
		protected void activate(ISelection selection) {
			try {
				final Object selectedElement= SelectionUtil.getSingleElement(selection);
				if (EditorUtility.isOpenInEditor(selectedElement) != null)
					EditorUtility.openInEditor(selectedElement, true);
			} catch (PartInitException ex) {
				// ignore if no editor input can be found
			}
		}

		@Override
		protected void linkToEditor(ISelection selection) {
			PackageExplorerPart.this.linkToEditor(selection);
		}

		@Override
		protected void open(ISelection selection, boolean activate) {
			fActionSet.handleOpen(selection, activate);
		}

	};

	IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager();
	fViewer.addSelectionChangedListener(new StatusBarUpdater(slManager));
	fViewer.addTreeListener(fExpansionListener);

	// Set help for the view
	JavaUIHelp.setHelp(fViewer, IJavaHelpContextIds.PACKAGES_VIEW);

	fillActionBars();

	updateTitle();

	fFilterUpdater= new FilterUpdater(fViewer);
	ResourcesPlugin.getWorkspace().addResourceChangeListener(fFilterUpdater);

	// Sync'ing the package explorer has to be done here. It can't be done
	// when restoring the link state since the package explorers input isn't
	// set yet.
	setLinkingEnabled(isLinkingEnabled());

	stats.endRun();
}