Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Programmatically add submenu(Command contribution)
Programmatically add submenu [message #665637] Fri, 15 April 2011 10:33 Go to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Hi,

I am trying to programmatically populate a context menu in my application. This works well as I register my menu in my plugin.xml using

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="popup:viewID">
      </menuContribution>
   </extension>

and adding a ContributionFactory at runtime
		final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
		menuService.addContributionFactory(ContextMenuContributionFactory.getInstance(getEditorSite().getId()));


But what should I do when one of my ContributionItems wants to declare a submenu?

I guess my item needs to define a menuContribution programmatically and add another ContributionFactory to that.

If so, how can I define the menuContribution?

thanks
Christian
Re: Programmatically add submenu [message #665653 is a reply to message #665637] Fri, 15 April 2011 11:35 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/15/2011 06:34 AM, Christian Pontesegger wrote:
>
> and adding a ContributionFactory at runtime
>
> final IMenuService menuService = (IMenuService)
> PlatformUI.getWorkbench().getService(IMenuService.class);
> menuService.addContributionFactory(ContextMenuContributionFa ctory.getInstance(getEditorSite().getId()));

That kind of factory gets applied once (although in some cases of
context menu, it might get applied multiple times). You're better of
using a regular menuContribution and the <dynamic/> element for the
section of your contribution you'd like to contribute dynamically. But
a ContributionFactory is API and will work.

> But what should I do when one of my ContributionItems wants to declare a
> submenu?

Add a MenuManager. That's a contribution item. If it's not dynamic in
nature, and you switched to a normal menuContribution instead of a
factory, you could simply define the submenu in the XML. But you can
define it in your ContributionFactory, you just become responsible for
filling it in.

Later,
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/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Phantom sticky shells
Next Topic:Help needed with helios SR2 crashing in Windows 7
Goto Forum:
  


Current Time: Fri Apr 19 21:40:57 GMT 2024

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

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

Back to the top