Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » e4 compatability layer: add toolbar item in main toolbar
e4 compatability layer: add toolbar item in main toolbar [message #1080081] Mon, 05 August 2013 08:50 Go to next message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
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 Sad...

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 09:21]

Report message to a moderator

Re: e4 compatability layer: add toolbar item in main toolbar [message #1080107 is a reply to message #1080081] Mon, 05 August 2013 09:28 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 596
Registered: December 2010
Senior Member

https://bugs.eclipse.org/bugs/show_bug.cgi?id=376486
Re: e4 compatability layer: add toolbar item in main toolbar [message #1080165 is a reply to message #1080107] Mon, 05 August 2013 10:55 Go to previous message
Sir Wayne is currently offline Sir Wayne
Messages: 206
Registered: July 2009
Senior Member
Ahhh thanks
Previous Topic:Loading data when Application starts
Next Topic:IMenueService and CoolbarManager
Goto Forum:
  


Current Time: Mon Jul 28 22:42:34 EDT 2014

Powered by FUDForum. Page generated in 0.02785 seconds