Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Adding popup menu submenu similar to New Child
Adding popup menu submenu similar to New Child [message #867606] Tue, 01 May 2012 11:35 Go to next message
Mikal Hitsøy Henriksen is currently offline Mikal Hitsøy HenriksenFriend
Messages: 3
Registered: May 2012
Junior Member
Hey, I'm extending another EMF-based plugin (ePNK if anyone's interested, can't link because of new account), and I want to extend the right-click menu in the tree editor with a dynamic sub-menu similar to the New Child and New Sibling menus. It will be called something like New Annotation, and it is supposed to contain entries for adding child entities with different pre-set attributes, with the available attributes depending on the selected entity, and also depending on sets of annotations the user has loaded. I know roughly how to generate which entries to make available in the submenu, but I can't figure out the right way to actually contribute it to the popup menu.

I've successfully used the org.eclipse.ui.popupMenus extension point to add individual static commands to a static submenu, but I don't see how this can be made to populate it dynamically. I can't add all possible entries, since the user is able to define new annotations.

If I was providing my own editor I could modify contributeToMenu in my EditingDomainActionBarContributor, but since I'm extending the ePNK editor I can't override its contributeToMenu, or at least I don't know how. Or somehow hook into the menu it contributes to. I believe this is the right area to look for the solution, though.

Any suggestions? Thanks
Re: Adding popup menu submenu similar to New Child [message #867615 is a reply to message #867606] Tue, 01 May 2012 11:40 Go to previous messageGo to next message
Mikal Hitsøy Henriksen is currently offline Mikal Hitsøy HenriksenFriend
Messages: 3
Registered: May 2012
Junior Member
I also checked out the org.eclipse.emf.edit.childCreationExtenders extension point, but this would put the new entries in the New Child menu (right?), which I don't want.

[Updated on: Tue, 01 May 2012 11:41]

Report message to a moderator

Re: Adding popup menu submenu similar to New Child [message #867910 is a reply to message #867606] Tue, 01 May 2012 14:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Mikal,

Comments below.

On 01/05/2012 1:35 PM, Mikal Hitsøy Henriksen wrote:
> Hey, I'm extending another EMF-based plugin (ePNK if anyone's
> interested, can't link because of new account), and I want to extend
> the right-click menu in the tree editor with a dynamic sub-menu
> similar to the New Child and New Sibling menus. It will be called
> something like New Annotation, and it is supposed to contain entries
> for adding child entities with different pre-set attributes, with the
> available attributes depending on the selected entity, and also
> depending on sets of annotations the user has loaded. I know roughly
> how to generate which entries to make available in the submenu, but I
> can't figure out the right way to actually contribute it to the popup
> menu.
It's not an EMF question. You can look at what we've done with JFace as
an example.
>
> I've successfully used the org.eclipse.ui.popupMenus extension point
> to add individual static commands to a static submenu, but I don't see
> how this can be made to populate it dynamically. I can't add all
> possible entries, since the user is able to define new annotations.
Look at how we use the action bar contributor.
>
> If I was providing my own editor I could modify contributeToMenu in my
> EditingDomainActionBarContributor, but since I'm extending the ePNK
> editor I can't override its contributeToMenu, or at least I don't know
> how.
If their editor isn't extensible, I'm not sure there's a way.
> Or somehow hook into the menu it contributes to. I believe this is the
> right area to look for the solution, though.
> Any suggestions? Thanks
Re: Adding popup menu submenu similar to New Child [message #868461 is a reply to message #867910] Wed, 02 May 2012 02:22 Go to previous messageGo to next message
Mikal Hitsøy Henriksen is currently offline Mikal Hitsøy HenriksenFriend
Messages: 3
Registered: May 2012
Junior Member
To anyone else interested: I figured out the correct way to do this. And this does relate to EMF to a certain degree.

As I mentioned in my original post, I used the org.eclipse.ui.popupMenus extension point to add static actions to the popup menu of the editor. The plugin's documentation also listed this as the way to add actions to the popup menu. But org.eclipse.ui.popupMenus isn't suitable for the dynamic submenu I want to provide.

I've spent all day now trying different techniques. I've read many places that the org.eclipse.ui.menus extensionpoint is to be preferred over org.eclipse.ui.popupMenus, but I couldn't for the life of me get it to work, as there is no standard menu id for any part of the popupmenu, and any submenus created with org.eclipse.ui.popupMenus (with id) will not work as targets for org.eclipse.ui.menus.

The reason I say it's related to EMF is that the editor EMF generates does not give an id to the menu it provides to the editor (in MultiPageEditorPart.createContextMenuForGen(*)). This caused confusion when I tried to use the Plugin Menu Spy (Alt-Shift-F2), as none of the entries in the top level of the popup menu had a location URI (which is what org.eclipse.ui.menus needs to place new menu contributions), and generally had very little info at all. As I was extending this plugin I was of course unable to modify this part of the source code.

Then by chance I noticed in the Plugin Selection Spy (Alt-Shift-F1) there was a field called "The active menu contribution identifiers:" which walue was the id of the editor as registerd in the org.eclipse.ui.editors extension point. Having tried everything else, I simply used the value of this to craft the location URI (which became "popup:org.pnml.tools.epnk.pnmlcoremodel.presentation.PnmlcoremodelEditorPNML?after=additions"). To my surprise, this worked! So I now have the full power of org.eclipse.ui.menus to create my dynamic submenu Smile
Re: Adding popup menu submenu similar to New Child [message #1088796 is a reply to message #868461] Sat, 17 August 2013 17:32 Go to previous message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
After a lot of searching I found this thread which was really helpful!!

Due to Mikal hints, I was able to create my own menuContribution through the org.eclipse.ui.menus extension point as youc an see in the image (import is the one I added).

index.php/fa/15936/0/

I'm wondering now how I can place it on a different section (maybe before Validate). Using ?before/after=additions is the only one which works, so I reckon additions (like Wizards, Run as..) is contributed by Eclipse and the above (undo, cut, copy) is contributed by emf?

Edit: I've seen that you can call the super constructor of the generated ActionBarContributor with a style bit. org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.menuAboutToShow(IMenuManager menuManager) seems to be the method where the order is determined. Is there a way to alter this and maybe remove additions?

Using ?after=redoAction for example didn't work which was wondering me.

Furthermore I haven't found a way to add my own menu item to an existing one (e.g. as child menu item for New Child). Is this possible. Using the Spy tool hasn't give me a hint.

Cheers,
Phil
  • Attachment: popupMenu.jpg
    (Size: 24.04KB, Downloaded 232 times)

[Updated on: Sat, 17 August 2013 18:01]

Report message to a moderator

Previous Topic:EMF XMl save config
Next Topic:[xcore] Extending metamodel created by Xtext leads to erroneous generated code
Goto Forum:
  


Current Time: Wed Nov 26 20:56:13 GMT 2014

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

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