Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to create a pop-up menu
How to create a pop-up menu [message #513821] Thu, 11 February 2010 12:16 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi guys,

I have an IContributionItem object and I want to create a pop-up menu in my View. How can I add this IContributionItem in the pop-up menu?

This works fine:
MenuManager menuManager = new MenuManager();
manager.add(myContributionItemObject);
Menu menu = menuManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuManager, viewer);


But I'd like to have myContributionItemObject in its own sub-menu called "Zoom". How can I do that?
Re: How to create a pop-up menu [message #513838 is a reply to message #513821] Thu, 11 February 2010 08:24 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

behnil@centrum.cz wrote:
>
> But I'd like to have myContributionItemObject in its own sub-menu called
> "Zoom". How can I do that?

Create a second MenuManager. Add that to the first MenuManager, and add
your contribution item to the second.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
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: How to create a pop-up menu [message #513868 is a reply to message #513838] Thu, 11 February 2010 14:38 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Paul,

thank for your advice. Did you mean something like this:

MenuManager menuManager = new MenuManager();
MenuManager submenuManager = new MenuManager("Zoom");
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.add(new Separator());
menuManager.add(submenuManager);
submenuManager.add(myContributionItemObject);
Menu menu = menuManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuManager, viewer);


Great, but if I hover by mouse on the "Zoom" in the menu, it turns gray and nothing happens..I mean, no sub-menu shows up. Confused
Re: How to create a pop-up menu [message #513907 is a reply to message #513868] Thu, 11 February 2010 16:09 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

behnil@centrum.cz wrote:
> MenuManager menuManager = new MenuManager();
> MenuManager submenuManager = new MenuManager("Zoom");
> menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
> menuManager.add(new Separator());
> menuManager.add(submenuManager);
> submenuManager.add(myContributionItemObject);
> Menu menu = menuManager.createContextMenu(viewer.getControl());
> viewer.getControl().setMenu(menu);
> getSite().registerContextMenu(menuManager, viewer);

That's because myContributionItemObject appears to be not-visible or
doesn't create any MenuItems. Your submenu is then disabled because it
has nothing in it. What is your contribution item doing?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
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: How to create a pop-up menu [message #513917 is a reply to message #513907] Thu, 11 February 2010 16:26 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Paul Webster wrote on Thu, 11 February 2010 11:09

That's because myContributionItemObject appears to be not-visible or
doesn't create any MenuItems. Your submenu is then disabled because it
has nothing in it. What is your contribution item doing?

PW


myContributionItemObject is a list of 6 zoom values. But if I right-click and open pop-up menu, there is a "Zoom" item and it's enabled. It goes gray only after I hover on that with mouse.

It's weird. If I use this code:
MenuManager menuManager = new MenuManager();
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(myContributionItemObject);
Menu menu = menuManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuManager, viewer);

It works perfectly except that those 6 zoom values are in root menu. And I want to put them in "Zoom" submenu Smile

[Updated on: Thu, 11 February 2010 16:27]

Report message to a moderator

Previous Topic:limiting command visibility depending on view selecction
Next Topic:Jeff McAffers new RCP book - when?
Goto Forum:
  


Current Time: Tue Mar 19 10:46:40 GMT 2024

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

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

Back to the top