Saturday, November 6, 2010

Uhh we have color: Running a legacy app on eclipse e4

I came back from ESE with lots of inspiration. So I couldn't stop and had to try our RCP application on e4 for the first time.

I had a little fight in getting everything up, the e4 sources are missing in the M3 download (theres a bug for that) and you have to install the tooling seperately. So I just pointed e4 to my workspace, switched the target platform and tried to launch. Oh, yes now we need an application model.

Setting up the application model for a legacy app seems to be not well documented, I didn't know at all what elements I would need as I was starting from zero. So I had a look at the example e4 app and stripped down the e4xmi to my needs.

<?xml version="1.0" encoding="ASCII"?>
<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="_lYit4OjtEd-nIcCsQMihjw" elementId="de.eiswind.mango.client">
  <children xsi:type="basic:TrimmedWindow" xmi:id="_lWJrwOjuEd-nIcCsQMihjw" elementId="de.eiswind.mango.client.mainWindow" label="Buchmanager" iconURI="platform:/plugin/de.eiswind.mango.client.core/icons/mango.gif" width="1024" height="768">
    <children xsi:type="advanced:PerspectiveStack" xmi:id="_bXMvVejuEd-nIcCsQMihjw"/>
    <mainMenu xmi:id="_xpyAkOjuEd-nIcCsQMihjw" elementId="menu:org.eclipse.ui.main.menu"/>
    <trimBars xmi:id="_CnxywOjvEd-nIcCsQMihjw">
      <children xsi:type="menu:ToolBar" xmi:id="_DF-xsOjvEd-nIcCsQMihjw" elementId="toolbar:org.eclipse.ui.main.toolbar"/>
    </trimBars>
  </children>
  <addons elementId="MinMax Addon" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon"/>
  <addons elementId="DnD Addon" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.dndaddon.DnDAddon"/>
  <addons elementId="Cleanup Addon" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.cleanupaddon.CleanupAddon"/>
</application:Application>

--27.02.2011 this xmi is a little buggy. Try the LegacyIDe.e4xmi from the platform plugin instead.

You basically need a menu and toolbar hook, and a perspective stack. the addons are needed to get the usual behaviour on views and editors for resizing.

Some things didn't work from scratch with my perpectives, but I received patches in almost no time when I reported the bugs to the e4 team. Still one issue open, but I think that will get fixed soon, too.

Finally I stole some eclipse css file and added the theme extension point to my app.
So now my app looks a little more "sexy" in terms of colors and styling. I could get used to it.

Did I mention that I didn't change a single line of the 3.6 based code ? The compatibility is great.

4 comments:

Kai Tödter said...

looks nice! But I really don't like the UI for the editor area (newly introduced with 4.1M3). I'll find out if there is a way to disable it for RCP apps.

Anonymous said...

the UI for the editor is temporary and will change

Kuldeep said...

What do I need to do if I want to remove/hide the Run and Search menus and some toolbar items which I was hiding in WorkbenchWindowAdvisor.postWindowCreate() method in my Eclipse 3.7. But in e4 this method does not get called at all.

Thomas Kratz said...

I worked around by creating an eralyStartup extensionsion that launches a user job. not nice, but if you look at the e4 implementation you will see why the method isnt called. at least i couldn't figure out a way tzo do this

Using Mapstruct with Protobuf3