Search code examples
eclipseeclipse-rcpeclipse-emfemfxmi

Creating custom menus with Eclipse e4 (using Application.e4xmi file) is not getting displayed during product launch (in debug mode)


I've created a new 'Eclipse 4 Application Project' using Luna and I created custom menu(s) using this 'Application.e4xmi' file. Also I've added a Handler Class that will be triggered when my custom menu is clicked (all these stuffs have been specified in the Application.e4xmi).

With this setup If I launch my product (as an Eclipse product) in debug mode, I'm not able to see my custom menus and also If I try to export as a product and trying to launch the eclipse product I'm running into problems.

xmi contents include :

<application:Application xmi:version="2.0"  xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_hHQuoFh2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ide.application" bindingContexts="_hHQuqVh2EeWNzdEqyCDxmA">
  <children xsi:type="basic:TrimmedWindow" xmi:id="_hHQuoVh2EeWNzdEqyCDxmA" label="com.ami.test.e4project" width="500" height="400"/>
  <handlers xmi:id="_6WD5YFh2EeWNzdEqyCDxmA" elementId="com.ami.test.e4project.handler.0" contributionURI="bundleclass://com.ami.test.e4project/com.ami.test.e4project.HandlerImplementation" command="_3T-ocFh2EeWNzdEqyCDxmA"/>
  <rootContext xmi:id="_hHQuqVh2EeWNzdEqyCDxmA" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
    <children xmi:id="_hHQuqlh2EeWNzdEqyCDxmA" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
    <children xmi:id="_hHQuq1h2EeWNzdEqyCDxmA" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
  </rootContext>
  <menuContributions xmi:id="_s3SAEFh2EeWNzdEqyCDxmA" elementId="com.ami.test.e4project.menucontribution.0" parentId="org.eclipse.e4.legacy.ide.application">
    <children xsi:type="menu:Menu" xmi:id="_z21zMFh2EeWNzdEqyCDxmA" elementId="com.ami.test.e4project.menu.filee" label="Filee">
      <children xsi:type="menu:HandledMenuItem" xmi:id="_0PiAAFh2EeWNzdEqyCDxmA" elementId="com.ami.test.e4project.handledmenuitem.new" label="New" command="_3T-ocFh2EeWNzdEqyCDxmA"/>
    </children>
  </menuContributions>
  <commands xmi:id="_3T-ocFh2EeWNzdEqyCDxmA" elementId="com.ami.test.e4project.command.command" commandName="command"/>
  <addons xmi:id="_hHQuolh2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
  <addons xmi:id="_hHQuo1h2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
  <addons xmi:id="_hHQupFh2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
  <addons xmi:id="_hHQupVh2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
  <addons xmi:id="_hHQuplh2EeWNzdEqyCDxmA" el ementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
  <addons xmi:id="_hHQup1h2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
  <addons xmi:id="_hHQuqFh2EeWNzdEqyCDxmA" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>

Solution

  • You are using menu contributions to a menu that does not exist (org.eclipse.e4.legacy.ide.application).

    When you create an e4 application using the Application.e4xmi there are no predefined menus or anything else. You must define the menus you want. Add a 'Main Menu' child to your 'Trimmed Window' and put the menu items there.