Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » More context menus for editor
More context menus for editor [message #765728] Wed, 14 December 2011 15:32 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

how can I have more context menus in my editor? I have a TableViewer and a ListViewer side by side in the editor part and I would like to contribute the theirs context menus independently. Both viewers show same model elements.

getSite().setSelectionProvider(tableViewer);

MenuManager menuMgr = new MenuManager();
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
tableViewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, tableViewer);


menuMgr = new MenuManager();
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = menuMgr.createContextMenu(listViewer.getControl());
listViewer.getControl().setMenu(menu);
getSite().registerContextMenu("secondMenu", menuMgr, listViewer);


when I contribute a menu like this:
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
     <command commandId="myCommandId" style="push">
          <visibleWhen checkEnabled="false">
               <and>
                  <count value="1"></count>
                  <iterate>
                     <instanceof value="myModelObject"></instanceof>
                  </iterate>
               </and>
          </visibleWhen>
     </command> 
</menuContribution>

in the table's context menu the contribution shows up correctly. But the list's menu is empty. I guess its because of the line
getSite().setSelectionProvider(tableViewer);

Which selectionProvider to register with the site when I have more of them by the way?
Re: More context menus for editor [message #765748 is a reply to message #765728] Wed, 14 December 2011 15:51 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-12-14 16:32, Behnil wrote:
> Hi,
>
> how can I have more context menus in my editor? I have a TableViewer and
> a ListViewer side by side in the editor part and I would like to
> contribute the theirs context menus independently. Both viewers show
> same model elements.
>
>
> getSite().setSelectionProvider(tableViewer);
>
> MenuManager menuMgr = new MenuManager();
> menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
> Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
> tableViewer.getControl().setMenu(menu);
> getSite().registerContextMenu(menuMgr, tableViewer);
>
>
> menuMgr = new MenuManager();
> menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
> Menu menu = menuMgr.createContextMenu(listViewer.getControl());
> listViewer.getControl().setMenu(menu);
> getSite().registerContextMenu("secondMenu", menuMgr, listViewer);
>
>
> when I contribute a menu like this:
>
> <menuContribution
> locationURI="popup:org.eclipse.ui.popup.any?after=additions">
> <command commandId="myCommandId" style="push">
> <visibleWhen checkEnabled="false">
> <and>
> <count value="1"></count>
> <iterate>
> <instanceof value="myModelObject"></instanceof>
> </iterate>
> </and>
> </visibleWhen>
> </command> </menuContribution>
>
> in the table's context menu the contribution shows up correctly. But the
> list's menu is empty. I guess its because of the line
>
> getSite().setSelectionProvider(tableViewer);
>
> Which selectionProvider to register with the site when I have more of
> them by the way?

If you have more than one context menu per view you should assign
different menu ids to *both*, i.e. use

MenuManager menuMgr = new MenuManager(null, "firstMenuId");
[..]
getSite().registerContextMenu("firstMenuId", menuMgr, tableViewer);

and

MenuManager menuMgr = new MenuManager(null, "secondMenuId");
[..]
getSite().registerContextMenu("secondMenuId", menuMgr, listViewer);

HTH & Greetings from Bremen,

Daniel Krügler
Re: More context menus for editor [message #765768 is a reply to message #765748] Wed, 14 December 2011 16:40 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
And what about the site's selection provider? When I have more of them, which one to set?
I suppose that menu service deal with actual selection of the editor part when composes context menu from declarative menu contributions. Or does it deal with selection from the selection provider registered by getSite().registerContextMenu("menuId", menuManager, selectionProvider)?

[Updated on: Wed, 14 December 2011 17:02]

Report message to a moderator

Re: More context menus for editor [message #765814 is a reply to message #765768] Wed, 14 December 2011 18:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

For an expression in a context menu, you need something like:

<visibleWhen checkEnabled="false">
   <with variable="activeMenuSelection">
      <and>...</and>
   </with>
</visibleWhen>


The activeMenuSelection get set when you open a context menu, based on the selection provider used in registerContextMenu(*).

selection is based on the view or editor selection provider.

Later,
PW



Re: More context menus for editor [message #766104 is a reply to message #765814] Thu, 15 December 2011 08:33 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Awesome, thank you Paul and Daniel.
Re: More context menus for editor [message #766763 is a reply to message #766104] Fri, 16 December 2011 11:34 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, I have still a problem with this.

I have this menu contribution:
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
    <command commandId="myCommand" style="push">
        <visibleWhen checkEnabled="false">
            <with variable="activeMenuSelection">
                <and>
                    <count value="1"></count>
                    <iterate>
                        <instanceof value="myModel"></instanceof>
                    </iterate>
                </and>
            </with>
        </visibleWhen>
    </command>  
</menuContribution>

Let's say my editor contains a TableViewer. This TableViewer is registered as selection provider to the editor's site.
It has also a context menu which is registered to the site so it can be contributed by other plugins.
getSite().setSelectionProvider(tableViewer);
MenuManager menuMgr = new MenuManager(null, "editor.mainContextMenu");
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
tableViewer.getControl().setMenu(menu);
getSite().registerContextMenu("editor.mainContextMenu", menuMgr, tableViewer);

Context menu is shown properly.

Now let's say that I can open a non modal dialog from this editor. In the dialog is a ListViewer containing the same model as the editor's TableViewer.
And would like to get context menu on that ListViewer also extended by other plugins. So I pass the editor's IWorkbenchPartSite to the dialog when is opened
and register ListViewer's context menu:
MenuManager menuMgr = new MenuManager(null, "editor.dialogContextMenu");
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = menuMgr.createContextMenu(listViewer.getControl());
listViewer.getControl().setMenu(menu);
editorSite.registerContextMenu("editor.dialogContextMenu", menuMgr, listViewer);

Now when the dialog is open, context menu show properly. That's amazing.

But, when I left click on the editor and then I click back to the dialog and pres right click on the listViewer, listViewer's context menu isn't shown at all.
When I after that right click on the tableViewer and then again right click on the listViewer, context menu shows up properly.
I really don't understand what is happening here.

After some debugging I found the MenuManager on the listViewer handleAboutToShow() and immediately after that handleAboutToHide() called.
So the context menu can't be shown I guess. but why is the handleAboutToHide() called and why right click on the tableViewer fixes that, is a mystery.
Re: More context menus for editor [message #766821 is a reply to message #766763] Fri, 16 December 2011 13:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You cannot use your editor or view partsite in a dialog. The dialog changes the active shell from the active workbench window and disables a lot of items.

What do you want your users to be able to do in the dialog? Since you mentioned they go back to the editor, it's non-modal. You want it up for a while?

PW


Re: More context menus for editor [message #766849 is a reply to message #766821] Fri, 16 December 2011 14:41 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, I was talking about my problem in general way. I should be more concrete I guess.

The editor contains nothing but a canvas with draw2d figures. It looks similar to a table.
I have created my own SelectionProvider for that figure table and registered its context menu with the editor's site. So other plugins can contribute to it.

I can't use draw2d scrollbars in this figure table, so when a column contains more rows than it can render, the last row is replaced with an ellipses "...".
When the user clicks on that last row, a dialog is open. This dialog contains just a listViewer with all those rows that don't fit into the figure table's column.

I need to have the same context menu for that listViewer like the table's one. So it have to be composed by workbench with other plugins menu contributions.
Re: More context menus for editor [message #766978 is a reply to message #766849] Fri, 16 December 2011 19:33 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Why not have the listViewer in another view, and show/activate that if needed by the table? Then it is just a view, and its context menu works fine.

PW


Re: More context menus for editor [message #767008 is a reply to message #766978] Fri, 16 December 2011 21:00 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Yes, I already thought about it.
So with the dialog it's not possible? Even when it will be set as modal? For the first time when it's opened, the context menu looks alright.
Previous Topic:Adding pane to the project-properties window in RCP
Next Topic:RCP Continuous Integration Environment advice
Goto Forum:
  


Current Time: Tue Mar 19 05:27:07 GMT 2024

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

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

Back to the top