Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Dynamically Contribute to Context Menu
Dynamically Contribute to Context Menu [message #1064319] Tue, 18 June 2013 16:39 Go to next message
Jacob M is currently offline Jacob MFriend
Messages: 4
Registered: June 2013
Junior Member
Hi,

Does anyone know how I can modify the right-click menu from the action of another context menu? I want to have one button configured from plugin.xml that can, from its IAction, change that context menu's layout. For example, a button "Generate Buttons" will change the menu by adding another button "myNewButton".

Here's my existing attempt. I feel I'm close, but 1) .createContextMenu() takes a "Control" - I've never explicitly created a Control so I don't think I've one I can reference, and 2) I don't even know if CreateContextMenu() is something I should use or if there's a better way (I've seen references to "Contributions" but have only used them for menu bar items, never the right-click menu).

MenuManager contextMenu = new MenuManager("#PopUp"); 
contextMenu.add(new Separator("additions"));
Menu menu = contextMenu.createContextMenu(null);


I've looked hard for tutorials or explanations on this but have been unable to find a suitable answer. I'm looking for any explanation, though I'd learn best from seeing actual code.

Thank you.
Re: Dynamically Contribute to Context Menu [message #1064864 is a reply to message #1064319] Fri, 21 June 2013 13:09 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You can add dynamic contributions to a popup menu using
org.eclipse.ui.menus. The locationURI is popup:<context.menu.id> and
then you want to contribute a dynamic element. If you contribute a
subclass of CompoundContributionItem, every time the menu is about to
show, you can return a list of contributions you'd like to supply.

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


Re: Dynamically Contribute to Context Menu [message #1065107 is a reply to message #1064319] Mon, 24 June 2013 11:44 Go to previous messageGo to next message
Jacob M is currently offline Jacob MFriend
Messages: 4
Registered: June 2013
Junior Member
Thank you, I'll look into this but could you provide a link to code or code itself in this thread to help me get started, considering where I am from what I posted (i.e. adding/removing buttons and associated classes from within the action of an existing button)? I knew it was related to CompoundContributionItem but can't find a good example/tutorial of how to begin this.
Re: Dynamically Contribute to Context Menu [message #1065151 is a reply to message #1065107] Mon, 24 June 2013 13:59 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Here's an example of using the dynamic element and a
CompoundContributionItem:
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.ui.examples.contributions/plugin.xml#n666

I would have your plugin manage the list of "dynamic" menu items you
want. Have your Generate item update the dynamic list.

Then simply have CompoundContributionItem return IContributionItems
based on the managed dyanmic list.

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


Re: Dynamically Contribute to Context Menu [message #1066478 is a reply to message #1064319] Tue, 02 July 2013 19:35 Go to previous messageGo to next message
Jacob M is currently offline Jacob MFriend
Messages: 4
Registered: June 2013
Junior Member
Ok, I see how to add that into the plugin.xml. But can you please direct me to Java code (that we'd use in an IAction) to manipulate that item? I.e. add more contributions to the context menu, delete them, etc. That's what I'm having difficulty with, not the creation in the xml.
Re: Dynamically Contribute to Context Menu [message #1072400 is a reply to message #1066478] Mon, 22 July 2013 17:18 Go to previous message
Jacob M is currently offline Jacob MFriend
Messages: 4
Registered: June 2013
Junior Member
Can anyone give an example, complete with code, how to do this?
Previous Topic:Defining an external tool to compile code in my plug-in
Next Topic:PDE Build end of life date
Goto Forum:
  


Current Time: Thu Apr 25 19:26:46 GMT 2024

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

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

Back to the top