tutorial : eclipse rcp e4 with 3.x views like project explorer, properties, etc.

This tutorial shows step-by-step how to add classical Eclipse 3.x views like Project Explorer and the Properties View to an Eclipse e4 Rich Client Platform (RCP) Application.

Eclipse 4.2 was released a few weeks ago with the new e4 platform that basically uses an EMF model to describe how your application looks and feels. While this is neat, the caveat is that e4 currently (August 2012) does not provide views for a number of core features of the old Eclipse 3.x platform including things like the Project Explorer, a Properties View and the like.

Eclipse 4.2 comes with a “Compatibility Layer” that makes all the old features that were not ported yet to e4 available. However, I could not find a site that tells me how to use it. There are a few quite instructive tutorials out there on how RCP applications with e4 work, for instance http://www.vogella.com/articles/EclipseRCP/article.html. But none showed me how to add a Project Explorer and all the IDE views that I needed for my projects (http://service-technology.org/seda and http://service-technology.org/greta in case you want to know). So I went for the usual approach in the Eclipse-verse: trial and error. Here is what I figured out and works for me.

For the rest of this tutorial I assume you are familiar with building Eclipse 3.X RCP applications. Please consult a more complete tutorial such as http://www.vogella.com/articles/EclipseRCP/article.html to get into the topic or refresh some details. To get a code-base to try out the things I talk about next, create a new RCP project using File > New Project > Plug-In Project, give it a name (let’s call it test.rcp here), and pick the Hello RCP Template to create the project.

  1. To use the “Compatibility Layer” of Eclipse 4, do not run an e4-based application, but run a classical Eclipse application. An Eclipse RCP consists of two things: an application, and a product. The product defines the look and feel of the RCP, the application provides the “framework” on which this look and feel can be pinned. e4 does not allow to pin the “Compatibility Layer”. Instead, we use a classical application (backed by Eclipse 4.X plugins) and add an “e4 aware product” on top of it. This solution has the drawback that some parts of your RCP application have to be defined in code. Yet some parts can be defined by the e4 model and become a lot easier.
  2. Add an e4 application model file to the RCP project: File > New > Eclipse 4 > Model > New Application Modeltest.rcp as container, give it the name Application.e4xmi, and check Include Default Addons. In this file we will later put all the fancy model definitions of our RCP application. But first we have to prepare a few other things.
  3. Register a new product definition in the RCP project: edit plugin.xml and insert the following product definition
    <extension id="product_test" point="org.eclipse.core.runtime.products">
      <product application="test.rcp.application" name="My Product">
        <property name="appName" value="My App"> </property>
        <property name="applicationXMI" value="test.rcp/Application.e4xmi"> </property>
      </product>
    </extension>
    

    where test.rcp.application refers to the Eclipse 3.X application defined in the RCP plugin at the org.eclipse.core.runtime.applications extension point, and test.rcp/Application.e4xmi refers to the application model file we just created.

  4. Create a new product configuration file using the File > New > Plug-In Development > Product Configuration wizard. Put the file in your RCP plugin (test.rcp), give it a name (test.rcp.product), and Initialize the file content using the existing product we just defined: test.rcp.product_test (where product_test stems from the id given in the extension point. You can configure various things like names and ids etc. The most important settings are the following.
  5. Link the product to Eclipse 3.X application by setting in test.rcp.product on the Overview Tab the Application to test.rcp.Application (as in the plugin.xml).
  6. Add required Eclipse 3.X and Eclipse e4 features to your product. To run the product, you will need a bunch of plugins and features from Eclipse which you can configure in the product configuration. Make it based on features (there are other solutions, but I prefer this one), open the Dependencies tab, add org.eclipse.e4.rcp and click the Add Required button which will add org.eclipse.emf.core and org.eclipse.emf.common to the product configuration.
  7. Define a Main Application Window. In the old eclipse world you would now be good to go and run the product. With e4, you aren’t. We have to define the look and feel of the application in the Application.e4xmi. Open the file and at Application > Windows add a new TrimmedWindow. You can configure various things here, but we will leave it for now.
  8. Run the application to test if things are good so far: right click on test.rcp.product and select Run As > Eclipse Application. The launch will probably fail, edit the launch configuration in Run > Run Configurations…, open the Plugins tab, select Launch with ‘plug-ins selected below only, check your RCP plugin test.rcp and click on Add Required Plug-ins to get all Eclipse plugins that are needed to run your application. When you click on Run an application windows looking like this should show up.

    In case your product does not launch and raises further errors, check whether there are VM arguments of your launch configuration that conflict with the available Java runtime.
  9. Define ‘shared elements’ that access Eclipse 3.x compatibility layer. Now comes the first step to actually enable Eclipse 3.x in your application. As the current editor for the Application.e4xmi has some limitations, we have to do some xml editing. Take a short-cut and replace the contents of your Application.e4.xmi with this code:
    <?xml version="1.0" encoding="UTF-8"?>
    <application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" 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="_VnmacNSzEeGBn6dQ9VPexA" elementId="test.rcp.application" bindingContexts="_VnmacdSzEeGBn6dQ9VPexA">
      <children xsi:type="basic:TrimmedWindow" xmi:id="_Vnmah9SzEeGBn6dQ9VPexA" label="My Main Window" iconURI="" width="800" height="600">
        <children xsi:type="advanced:PerspectiveStack" xmi:id="_Vnmaj9SzEeGBn6dQ9VPexA" selectedElement="_VnmakNSzEeGBn6dQ9VPexA">
          <children xsi:type="advanced:Perspective" xmi:id="_VnmakNSzEeGBn6dQ9VPexA" elementId="test.rcp.perspective" selectedElement="_VnnBgNSzEeGBn6dQ9VPexA" label="My Perspective" iconURI="">
            <tags>Perspective</tags>
            <tags>categoryTag:General</tags>
            <children xsi:type="basic:PartSashContainer" xmi:id="_VnnBgNSzEeGBn6dQ9VPexA" horizontal="true">
              <children xsi:type="basic:PartStack" xmi:id="_VnnBgdSzEeGBn6dQ9VPexA" containerData="3400">
                <tags>newtablook</tags>
                <tags>org.eclipse.e4.primaryNavigationStack</tags>
                <children xsi:type="advanced:Placeholder" xmi:id="_QR29cNS2EeGBn6dQ9VPexA" elementId="org.eclipse.ui.navigator.ProjectExplorer" ref="_sS7Q8NS1EeGBn6dQ9VPexA"/>
              </children>
              <children xsi:type="basic:PartSashContainer" xmi:id="_bTQ1YNS2EeGBn6dQ9VPexA" elementId="" containerData="10000">
                <children xsi:type="advanced:Placeholder" xmi:id="_hP-EYNS2EeGBn6dQ9VPexA" elementId="org.eclipse.ui.editorss" ref="_Hmg4kNSjEeGwXp2p959l3w"/>
                <children xsi:type="basic:PartStack" xmi:id="_qAHrYNS2EeGBn6dQ9VPexA" elementId="org.eclipse.ui.views.PropertySheetMStack" containerData="3400" selectedElement="_soNH8NS2EeGBn6dQ9VPexA">
                  <tags>newtablook</tags>
                  <tags>org.eclipse.e4.secondaryDataStack</tags>
                  <children xsi:type="advanced:Placeholder" xmi:id="_soNH8NS2EeGBn6dQ9VPexA" elementId="org.eclipse.ui.views.PropertySheet" ref="_WqRGcNS1EeGBn6dQ9VPexA"/>
                </children>
              </children>
            </children>
          </children>
        </children>
        <sharedElements xsi:type="advanced:Area" xmi:id="_Hmg4kNSjEeGwXp2p959l3w" elementId="org.eclipse.ui.editorss">
          <children xsi:type="basic:PartStack" xmi:id="_HmhfoNSjEeGwXp2p959l3w" elementId="org.eclipse.e4.primaryDataStack">
            <tags>newtablook</tags>
            <tags>org.eclipse.e4.primaryDataStack</tags>
            <tags>EditorStack</tags>
          </children>
        </sharedElements>
        <sharedElements xsi:type="basic:Part" xmi:id="_WqRGcNS1EeGBn6dQ9VPexA" elementId="org.eclipse.ui.views.PropertySheet" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView" label="Properties" iconURI="platform:/plugin/org.eclipse.ui.views//icons/full/eview16/prop_ps.gif" closeable="true">
          <tags>View</tags>
          <tags>categoryTag:General</tags>
          <menus xmi:id="_HngXENSjEeGwXp2p959l3w" elementId="org.eclipse.ui.views.PropertySheet">
            <tags>ViewMenu</tags>
            <tags>menuContribution:menu</tags>
          </menus>
          <toolbar xmi:id="_Hng-INSjEeGwXp2p959l3w" elementId="org.eclipse.ui.views.PropertySheet"/>
        </sharedElements>
        <sharedElements xsi:type="basic:Part" xmi:id="_sS7Q8NS1EeGBn6dQ9VPexA" elementId="org.eclipse.ui.navigator.ProjectExplorer" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView" label="Project Explorer" iconURI="platform:/plugin/org.eclipse.ui.navigator.resources//icons/full/eview16/resource_persp.gif">
          <tags>View</tags>
          <tags>categoryTag:General</tags>
          <menus xmi:id="_4UXAUNSmEeG-a6zBTyJ-wg" elementId="org.eclipse.ui.navigator.ProjectExplorer">
            <tags>ViewMenu</tags>
            <tags>menuContribution:menu</tags>
          </menus>
          <menus xsi:type="menu:PopupMenu" xmi:id="_4VpZwNSmEeG-a6zBTyJ-wg" elementId="org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
            <tags>menuContribution:popup</tags>
            <tags>popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu</tags>
          </menus>
          <toolbar xmi:id="_4UXAUdSmEeG-a6zBTyJ-wg" elementId="org.eclipse.ui.navigator.ProjectExplorer"/>
        </sharedElements>
        <trimBars xmi:id="_VOV6ANTAEeGTY-uOtVc6Mg" elementId="org.eclipse.ui.main.toolbar"/>
        <trimBars xmi:id="_VP1HwNTAEeGTY-uOtVc6Mg" elementId="org.eclipse.ui.trim.status" side="Bottom">
          <children xsi:type="menu:ToolControl" xmi:id="_VP1u0NTAEeGTY-uOtVc6Mg" elementId="org.eclipse.ui.StatusLine" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.StandardTrim">
            <tags>stretch</tags>
          </children>
          <children xsi:type="menu:ToolControl" xmi:id="_VQKe8NTAEeGTY-uOtVc6Mg" elementId="org.eclipse.ui.HeapStatus" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.StandardTrim"/>
          <children xsi:type="menu:ToolControl" xmi:id="_VQRMoNTAEeGTY-uOtVc6Mg" elementId="org.eclipse.ui.ProgressBar" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.StandardTrim"/>
        </trimBars>
      </children>
      <bindingTables xmi:id="_VnmafNSzEeGBn6dQ9VPexA" bindingContext="_VnmacdSzEeGBn6dQ9VPexA"/>
      <rootContext xmi:id="_VnmacdSzEeGBn6dQ9VPexA" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
        <children xmi:id="_VnmactSzEeGBn6dQ9VPexA" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
        <children xmi:id="_Vnmac9SzEeGBn6dQ9VPexA" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
      </rootContext>
      <descriptors xmi:id="_9E9jYNS4EeGBn6dQ9VPexA" elementId="org.eclipse.ui.navigator.ProjectExplorer" label="Project Explorer" iconURI="platform:/plugin/org.eclipse.ui.navigator.resources//icons/full/eview16/resource_persp.gif" category="org.eclipse.e4.primaryNavigationStack" closeable="true" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView">
        <tags>View</tags>
        <tags>categoryTag:General</tags>
      </descriptors>
      <descriptors xmi:id="_W6yT4NSjEeGgKvWHVYtRxQ" elementId="org.eclipse.ui.console.ConsoleView" label="Console" iconURI="platform:/plugin/org.eclipse.ui.console//icons/full/cview16/console_view.gif" allowMultiple="true" category="org.eclipse.e4.secondaryDataStack" closeable="true" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView">
        <tags>View</tags>
        <tags>categoryTag:General</tags>
      </descriptors>
      <descriptors xmi:id="_W6ziANSjEeGgKvWHVYtRxQ" elementId="org.eclipse.ui.views.ProgressView" label="Progress" iconURI="platform:/plugin/org.eclipse.ui.ide//icons/full/eview16/pview.gif" category="org.eclipse.e4.secondaryDataStack" closeable="true" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView">
        <tags>View</tags>
        <tags>categoryTag:General</tags>
      </descriptors>
      <descriptors xmi:id="_W63zcdSjEeGgKvWHVYtRxQ" elementId="org.eclipse.ui.views.PropertySheet" label="Properties" iconURI="platform:/plugin/org.eclipse.ui.views//icons/full/eview16/prop_ps.gif" allowMultiple="true" category="org.eclipse.e4.secondaryDataStack" closeable="true" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView">
        <tags>View</tags>
        <tags>categoryTag:General</tags>
      </descriptors>
      <addons xmi:id="_VnmadNSzEeGBn6dQ9VPexA" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
      <addons xmi:id="_VnmaddSzEeGBn6dQ9VPexA" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
      <addons xmi:id="_VnmadtSzEeGBn6dQ9VPexA" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
      <addons xmi:id="_Vnmad9SzEeGBn6dQ9VPexA" 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="_VnmaeNSzEeGBn6dQ9VPexA" 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="_VnmaedSzEeGBn6dQ9VPexA" 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>
    
  10. Understand a basic Application Window layout This definition does a lot of small things. Technically, a few additional namespaces are made available to the application:Application element to use some of the more advanced features. Besides some key binding handlers, the main changes are: shared elements for the main window which define some kind of placeholders for UI contributions. These placeholders are used in the definition of the main window.e4 Application Model of the Main Window using a Project Explorer and Editor Area and a Properties ViewThe Main Window defines Controlswhich are all the parts a user can interact with.
    1. It’s main children is a Perspective (also set as the main perspective of that window) that contains two PartSashContainers.
    2. A PartSashContainer splits the window into several areas (one area for each of its child elements) that have an adjustable width or height, depending on the orientation of the PartSashContainer.
    3. A PartStack is an area where several views can be stacked on top of each other, the different views on such a stack that can all be accessed using tabs at the top of the PartStack as we know it from the Eclipse IDE.
    4. The Placeholders refer to the Shared Elements that we defined as well.
    5. In addition we defined TrimBars, one for the main menu and one for the status bar the bottom for which we also define some default contents such as a progress indicator.
    6. The Shared Elements themselves are where the magic lies. For instance, the Project Explorer is defined by a shared element that defines a Part with the elementId="org.eclipse.ui.navigator.ProjectExplorer" that is made available by the Compatiblity Layer, defined at the URI contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView"
  11. To run the new application, we need a few more plugins that provide the code for the Project Explorer etc. Open the plugin.xml of your RCP plugin (test.rcp) and add the following plugins to its dependencies
    1. org.eclipse.ui.views
    2. org.eclipse.ui.navigator
    3. org.eclipse.ui.navigator.resources

    When you run the application, you should now see the following window.
    Eclipse e4 RCP application with Project Explorer and Properties view
    Notes:

    1. You may have to add more Required Plugins to your launch configuration.
    2. You may have to delete the file ${runtime-workspace}/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi in the runtime-workspace used by your application. This file is created during startup from the Application.e4xmi and after that is used to remember the layout of the window etc. Changes in Application.e4xmi are not copied to the workbench.xmi file.
  12. Last Step: Enable the workspace resources. In the current application, you will not be able to see and use workspace resources such as projects and files. To actually use them, we need to initialize the IDE workspace of Eclipse. In the ApplicationWorkbenchAdvisor.java (generated by the Hello RCP in package test.rcp), override the initialize(...) method (taken from stackoverflow.com)
    ...
    import org.eclipse.core.runtime.Platform;
    import org.eclipse.jface.resource.ImageDescriptor;
    import org.eclipse.ui.ide.IDE;
    import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
    import org.osgi.framework.Bundle;
    ...
    
    @Override
    public void initialize(IWorkbenchConfigurer configurer) {
    	super.initialize(configurer);
    	...
    	// inserted: register workbench adapters
    	IDE.registerAdapters();
    
    	// inserted: register images for rendering explorer view
    	final String ICONS_PATH = "icons/full/";
    	final String PATH_OBJECT = ICONS_PATH + "obj16/";
    	Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
    	declareWorkbenchImage(configurer, ideBundle,
    		IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + "prj_obj.gif", true);
    	declareWorkbenchImage(configurer, ideBundle,
    		IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT + "cprj_obj.gif", true);
    }
    
    private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p,
    		Bundle ideBundle, String symbolicName, String path, boolean shared) {
    	URL url = ideBundle.getEntry(path);
    	ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    	configurer_p.declareImage(symbolicName, desc, shared);
    }
    

    If you do not have any ApplicationWorkbenchAdvisor.java, your Eclipse RCP is probably not built on the Eclipse 3.X framework. Use the Hello RCP template to get a basic structure of your application, including this class, or consult an Eclipse 3.X RCP tutorial. Finally, add plugin org.eclipse.ui.ide to the dependencies of your RCP plugin project in the plugin.xml. The application should now look like this:
    Eclipse e4 RCP application with project explorer, text editor and properties view

Done. You can now extend your application through code as well as through the e4 application model and have access to the Eclipse 3.x views, including other views like the Problems View or the Error Log.

Update 2015-08-24: if in the final application the ProjectExplorer content is not visible by its own (but only after you forced an updated, e.g., via opening the context menu with a right-click), try this: override the getDefaultPageInput() method of the ApplicationWorkbenchAdvisor and add the following line:

return ResourcesPlugin.getWorkspace().getRoot();

(thanks Alexander for the hint)

73 thoughts on “tutorial : eclipse rcp e4 with 3.x views like project explorer, properties, etc.

  1. Great article, thank you for writing about Eclipse 4. I have a question to your statement about the Eclipse 4 application model editor (As the current editor for the Application.e4xmi has some limitations), which limitation do you see, we can try to fix them.

  2. Hi Ravi,
    It is a very interesting article!!
    After finishing it, I could add the Console, too.
    However, I don’t know how to use the Project Navigator and Console, or even how to add a simple customized View.
    I tried adding simple view as Lars teaches in Eclipse 3 and 4 tutorials, but it is not working over the project I created following your tutorial: “eclipse rcp e4 with 3.x views …”
    Please, could you give just more few steps on how to add a simple view or just how to do a simple thing over the Project Navigator you added?

    Thanks,
    Vítor Moscon

    • Whats explained in thsi tutorial works well and all 3.x editors are also working just fine as were expected from compatibility layer. But the problem is, when I add PartStack and Parts according to E4 directly from Application.e4xml file, it doesnt show up. Any thoughts?

      • solution:… You got to remove workbench.xmi everytime you do the layout change in e4xml file…

        #cd runtime-x.y.product/.metadata/.plugins/org.eclipse.e4.workbench
        #rm -f workbench.xmi

        and the run your application. New workbench.xmi will be generated and all your changes would be there

  3. Whoa, now that I’d basically given up hope (and had accomodated myself with the full platform, meh), I stumble across this.
    Great article.

  4. Thanks for the great information. I am able to now get the eclipse3 Properties VIew to show up in my E4 application (well, now e3 w/ e4 model application).

    However, I am not able to get the Properties View to see my selected items that implement IPropertySource. So nothing shows up in the Properties View. I suspect this is because the selection model has changed between E3 and E4.

    In E3 I would have done something like:
    .getSite().setSelectionProvider(viewer);
    to get selection events to start firing and the Properties View would have seen these.

    In E4 you add yourself to the viewer as a selection change listener and then in the handler you tell the E4 ESelectionService that something has changed selection.
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    // set the selection to the service
    selectionService.setSelection(
    selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
    }
    });

    My guess is that the E3 Properties View doesn’t know anything about this ESelectionService and I am not sure if there is something to ‘tweak’ in the CompatibilityLayer that is used in this demo. Or is there some way to still get the old ViewPart and use the E3 selection service.

    Thanks,
    kable

  5. I just want to say that the last 3 – obviously spam – comments (from April 18-23) are absolutely hilarious :).

    Also, thanks Dirk for very useful tutorial.

  6. Thank you very much. I had been searching for 3 days about using 3x views for e4 before found this article. It helps me a lot!!!!

  7. Thanks for sharing your experience. I managed to get it to build & run under eclipse 43 (Kepler)

    I’ve uploaded my effort to gitGUB https://github.com/stevej2608/test.rcp

    I have a problem with the project explorer needing a r-click before it will display the tree. I’ll try and resolve this.

    Thanks again, Steve

  8. I am new to eclipse RCP development and I get stuck in the first section of the walkthrough:

    “where test.rcp.application refers to the Eclipse 3.X application defined in the RCP plugin at the org.eclipse.core.runtime.applications extension point, and test.rcp/Application.e4xmi refers to the application model file we just created.”

    I have created a plugin-project, but I am usure where you are referrign to when you mention the “Eclipse 3.X application”. As far as I follow it, we just created an e4 application (via it’s model file).

    Could anyone explain where my thinking is wrong? Any help is appriciated greatly.

    Pim van Nierop
    VU University Amsterdam

    • To give more insight into what I am doing:

      ad init. I created the pugin-project
      ad 2. I Created a new e4 Application Model config file
      ad 3.1. Added the xml fragment as shown in the plugin.xml
      ad 3.2. I created the following extension to org.eclipse.core.runtime.applications in the plugin.xml.

      This is not indicated in the text, but I guess this creates a 3.x style application definition. I fact, addign this xml fragment correcly allows me to perform the step 5.
      ad 4. Created a product definition.
      ad 5. Added the 3.x style application to the product.
      ad 6. Added application window.

      After fixing the plugin dependencies I get an error that, as far as I could deduce, relates to the 3.x style application:
      “!ENTRY org.eclipse.osgi 4 0 2013-08-14 14:29:07.274
      !MESSAGE Application error
      !STACK 1
      org.eclipse.core.runtime.CoreException: Executable extension definition for “run” not found.”

      So, is the example in this tutorial not self contained? Does it assue I have a running 3.x application somewhere?

    • It turned out I needed to add a ‘run’ item to the 3.x application in the plugin.xml. My application extension now looks like (I hope to get the xml structure displayed, I am unfamiliar with wprdpress markup):

      |extension
      id=”test.rcp.application”
      point=”org.eclipse.core.runtime.applications”|
      |application
      cardinality=”singleton-global”
      thread=”main”
      visible=”true”|
      |run
      class=”test.rcp.Application”|
      |/run|
      |/application|
      |/extension|

      I have to create a new Application Java class file that implements IApplication. However, when running the product I get no windows and the console message:

      gogo: InterruptedException: sleep interrupted
      java.lang.InterruptedException: sleep interrupted
      at java.lang.Thread.sleep(Native Method)
      at org.apache.felix.gogo.shell.Activator.run(Activator.java:72)
      at java.lang.Thread.run(Thread.java:722)

    • I have sorted out what was giving me problems. For reference I will state the solution here. Please feel free to clear up my messages if desired.

      The cause of my problem is that in the eclipse 4.3 sdk I did not create the initial plugin-project with the option “Would you like to create a 3.x rich client application?” as “Yes”. When you do this the “Hello RCP” template becomes available.

  9. Hi Dirk,
    Its a great article. Thanks for that.
    I have created one e4 application model project which consists of a trimmed window (say window name as “analysis”) with some parts on it. When i launch this project everything is fine as expected.
    Now i want to modify this project in such a way that, i need to create one more window( with a part which has a button, say “Open analysis window”) , which should become my first window when i run this project and clicking on this button should launch the trimmed window which i created earlier using e4 application model.

    Is it possible to do so?…Please help

  10. Great article, which helped me a lot. I am currently trying to get an Xtext generated editor (based on IEditorPart) to display in the placeholder “org.eclipse.ui.editorss”. Is this possible? I am struggling to bring the two worlds (e3 and e4) to speak to each other at this point.

    Any hint would be appreciated.

    • Yes, I am struggeling with sort of the same problem. How can a e4 MInputPart be started on a file/resource that is double clicked in the e3 Project Explorer.

      • I think your problem is different from mine.

        I got my editor to show up by simply opening it from the IWorkbenchPage injected into my OpenEditorHandler:

        public class OpenEditorHandler {
        @Execute
        public void openItem(@Named(IServiceConstants.ACTIVE_SELECTION) MyModelItem item, IWorkbenchPage page) {
        IEditorInput input = … ; // something based on the item’s nature and location
        page.openEditor(input, EDITOR_ID);
        }

        where EDITOR_ID is the id of your editor contributed to org.eclipse.ui.editors in your xtext.ui plugin.

      • Wernke, would you allow me to ask you for additional info about this via email? I am a novice in this and I would like to get working what you suggest here.

      • How did you couple the “open file” event that is tiggered from double clicking a file in the 3.x Project Explorer to a 4.x Handler class that uses dependency injection? I understand your OpenEditorHandler, but I do not know how to couple it to the Project Explorer. Thnx.

    • Hi Pim, I am not using the project explorer. Your case should be straightforward though. If you register your editor to the extension point org.eclipse.ui.editors it should open on its own when you double click a file with the registered extension. No own handler needed.

  11. Hi,
    thank you very much for this tutorial. It saved me a lot of time.
    But I still have one anoying problem. Implementing the Project Explorer or Package Explorer ( doesn’t matter) worked just fine, but a few key bindings are not working one them.
    In my case DEL, COPY, PASTE don’t work, but bindings like RENAME do work.
    Do you maybe have any idea why that is?

    • I got it working, but just with an ugly workaround. Since the DEL key is working in the editor, i assumed that it is at least working in that context. And because rightclick->DEL in the project explorer is also working, I figured it would be best to built a handler that checks for the different contexts and than calls the appropriate command. So here it is…maybe someone knows a better way. Because this way might not work once you have another part with a different context.

      public class DeleteKeyHandler{

      @Execute
      public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, EHandlerService hService, ECommandService cService, EContextService context) {

      for (String tmp : context.getActiveContextIds()) {
      if (tmp.equals(“org.eclipse.ui.textEditorScope”)) {
      Command command = cService.getCommand(“org.eclipse.ui.edit.delete”); //Context: [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window, org.eclipse.ui.textEditorScope, org.eclipse.xtext.ui.XtextEditorScope]
      if (command.isDefined()) {
      ParameterizedCommand cmd = cService.createCommand(“org.eclipse.ui.edit.delete”, null);
      if (hService.canExecute(cmd)) {
      hService.executeHandler(cmd);
      }
      }
      return;
      }
      }
      Command command = cService.getCommand(“org.eclipse.ltk.ui.refactoring.commands.deleteResources”); //Context: [org.eclipse.ui.contexts.dialogAndWindow, org.eclipse.ui.contexts.window]
      if (command.isDefined()) {
      ParameterizedCommand cmd = cService.createCommand(“org.eclipse.ltk.ui.refactoring.commands.deleteResources”, null);
      if (hService.canExecute(cmd)) {
      hService.executeHandler(cmd);
      }
      }
      }
      }

  12. Thank you for your Help!!!

    When I tried this, I faced some critical problem…..

    In Application.e4xmi file, I tried to make command and handler, then I make ‘HandledMenuItem’ in Main Menu…. But when I run my application, that menu does not work. (@Execute method in Handler, I make some logs…but does not printed…..T_T)…

    Maybe,….. This is Start with e3 Application LifeCycle… (related to Application, WorkbenchAdvisor…etc…) But Handler (and Injection..) must be start with E4.Application LifeCycle..(right?) So, my Handler does not triggered…I think…

    Does any Solution for this problem?

    (I am a Korean.. So My English is terrible…Sorry..T_T)

  13. As I mentioned in a reply above a problem then a solution – I will list down a few more general problems I faced and their solution for others’ eyes in case they also hit same thing as these issue wasted a few hours of my time…

    Problem1: Any additional parts you add as per e4 practice in e4xml file – it wont appear when you run.
    Solution: You got to remove workbench.xmi everytime you do the layout change in e4xml file…
    #cd runtime-x.y.product/.metadata/.plugins/org.eclipse.e4.workbench
    #rm -f workbench.xmi
    and the run your application. New workbench.xmi will be generated and all your changes would be there.

    Problem2: Newly added part class referenced in ‘Class URI’ field of part; wont invoke code in @postConstruct and @preDestroy dependency injection annotations
    Solution: By default E3 plugin initially created is not picking the right version of javax.annotations. Go to plugin.xml and add ‘imported packages’ in the Dependency Tab; select ‘javax.annotations 1.1.0’

  14. Excellent Tutorial!!!
    I tried to do something similar, but starting from the mail RCP Template …
    I tried to replace the class corresponding to the ProjectExplorer (removed from plugin.xml) with a part descriptors in the corresponding application.e4xmi … and I don’t get it to work and get only a “Could not create the view: com.eclipse-tips.rcp.mail.navigationView” …
    Any help is appreciated

  15. I am trying to add an handler to the process explorer (implemented via the Navigationview class of the RCP mail plug-in template) but no success … of course I delete workbench file, but I get no error and nothing show up in console( my handler class does just that and nothing more right now).
    In Application.e4xmi I have added category/command/handlers … but nothing shows up.
    I tried a generic Part -Explorer -> Handler and a Part-Explorer->Menus->Popup Menu

    and here’s my handler:
    package test.rcp;
    import org.eclipse.e4.core.di.annotations.Execute;
    public class MessagePopupAction {

    @Execute
    public void execute(){
    System.out.println((this.getClass().getSimpleName() + ” called”));

    };

  16. What about the standard IDE menus? I followed the example (in Eclipse 4.4) and I get a “Hello RCP” window, much like in the screen shot above. However, I do not get any of the standard menus (File, Help, …). I only get a “My Product” menu.

  17. Pingback: How to add project explorer,Outline and Property Table views in to eclipse rcp application | Computer science, programming and Eclipse RCP

  18. Dirk,. Thank you kindly for this post.

    I’m very new to Eclipse RCP and maybe I don’t understand all of this enough. I am working with Eclipse 4.4 and e4 Application Model. Is there a way to do this strictly in e4 without using 3.x compatibility layer on any level?. Specifically I am looking to populate the table in the properties page with data from the selected object which is selected in the Project Manager. Any link to helpful tutorials on how to experiment with this would be most appreciated. Is there a simple way to do this, or will I simply have to run the getter methods on the selected object and then populate the table from that data?
    – Anthony

    • Dear Anthony,

      as far as I know, e4 does not provide a properties component that you could fill. You would have to rebuild that yourself in e4. If you want to use the existing properties component, then you have to see the e3 layer.

      Dirk

  19. Dirk,
    thank you for the tutorial. I followed your instructions and now I’m wondering about the following issue:
    When running the application I always get the errors
    “Product iec61850ETCompat.product could not be found.” and
    “java.lang.RuntimeException: No application id has been found.” if I don’t check my own project in the run configurations Plug-in tab each time I want to run it.
    Furthermore another product extension point is added to my plugin.xml though I already defined the one in step 3.
    Could you point me out what I am doing wrong?

  20. Dirk,
    We have our product well in shape with rcp 3.x and development IDE is eclipse indigo. My product is having many legacy views like Project Explorer and console.
    Now we want to migrate it to rcp 4 and IDE will Mars.1

    Do you see any issue to migrate to rcp4 ? Please suggest if there is any potential problems ?

    Can you give suggestions for migration.

    • I don’t have much experience with migrating RCP 3.x to 4, just for one product based on which I wrote this tutorial. I think everything is there, i.e., you won’t loose functionality, but finding the right hooks in RCP 4 to get them all in can be quite time consuming as you have to synchronize the way the legacy views get on the UI (via API code) with the e4 way (models).

      • Hello Dirk,
        Thanks for your reply.

        Yes migration and getting 3.x legacy components to RCP4 is quite time consuming process but somehow i managed and migrated my legacy 3.x components successfully.

        Now i am facing issue with CSS.

        CSS is working over RCP4 also with my existing 3.x CSS setup but few specific things are not working after migration.

        CSS is not applied to CoolBar,Banner on RCP4 and extra space is added prior to ToolBar contribution.

        Can i get any help ??

        Snippet of CSS :-
        CBanner,CoolBar,CTabFolder,ToolBar{
        background-color: rgb(82,84,81);
        }

        CoolBar and Banner is not working on RCP4.

  21. Hello,
    Above issue is fixed with using proper class names and identifiers respectively but extra spaces are added prior to ToolBar is not fixed.

    Any Help?

    Thanks,
    Kiran.

    • Hi Kiran, good to hear that you solved the CSS issue as I am not familiar with that part of e4. As for the extra spaces added prior to ToolBar: I experienced that myself as well and I think (but am not sure) that it is because both 3.X and e4 both contribute toolbars in their own way. The empty space most likely originates in an empty 3.X toolbar provided by the legacy layer/some view. That’s all I recall from the time of writing the tutorial. I hope this helps you a bit further.

      Dirk

  22. Hello Dirk,

    Fantastic article! Thanks a lot!

    A basic question. It is now 2016. If I want to write an e4 application, and I want to use the common navigator framework (CNF) and use extensions for using the team functionality (e.g. SVN/Git integration), do I still need to use the compatibility layer? Is there no “native” e4 support? If yes, any hints to any links or APIs? I have looked around, but I can see of no mention of being able to use CNF e.g. in an e4 application.

    Thanks in advance!
    Kind regards,
    Abhi

  23. Hello Dirk,
    I followed your tutorial with my e3 application and I have an exception at the launch:
    ERROR ui.ApplicationWorkbenchAdvisor – Unable to process “PartServiceImpl.engine”: no actual value was found for the argument “IPresentationEngine”.
    There is another way to use e3 application with e4 ? I didn t find another concrete tutorial to migrate e3 to e4.

    • Hi Anael, I haven’t seen that problem before. My closest guess would be some missed or wrong configuration somewhere. Try doing the tutorial again down to the last comma and point. Maybe that fixes it. Sorry, Dirk

  24. Hi Dirk,
    thanks for this very helpful tutorial.
    I am using NEON (4.6) to implement your tutorial. All wokrs fine except the icons of the project explorer, I don’t mind to have no menu for the moment. The project icon is missing at all, its just a small red square. The folder and text file icons are fine but the text its too close to the icons.
    I think the icons should be in org.eclipse.ui.ide and this plugin is included but it dies not help at all.

    Do you have any idea how to have propper icons displayed?

    • Hi Martin,
      I had same problems.
      Replace *.gif to *.png, It works fine for me.

      Since Neon, gif images seem to be removed from org.eclipse.ui.ide .

      thanks.

    • Hi Martin!

      I am also following the tutorial using NEON and I get stack in step 11 when I add these 3 plug-ins. Do we need any additional plug-ins apart from these ones? (otherwise it gives me RuntimeException and does not execute)

      Cheers!

  25. Hi ,

    How to get rid of default context menu on project explorer ? I want to override all the context menu such as new, open with, and so .. I am not able to figure out to remove the context menu option and unable to add my pop-up menus

  26. This tutorial was still helpful years later, much appreciated!

    Bit of a word of warning: I didn’t copy-paste because I was only interested in getting the old editor view, and it seems like the newest editors for .e4xmi files at least gave me no issues entering in what I needed to visually, but in doing so I got tunnel vision and put the placeholder that referenced the editor area (The Area of id org.eclipse.ui.editorss) underneath a Part Stack and not a Part Sash Container, which caused a ClassCastException at runtime:

    org.eclipse.e4.ui.model.application.ui.advanced.impl.AreaImpl cannot be cast to org.eclipse.e4.ui.model.application.ui.basic.MPart

    So, I had to make sure that the Placeholder that referenced the editor was not underneath a Part Stack, but rather directly underneath the Part Sash Container.

    In hindsight it’s rather obvious what happened but in trying to look over things a bunch of times it took quite a while before I realised the cause of the issue because I was so used to Part Stack->Part model that I just didn’t notice it didn’t work here. Hopefully this helps anyone else out there who may have this issue.

  27. Hi,

    I met one problem in the tutorial, in step 5″ for link the product to Eclipse 3.X application by setting in test.rcp.product on the Overview Tab the Application to test.rcp.Application (as in the plugin.xml).”
    I didn’t found “test.rcp.Application” in Overview -> Production Definition -> Application in test.rcp.product.

    Thank you

  28. Hi i have the example working, but when i want to make the fix about the issue with the refresh of project explorer i cant make it work.

    if in the final application the ProjectExplorer content is not visible by its own (but only after you forced an updated, e.g., via opening the context menu with a right-click), try this: override the getDefaultPageInput() method of the ApplicationWorkbenchAdvisor and add the following line:

    “return ResourcesPlugin.getWorkspace().getRoot();” i add this line but not recognize the ResourcesPlugin import, what is this?

    Thanks

  29. Hi there,
    Thanks a lot for your wonderful tutorial. I have got a question. Files (java, etc.) have not their own default editor icons. What should I do?
    Best Regards,

Leave a reply to Angel Manica Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.