Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Adding a predefined popup menu to a TreeViewer without an id
Adding a predefined popup menu to a TreeViewer without an id [message #631686] Fri, 08 October 2010 13:30 Go to next message
staudta is currently offline staudtaFriend
Messages: 17
Registered: August 2010
Junior Member
Hi again,

I have unfortunately another problem that I'm at the moment not able to solve.
An already existing plugin provides a view (extension point: org.eclipse.ui.views). There are also extension points for
org.eclipse.ui.commands, org.eclipse.ui.handlers and org.eclipse.ui.menus. To add a popup menu to the view isn't a big deal.
It is possible to define a menuContribution and the locationURI points to the view id. - so far everything is fine and understood.

In addition to that view, I have another use case and I need to open a dialog. This dialog should look and behave almost as the view. The only difference is that only a subset of the context menu entries should be visible.

The dialog contains of a TreeViewer. To this TreeViewer I set the already a ContentProvider, LabelProvider, and Input. The only missing part is the context menu.

As mentioned commands and handlers exist. I need to define my own menu, but my TreeView does not have an id so I can't use: "popup:<view-id>?before=additions".

What would you do to get these already defined handlers to you own view?
Thank you in advance. I look forward to your ideas.
Adrian
Re: Adding a predefined popup menu to a TreeViewer without an id [message #631768 is a reply to message #631686] Fri, 08 October 2010 16:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you use a MenuManager to create your context menu, you can still use
org.eclipse.ui.menus.IMenuService.populateContributionManage r(ContributionManager,
String) and
org.eclipse.ui.menus.IMenuService.releaseContributions(Contr ibutionManager)

When you populate that menu manager, you get to specify the ID.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Adding a predefined popup menu to a TreeViewer without an id [message #632795 is a reply to message #631768] Thu, 14 October 2010 10:13 Go to previous messageGo to next message
staudta is currently offline staudtaFriend
Messages: 17
Registered: August 2010
Junior Member
Thank you that worked fine.
The menuContribution that I'm reusing has some commands, and these commands have conditions as "visibleWhen" and than an "iterate" element. This iterate element seems to get an empty Collection that means that the selection is not contributed.

I thought that I need do add a SelectionProvider.
Well if I'm looking the View-Implementation that this code adds the selection Provider:
private TreeViewer viewer;
...
public void createPartControl(Composite parent) {
   ...
   getSite().setSelectionProvider(viewer);
   ...

with
    public IWorkbenchPartSite getSite() {
        return partSite;
    }


Can I provide a SelectionProvider for a org.eclipse.jface.dialogs.Dialog?
My code looks currently like this

	protected Control createDialogArea(final Composite parent) {
		final Composite composite = (Composite) super.createDialogArea(parent);
		composite.getShell().setSize(composite.getShell().computeSize(400, 200));
		composite.setLayout(new FillLayout());

		viewer = new TreeViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
		viewer.setContentProvider( new WXContentProvider() );
		IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
		viewer.setLabelProvider(new DecoratingLabelProvider(new WXLabelProvider(), decoratorManager.getLabelDecorator()));
		viewer.setSorter(new WXViewerSorter());
		viewer.setInput(WorkspaceManager.getInstance().getCurrentWorkspace());

		final MenuManager menuMgr = new MenuManager();
		menuMgr.setRemoveAllWhenShown(true);
		IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
		menuService.populateContributionManager(menuMgr, "popup:<view-id>");
		viewer.getControl().setMenu(menuMgr.createContextMenu(viewer.getControl()));

		parent.pack();
		return composite;
	}



Thank you, Adrian

[Updated on: Thu, 14 October 2010 10:48]

Report message to a moderator

Re: Adding a predefined popup menu to a TreeViewer without an id [message #633570 is a reply to message #632795] Mon, 18 October 2010 12:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Adrian wrote:
> Thank you that worked fine.
> Can I provide a SelectionProvider for a org.eclipse.jface.dialogs.Dialog?
> Or is there another solution to get the context menu working?

By default no, dialog is not integrated into the window/part based
variables provides.

You could either 1) use property testers in the dialog, which could
query the dialog selection or 2) provide a DialogSelectionSourceProvider
through org.eclipse.ui.services. Then use that as a variable in your
context menu.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Adding a predefined popup menu to a TreeViewer without an id [message #734211 is a reply to message #633570] Fri, 07 October 2011 04:50 Go to previous message
Li Chen is currently offline Li ChenFriend
Messages: 20
Registered: July 2011
Location: Sydney
Junior Member
Paul Webster wrote on Mon, 18 October 2010 08:46
Adrian wrote:
> Thank you that worked fine.
> Can I provide a SelectionProvider for a org.eclipse.jface.dialogs.Dialog?
> Or is there another solution to get the context menu working?

By default no, dialog is not integrated into the window/part based
variables provides.

You could either 1) use property testers in the dialog, which could
query the dialog selection or 2) provide a DialogSelectionSourceProvider
through org.eclipse.ui.services. Then use that as a variable in your
context menu.

PW


Would you be able to expand a little bit on option 2 please?
Previous Topic:Common Navigator Framework - Trigger refresh
Next Topic:Register a PreferencePage at runtime?
Goto Forum:
  


Current Time: Tue Mar 19 04:41:25 GMT 2024

Powered by FUDForum. Page generated in 0.02758 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top