Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to contribute a new menu item in an existing menu via a fragment?
How to contribute a new menu item in an existing menu via a fragment? [message #1001806] Thu, 17 January 2013 07:00 Go to next message
Eclipse User
Hello,
I'm looking for a simple tutorial on how to contribute a new menu item t
an existing menu. I found some urls:

http://www.vogella.com/articles/Eclipse4Modularity/article.html#contributefragments_model
http://www.vogella.com/articles/EclipseRCP/article.html#commands_popup

But the described model alwayws refers to the application.e4xmi and not
just to a fragment.e4xmi. So I'm confused how to contribute because
sometimes "menu:" must be a prefix of the menu id to contribute to and
sometimes not. The attached file shows my fragment.e4xmi and my intends
to contribute a menu item but nothing happens. Would be nice if you
could give me some pointers to tutorials or any hints how to realise
this. Or maybe a good book would be nice, too.

best regards,
Gilbert


-------------------------------------------------------


<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands"
xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment"
xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu"
xmi:id="_IU2pYGCJEeK-fpTrs2yrzw">
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_LgthYGCJEeK-fpTrs2yrzw" featurename="commands"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command"
xmi:id="_S2HosGCJEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.commands.modifyFillColor"
commandName="Modify Fill Color of EClasses" description="Modifies the
fill color of each EClass in an open Ecore Tools Diagram Editor"
category="_mWvIoGCJEeK-fpTrs2yrzw"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_inHcQGCJEeK-fpTrs2yrzw" featurename="categories"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Category"
xmi:id="_mWvIoGCJEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.categories.ecoretoolsadditions"
name="Ecore Tools Additions" description="Some additional features for
the Ecore Tools"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_unv8kGCJEeK-fpTrs2yrzw" featurename="handlers"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler"
xmi:id="_xYe-0GCJEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.handlers.fillColorChangeHandler"
contributionURI="bundleclass://org.test.ecoretools.additions/org.test.ecoretools.additions.ModifyFillColorHandler"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_0b4XAGCMEeK-fpTrs2yrzw" featurename="toolBarContributions"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="menu:ToolBarContribution"
xmi:id="_1F4O4GCPEeK-fpTrs2yrzw" elementId="org.test.ecoretools.toolbar">
<children xsi:type="menu:HandledToolItem"
xmi:id="_PV008GCNEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.item" label="Modify Fill
Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_Q4ShsGCXEeK-fpTrs2yrzw" featurename="menuContributions"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="menu:MenuContribution"
xmi:id="_g19fUGCXEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menuitem"
parentId="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
<children xsi:type="menu:HandledMenuItem"
xmi:id="_aj-cgGCaEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</elements>
<elements xsi:type="menu:MenuContribution"
xmi:id="_e1RSkGCaEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menuitem"
parentId="menu:org.eclipse.ui.main.menu">
<children xsi:type="menu:HandledMenuItem"
xmi:id="_e1RSkWCaEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_QtvCEGCYEeK-fpTrs2yrzw" featurename="children"
parentElementId="org.eclipse.ui.main.menu">
<elements xsi:type="menu:Menu" xmi:id="_fsYLoGCYEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.menu" label="Ecore Tools Additions">
<children xsi:type="menu:HandledMenuItem"
xmi:id="_m81W8GCXEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_eLubwGCZEeK-fpTrs2yrzw" featurename="children"
parentElementId="org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
<elements xsi:type="menu:HandledMenuItem"
xmi:id="_i8654GCZEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_wQ-UcGCaEeK-fpTrs2yrzw" featurename="children"
parentElementId="menu:org.eclipse.ui.main.menu">
<elements xsi:type="menu:HandledMenuItem"
xmi:id="_wQ-UcmCaEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</fragments>
</fragment:ModelFragments>
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1001936 is a reply to message #1001806] Thu, 17 January 2013 10:30 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

In your fragment, create a new model fragment setting the 'Element Id' to your application id and the 'Featurename' to menuContributions. Then just add your new menu contributions.

You will either need to import existing commands or create a separate model fragment and define your commands there.

JD
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1001978 is a reply to message #1001936] Thu, 17 January 2013 11:32 Go to previous messageGo to next message
Eclipse User
Hi Joseph
one of my tries realises exactly what you wrote:

<fragments xsi:type="fragment:StringModelFragment"
xmi:id="_Q4ShsGCXEeK-fpTrs2yrzw" featurename="menuContributions"
parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="menu:MenuContribution"
xmi:id="_g19fUGCXEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menuitem"
parentId="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
<children xsi:type="menu:HandledMenuItem"
xmi:id="_aj-cgGCaEeK-fpTrs2yrzw"
elementId="org.test.ecoretools.modifyFillColor.menu.item" label="Modify
Fill Color of EClasses"
iconURI="platform:/plugin/org.test.ecoretools.additions/icons/EclassModified.png"
command="_S2HosGCJEeK-fpTrs2yrzw"/>
</elements>
</fragments>

I want to add the command to popup menu of the Ecore Tools Diagram
editor. Did I specify the property "parentId" right (I mean, is the
prefix "popup" needed)?

best regards,
Gilbert
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1003521 is a reply to message #1001806] Mon, 21 January 2013 07:33 Go to previous messageGo to next message
Eclipse User
Can somebody help me?

best regards,
Gilbert
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1004484 is a reply to message #1003521] Wed, 23 January 2013 05:34 Go to previous messageGo to next message
Eclipse User
I can't imagine that nobody knows this?

best regards,
Gilbert
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1004494 is a reply to message #1004484] Wed, 23 January 2013 05:50 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5245
Registered: July 2009
Senior Member
The 2nd article you reference makes no sense in a pure e4 app. If you
want to contribute to an existing menu-element in the base model you
need simply but in the id of it! No menu:-prefix an stuff is needed.

Tom

Am 23.01.13 11:34, schrieb Gilbert Mirenque:
> I can't imagine that nobody knows this?
>
> best regards,
> Gilbert
>
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1004629 is a reply to message #1004494] Wed, 23 January 2013 10:12 Go to previous messageGo to next message
Eclipse User
Hi,

Tom Schindl wrote:
> [..] No menu:-prefix an stuff is needed.

thank you Tom, that was the trick. It works now. But one left problem:
I added another menu contribution via my fragment but decided to remove
it. But the menu entry still appears in the menu. Why is this and how
can I make it disappear?

best regards,
Gilbert
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1004633 is a reply to message #1004629] Wed, 23 January 2013 10:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5245
Registered: July 2009
Senior Member
The model is persisted and on subsequent start ups the additional item
is coming from the persisted state, we don't yet have logic to clean it
up appropriately.

Tom

Am 23.01.13 16:12, schrieb Gilbert Mirenque:
> Hi,
>
> Tom Schindl wrote:
>> [..] No menu:-prefix an stuff is needed.
>
> thank you Tom, that was the trick. It works now. But one left problem:
> I added another menu contribution via my fragment but decided to remove
> it. But the menu entry still appears in the menu. Why is this and how
> can I make it disappear?
>
> best regards,
> Gilbert
>
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1004644 is a reply to message #1004633] Wed, 23 January 2013 10:29 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 328
Registered: December 2010
Location: Germany
Senior Member
The application model is saved in the workspace (data area).

If you start from the IDE you can check "Clear" with "workspace" on the "Main" Tab in the Run Configuration.

Alternativly you can start with -clearPersistedState.
Re: How to contribute a new menu item in an existing menu via a fragment? [message #1005001 is a reply to message #1004633] Thu, 24 January 2013 04:41 Go to previous message
Eclipse User
Is there a bug report which I can follow?
Previous Topic:Where to find the IServiceConstants?
Next Topic:In Eclipse 4.2, CTabFolder API not working same as Eclipse 3.7
Goto Forum:
  


Current Time: Sat Jul 26 09:21:13 EDT 2014

Powered by FUDForum. Page generated in 0.02929 seconds