Hello,
I'm using e4 with the compatibility layer an want to expand the the main toolbar
My product definition is based on "org.eclipse.ui.ide.workbench" application.
So when I launch my product, the direct tool item isn't shown.
I added a fragment.e4xmi. This fragment contains:
<?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:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_i66q4Pt9EeKex-36mnvnVw">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_q25C8Pt9EeKex-36mnvnVw" featurename="children" parentElementId="org.eclipse.ui.main.toolbar" positionInList="after=additions">
<elements xsi:type="menu:ToolBar" xmi:id="_bWQKIPt-EeKex-36mnvnVw" elementId="myTest">
<children xsi:type="menu:DirectToolItem" xmi:id="_5jUbIPt9EeKex-36mnvnVw" elementId="directtoolitem.0" label="Test" iconURI="" contributionURI="bundleclass://documenteditor/test.MyTest"/>
</elements>
</fragments>
</fragment:ModelFragments>
But doesn't work ...
Second try was to do it programmatically.
<extension
id="id"
point="org.eclipse.e4.workbench.model">
<fragment
uri="fragment.e4xmi">
</fragment>
<processor
beforefragment="false"
class="test.MenuProcessor">
<element
id="org.eclipse.ui.file.menu">
</element>
</processor>
</extension>
The MenueProccesor is executed, but the MMenue is null and the window.getChildren() is empty. So what i have to do?
public class MenuProcessor
{
// I get this via the parameter
// of the process definition
@Inject
@Named("org.eclipse.ui.file.menu")
private MMenu menu;
@Inject
private MApplication application;
@Execute
public void execute()
{
System.out.println("hier");
// System.out.println("Starting processor");
// Remove the old exit menu entry
if (menu != null && menu.getChildren() != null)
{
List<MMenuElement> list = new ArrayList<MMenuElement>();
for (MMenuElement element : menu.getChildren())
{
System.out.println(element);
// Separaters have no label hence we
// need to check for null
if (element.getLabel() != null)
{
if (element.getLabel().contains("Exit"))
{
list.add(element);
}
}
}
menu.getChildren().removeAll(list);
// Now add a new menu entry
MDirectMenuItem menuItem = MMenuFactory.INSTANCE.
createDirectMenuItem();
menuItem.setLabel("Another Exit");
menuItem.setContributionURI("bundleclass://"
+ "com.example.e4.rcp.todo.contribute/"
+ MyTest.class.getName());
menu.getChildren().add(menuItem);
}
MWindow window = application.getChildren().get(0);
for (MWindowElement windowElement : window.getChildren())
{
System.out.println(windowElement.getElementId());
}
}
}
[Updated on: Mon, 05 August 2013 13:21]
Report message to a moderator