JavaFX 2.0, Swing & SWT Renderers for the Eclipse 4.x Application Platform

I wish you all a Happy New Year!

During the last weeks I had a bit of spare time and started experimenting with new rendering engines for the Eclipse 4.x Application Platform. Based on my experiences with  JavaFX 2.0 renderers in e(fx)clipse (by Tom Schindl from BestSolution.at, great JavaFX support for Eclipse), I started an experiment: Would it be possible to create a generic rendering engine that only has dependencies to the Eclipse 4.x workbench model and then delegate all UI toolkit specific logic to the UI toolkit specific renderers?

When I took a deep look at the projects org.eclipse.e4.ui.workbench.swt, org.eclipse.e4.ui.workbench.renderers.swt and org.eclipse.e4.ui.workbench.addons.swt, I figured out that most of the workbench model related code could be useful for other renderes, too. But there is a very strong coupling to SWT, so it is not possible to reuse any code without copying it. My approach is a simple generic rendering engine, that also provides a generic e4 application. Then, for every supported UI toolkit, just a derived application and new renderers have to be implemented. The basic bahavior is driven only by model changes, the renderes have to react on those changes. The engine also takes care of letting each renderer do the binding from the specific UI toolkit back to the model.

Currently I have implemented simple rendering engines for JavaFX 2.0, Swing, and SWT. I also started the same approach with a generic MinMax model addon. The addon gets the additions needed to adapt to a specific UI toolkit through DI.

I reimplemented my e4 contacts demo and split it into a generic project that contains the workbench model, the domain model and all parts, which are not UI toolkit specific. Then I created a UI toolkit specific implementation for JavaFX 2.0, Swing and SWT. The Details and the Table widgets I had to implement with the UI toolkits natively. Here are a few screen shots of the results, click on them to see the images in original size.

JavaFX 2.0 based contacts demo with 3 different CSS based themes:

     

Swing based contacts demo with Nimbus and Napkin Look & Feel (Napkin is my favorite Look & Feel to show prototypes to the management :)):

  

SWT based contacts demo (my new rendering engine) with 2 different CSS based themes:

  

The current alpha version 0.0.1 you find at GitHub: https://github.com/toedter/e4-rendering

If you want to run the JavaFX 2.0 Contacts Demo, you also need to have the latest version (0.0.11 or better) of e(fx)clipse installed. The easiest way is to download the pre-configured Eclipse 4.x SDK from http://efxclipse.org/install.html#the-lazy-ones and then clone the above git repository.

Right now this is just a proof of concept, only very basic stuff is implemented. But I am planning to enhance the engine and UI toolkit specific renderers until EclipseCon 2012. If there is enough interest in the community, I would love to organize a BOF at EclipseCon to discuss the pros and cons of this approach.

What do you think?

Stay tuned!

Kai

You find me on Twitter and Google+.
If you are interested in in-house Eclipse RCP 3.x or 4.x training,
please contact me…

This Post Has 27 Comments

  1. Pau Carré

    Does it mean that it will be possible to run Eclipse 4.x using only Swing?

  2. Kai Tödter

    @Pau

    if you mean the Eclipse 4.x SDK => No, this will always be on top of SWT.

    But you could build applications on top of the Eclipse 4.x application platform that use UI toolkit specific renderers for the workbench model. Of course, all the content of the view parts, dialogs, etc. have to be implemented natively in the respective UI toolkit.

  3. Vitaliy

    This is awesome! Swing version is running on linux. JavaFx realised for linux, but i cant get it work. Is there tutorial on this app?

  4. Eugen Eisler

    Eclipse SDK, Version: 4.2.0, Build id: I20120127-1145

    GenericE4Application, Zeile 264:
    eclipseContext.set(EPartService.PART_SERVICE_ROOT, new ContextFunction() {
    Es gibt keinen statischen Member in “EPartService.PART_SERVICE_ROOT”
    Was kann man da machen?

  5. Kai Tödter

    @Vitaliy
    Not yet, I will drive it in the next weeks. Hopefully I get a good state just before EclipseCon

  6. Kai Tödter

    @Eugen Eisler
    This is fixed in the current master. It was a change from Eclipse 4.2 M4 to M5. Alternatively you could just delete the whole statement beginning with line 264 (That’s what I did).

  7. Binyan

    Kai, I’m also very interested in trying out what you have done for the swing version, but I’ve spent hours tonight trying to get it to work. If you could hook up the magic steps to get this to work, then I’ll be sure to hook you up at the bar next month in Reston, deal? 🙂

    1. Kai Tödter

      Binyan,

      Here are the steps:
      1) Install Eclipse 4.2M5 + efxclipse, the easiest way is the pre-configured distro http://www.efxclipse.org/install.html#the-lazy-ones
      2) Get the e4-rendering master from my Git repo
      3) Open contacts.product in project com.toedter.e4.demo.contacts.swing
      4) In the Overview tab, in the Testing section, click: Launch an Eclipse Application

      That should be all.

  8. Binyan

    @Kai Tödter
    Thanks Kai,

    Finally got back around to trying this and things do work (on Windows). I previously tried the same setup on OSX Snow Leopard and it would lock up as soon as I believe the swing thread was about to be started. Maybe it was the beta version of the java 7 jdk, or something else. Sadly most of development uses a mac, so if I’m going to make any progress, I’ll need to find out what is really going on there. Still, I’ll see you at the bar next month.

    Also as an fyi, the app throws the following on startup:

    Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at org.eclipse.core.databinding.observable.list.ObservableList.get(ObservableList.java:145)
    at com.toedter.e4.demo.contacts.swing.views.ListView$2.valueChanged(ListView.java:77)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.setAnchorSelectionIndex(Unknown Source)
    at com.toedter.e4.demo.contacts.swing.views.ListView.(ListView.java:94)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:44)

  9. Binyan

    Don’t know why but the IOOBE is caused by the fact that the source I have has line 89 of ListView.java with “Tödter”.equalsIgnoreCase(contact.getLastName()) instead of “Tödter”.equalsIgnoreCase(contact.getLastName()). Really wierd since all I’ve done is clone the repo and imported the projects.

  10. Dimitry

    @Kai
    I consider porting of mind map editor Freeplane developed as a pure swing application to e4 after a stable swing rendering engine is available. How do you think when it comes?

    Regards, Dimitry
    https://sourceforge.net/projects/freeplane/

  11. Kai Tödter

    @Dimitry

    I am not sure if there will be a product quality Swing based rendering engine. Right now it is just a proof of concept. My plan is to improve both the Swing and JavaFX renderers until EclipseCon. Then I would like to have a BOF about that topic, and then let’s see.

  12. Binyan

    @Kai

    The current code fails to work on OSX because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=212617. Calling any of the swing apis results in deadlock with OSX 10.6.x and Eclipse 4.2M5. It is passed down from wikis to issue trackers that some arcane combination of –launcher.secondThread, -XstartOnFirstThread, -XstartOnSecondThread and removal of the -ws ${target.ws} would allow swing to come up and work, but I haven’t been able to reproduce reported results. If you have anything to add, it would be greatly appreciated.

  13. jmini

    Hi,

    Does your project work with M6 ?

    I get this exeception when I try to start the SWT application:
    org.eclipse.core.runtime.CoreException: Plug-in com.toedter.e4.ui.workbench.swt was unable to load class com.toedter.e4.ui.workbench.swt.SWTE4Application.

    Caused by: java.lang.UnsupportedClassVersionError: com/toedter/e4/ui/workbench/swt/SWTE4Application : Unsupported major.minor version 51.0

    The only modification I did, is to change the Execution environment to JavaSE-1.6 (because I do not have 1.7 on my Mac) and I closed the JavaFX projects because I do not have e(fx)clipse.

    Thanks for your answer…

  14. enzogupi

    Thanks Kai,
    your javafx renderer does the job very well (tested with e(fx)clipse 0.0.13 and Eclipse M6).
    Now I’m wondering how to render with javafx also the e4 part (the main window and its borders).
    Would it be possible?

  15. enzogupi

    @enzogupi

    I’ve found it!

    Just adding “stage.initStyle(StageStyle.UNDECORATED);” after the stage initializazion, and the window has no border. Now I can customize every aspect of appereance!

  16. Oliver Pfau

    I like the JavaFX style stuff. To use it with RCP capabilities would be great. Good work 🙂

  17. Oliver Pfau

    What is the state of the JavaFX integration within eclipse RCP? Do you think the JavaFX renderers will get fix part of eclipse 4 or is it too early to say?

  18. krunal

    Hi,
    Kai,

    I have tried with step that you mention but my gives error stack trace like below .
    java.lang.RuntimeException: No application id has been found.
    at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:242)
    at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
    An error has occurred. See the log file

    Let me know what i do for run

    1. Kai Tödter

      Update from Github and then launch the demos from the contacts.product file (create your own launchers). Hope that helps…

  19. Oliver Pfau

    I am quite new using eclipse 4. How is it configured when the DetailsView.setSelection() method invoked? The selected conact is set to IEclipseContext in the ListView. Is this a build-in mechanism of eclipse 4 (selection provider or something)?

  20. fadel

    hi @Kai Tödter,
    I’d like to use your JavaFX contact demo but not as a bundle( not as in here https://github.com/toedter/e4-rendering). Do you have a contact Demo application that has a main method ?
    thanks!!

  21. Codex

    Seriously Javafx is beautiful and simple to write i really love this framework .And want to know more of this.

Leave a Reply

I accept the Privacy Policy