|Re: multiple context menu's in one editor [message #544629 is a reply to message #544602]
||Mon, 05 July 2010 06:34
| Daniel KrÃ¼gler
Registered: July 2009
On 04.07.2010 22:07, SlowStrider wrote:|
> I have one (Form)editor with multiple TableViewers. I would like each
> TableViewer to have it's own context menu.
> My menu's can contain commands such as "insert new row", "delete
> selection", etc...
> I think it's not hard to do this in pure SWT with "low level" selection
> listeners, but I would like to do it the clean RCP way with commands and
> structured selections. (Actually I am not sure if I ever need another
> plugin to contribute commands, but it would be nice to have this
> As described
> http://www.ralfebert.de/blog/eclipsercp/commands_context_men u/, I found
> out how to add a context menu to one TableViewer(s) and register it and
> it's structured selection with the editor so that plugins can contribute
> commands. Their handlers can then access the selection using
> HandlerUtil.getCurrentSelection(event) inside their execute method.
> But in my case I have multiple TableViewers that should have their own
> commands and have their own selection. So I have these questions:
> 1. How can I contribute commands to one specific TableViewer but not to
> the others? Can I somehow change the
> <menuContribution locationURI="popup:some.package.someditor">
> <menuContribution locationURI="popup:some.package.someditor.someviewer">?
Yes, in fact the latter assumption is correct. You have to create a
MenuManager for each Table control (or whatever control you need a
context menu for) as described in the Link. You also need to invoke
the call to registerContextMenu, but this time you need the three-
void registerContextMenu(String menuId, MenuManager menuManager,
For the first parameter you need to provide a unique ID for each
viewer. This i9d needs to be used within the locationURI as you
You don't need to invoke
because this would not only register one of the viewers as selection
> 2. When I write a handler for a command such as "insert new row" or
> "delete selected rows" or "call selected person" I will need access to
> the structured selection of the specific TableViewer and I need access
> to the WritableList in it's content provider to remove/add the new
> items. And what do I do when I need access to other data/methods that is
> only known by my specific editor? What is a clean way to get access to
> this information in the handler code?
Use HandlerUtil.getActiveEditor or HandlerUtil.getActivePart and
cast to your concrete Editor class - or even better: Let your editor
implement some specific interface that provides the functionality you
need and cast to the interface.
HTH & Greetings from Bremen,
|Re: multiple context menu's in one editor [message #544754 is a reply to message #544675]
||Mon, 05 July 2010 12:35
| Henno Vermeulen
Registered: July 2009
Ok it works! Without setting the selection provider on the entire site, |
But I found out that
Returns the selection of the ISelectionProvider (TableViewer) I associated with the popup menu.
But how can I properly re-use this command from a button inside my editor? Then the popup menu will not be active. I think I'll just solve this by making a "removeSelectedConcreteObject" method in my editor...
[Updated on: Mon, 05 July 2010 12:45]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.02362 seconds