Java Code Examples for org.eclipse.ui.IWorkbenchPartSite#registerContextMenu()

The following examples show how to use org.eclipse.ui.IWorkbenchPartSite#registerContextMenu() . 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: 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 2
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 3
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 4
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 5
Source File: ServersViewer.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void hookContextMenu ( final IWorkbenchPartSite site )
{
    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 );
    site.registerContextMenu ( menuMgr, this.viewer );
}
 
Example 6
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 7
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 8
Source File: AbstractEditorPropertySection.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);
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider());
}
 
Example 9
Source File: CallHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Attaches a context menu listener to the tree
 * @param menuListener the menu listener
 * @param viewSite the view site
 * @param selectionProvider the selection provider
 */
void initContextMenu(IMenuListener menuListener, IWorkbenchPartSite viewSite, ISelectionProvider selectionProvider) {
    MenuManager menuMgr= new MenuManager();
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(menuListener);
    Menu menu= menuMgr.createContextMenu(getTree());
    getTree().setMenu(menu);
    viewSite.registerContextMenu(menuMgr, selectionProvider);
}
 
Example 10
Source File: LocationViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Attaches a context menu listener to the tree.
 *
 * @param menuListener the menu listener
 * @param popupId  the id of the popup
 * @param viewSite the part site
 */
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 11
Source File: TypeHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Attaches a context menu listener to the tree.
 *
 * @param menuListener the menu listener
 * @param popupId the popup id
 * @param viewSite the view site
 */
public void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) {
	MenuManager menuMgr= new MenuManager();
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(menuListener);
	Menu menu= menuMgr.createContextMenu(getTree());
	getTree().setMenu(menu);
	viewSite.registerContextMenu(popupId, menuMgr, this);
}
 
Example 12
Source File: MethodsViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Attaches a contextmenu listener to the table
 * @param menuListener the menu listener
 * @param popupId the popup id
 * @param viewSite the view site
 */
public void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) {
	MenuManager menuMgr= new MenuManager();
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(menuListener);
	Menu menu= menuMgr.createContextMenu(getTable());
	getTable().setMenu(menu);
	viewSite.registerContextMenu(popupId, menuMgr, this);
}
 
Example 13
Source File: BaseDebugView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
    IViewSite viewSite = getViewSite();
    if (viewSite != null) {
        configureToolBar(viewSite);
    }

    parent.setLayout(new GridLayout(1, true));

    viewer = new TreeViewer(parent);
    provider = createContentProvider();
    viewer.setContentProvider(provider);
    viewer.setLabelProvider(new PyDebugModelPresentation(false));

    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTree());

    MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(viewer.getTree());
    viewer.getTree().setMenu(menu);
    IWorkbenchPartSite site = getSite();
    site.registerContextMenu(menuManager, viewer);
    site.setSelectionProvider(viewer);

    this.parent = parent;

    listener = createListener();
    if (listener != null) {
        DebugPlugin plugin = DebugPlugin.getDefault();

        ILaunchManager launchManager = plugin.getLaunchManager();
        launchManager.addLaunchListener(listener);

        plugin.addDebugEventListener(listener);
    }
}
 
Example 14
Source File: CodeSelectorFactory.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Registers the context menu, if {@link #hasContextMenu()} returns true, with the site. The id
 * of the context menu is viewId plus . and {@link #getCodeSystemName()}. <br />
 * example ids: <i>ch.elexis.codedetailview.Block</i> or <i>ch.elexis.LeistungenView.Block</i>
 * 
 * @param site
 */
public void activateContextMenu(IWorkbenchPartSite site,
	DelegatingSelectionProvider selectionProvider, String viewId){
	if (hasContextMenu() && site.getPart() != null) {
		selectionProvider.setSelectionProviderDelegate(getSelectionProvider());
		site.registerContextMenu(viewId + "." + getCodeSystemName(), getMenuManager(),
			selectionProvider);
	}
}
 
Example 15
Source File: MedicationViewerHelper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static void addContextMenu(TableViewer viewer, MedicationComposite medicationComposite,
	IWorkbenchPartSite site){
	// register context menu for table viewer
	MenuManager menuManager = new MenuManager();
	Menu menu = menuManager.createContextMenu(viewer.getTable());
	
	viewer.getTable().setMenu(menu);
	if (site != null) {
		site.registerContextMenu("ch.elexis.core.ui.medication.tables", menuManager, viewer);
	}
}
 
Example 16
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();
}