Eclipse 4.1 Application Platform – A platform for anyone

This post is dedicated to “Eclipse 4.1 Application Platform” (EAP).

So what is the EAP? In short it is a Widget-Toolkit agonstic UI-Application framework for OSGi which provides the following features:

  • An extensible central application model abstracting the main concepts of UI-Applications:
    • UI-Concepts like Windows, Toolbars, Parts, …
    • None-UI Concepts like Commands and Handlers, Extensions, …
    • An event bus to get away with listeners
    • UI-State persistance
  • A dependency injection container to keep up with modern programming technologies
  • An extension system build applications from various modules instead one big

As said the EAP-Core is widget agonstic and can be used with any native UI-Technology you want to write your applications with.

Here’s an example application coded 3 times with the native technologies. The only thing they share is the EAP which provides the runtime platform.

  • SWT
  • Swing
  • JavaFX

As of now SWT is the platform with the best support because the Eclipse 4.1 SDK is built on top of EAP and ships with a set of default SWT-Renderes. The Swing and JavaFX implementations for EAP are currently proof of concepts but can be used as a show case of how powerful and flexible the design of EAP is (you’ll find the sources in my github-repo).

The only interface EAP requires you to implement and register looks is this:

public interface IPresentationEngine {
 public Object createGui(MUIElement element, Object parentWidget, IEclipseContext parentContext);

 public Object createGui(MUIElement element);

 public void removeGui(MUIElement element);

 public Object run(MApplicationElement uiRoot, IEclipseContext appContext);

 public void stop();

This where EAP hands over control to you to build and keep the UI in sync with the model.

The already written IPresentationEngine implementation for Eclipse 4.1 is a good source of inspiration on how one could approach the problem but finally it is up to you – all the EAP expects you to respect is the IPresentationEngine-Interface.

… and before some mentions that the current application model is not supporting modern UI-Concepts needed to built App-UIs as you know them from smart phones, tablets, … . You can extend the application model and add the concepts you think are missing.

All I can say: If you have the task to write an UI-Application you should take a look at this new but quite solid runtime platform because it offers you many advanced concepts you’d have to reinvent if not doing so.

Posted in e4 | 8 Comments

How to apply the e4 programming model to 3.x

So while I could only encourage everyone to use the Eclipse 4.1 Application Platform (EAP) to write UI-applications, this post is for those who have existing 3.x code which they want to refactor step by step to run on EAP.

So if you ever looked at how EAP are developed the first thing you notice is the new programming model or better said the paradigm shift happing because you use DI and Services instead of subclassing and use of statics. So if you want to move your code gradually from a 3.x development model to EAP what you need is a bridge that allows you to run the refactored UI-Code in your existing 3.x runtime.

This is exactly where the Tools Bridge feature as part of the e4 updatesite might catch your attention. It allows you to use the e4 programming model inside the 3.x runtime. All you need to do to get started is to install this feature into your 3.x workspace.

Now you are able to write code that follows the e4 programming model and hence runs natively on the EAP (=without any compat layer). All you need to do to integrate your code afterwards is to subclass one of the generic ViewPart/EditorPart classes:

  • DIViewPart
  • DISaveableViewPart
  • DIEditorPart

who’ll act as the integration points into Eclipse 3.x. Now you might be confused, right? So just checkout the git-repo with a view i’ve written which works inside 3.x and 4.x and brings a feature into Eclipse I always wanted to have. It shows all images in a folder as a preview.

Here’s the view in a running 3.7 RC4:

And here in a 4.1 RC4:

You can naturally also install the view into your 3.x/4.x Eclipse Install:

For 3.x:

  • Add the e4 update site as shown above
  • Get the p2repo and add it to your update configuration

For 4.x:

  • Get the p2repo and add it to your update configuration

Please note that there’s a bug in the plugin version of one of the plugins from e4 so you won’t be able to upgrade after having installed it so only give it a try on an installation which you have no problem with reverting.

Final note: The bridge I introduced here has been built for the e4 modeltooling but will quite likely get more customers in 4.2 because we plan to refactor parts of the exiting platform code to be useable in EAP applications so it might get a key component in 4.2.

Posted in 3.x, e4, Enhanced RCP | 8 Comments

Using Xtext to create JavaFX-CSS Editor

While working on the example application showed in my last blog

I missed the possibility to edit the CSS-Files used to theme JavaFX-applications.

Having heard about Xtext and that it allows one easily create editors for your DSL (and CSS is nothing more) I decided to start teaching myself some Xtext and so I sat down the last 2 evenings and worked on an editor to author CSS-Files for JavaFX.

First of all I had (or better still have) not a really a knowledge about language design, LL-Parsers, … so what I produced until now is probably nonsense. Anyways even if not 100% correct yet I have a working editor which is able to parse the FX-CSS-File coming with the JavaFX 2.0 example.

It’s quite amazing at least for me as a total newbie to all this stuff to get an editor with autocompletion, … working in such a short time – Xtext rocks. If someone who has more knowledge about all this stuff and wants to help me / give feedback – the sources are available from my github-repository.

Maybe this Xtext-based editor can be used to build a JavaFX-Tooling and Runtime-Stack on top of Eclipse technologies:

  • Xtext to build tooling to author CSS-Files
  • JDT/PDE to develop OSGi based JavaFX applications (I already filed bugs against JavaFX to make it run without hacks in an OSGi-Env which are built using
  • Window Builder to write a visual editor
  • The Eclipse 4.x Application Platform as a runtime container / framework to build JavaFX-Applications using DI, the workbench model, …
  • Xtext/Xbase to build a DSL with a modern syntax supporting closures, …
Posted in e(fx)clipse, e4, Eclipse | 5 Comments

Taking JavaFX for a spin

So it’s been about 2 weeks ago when a JavaFX beta was released to the public and I could not resist to bring up some Windows and give it a try.

First of all I’m quite impressed on the features it gives me compared to what I know from SWT and Swing. I can control almost L&F stuff using CSS.

The first thing I did naturally was to get Eclipse Databinding integrated so that I was able to bing my EMF-Objects to it (took me half a day to implement a Value-Property-Binding) and so I can now write code like this:

// ...
private void createControls()
{
  // ...
  {
    Label l = new Label("Firstname");
    rootPane.add(l, 0, 0);

    w_firstName = new TextBox();
    GridPane.setHgrow(w_firstName, Priority.ALWAYS);
    rootPane.add(w_firstName, 1, 0);
  }
  // ...
}

private void bindControls()
{
  IValueProperty tProp = JFXBeanProperties.value("text");

  {
    IEMFValueProperty mProp = EMFProperties
      .value(AddressbookPackage.Literals.PERSON__FIRSTNAME);
    dbc.bindValue(tProp.observe(w_firstName),
    mProp.observeDetail(master));
  }
  // ...
}

I know JFX comes with its own binding solution but JFX-Folks do you really think I’ll clutter my Domain-Model with your custom observable system (or did I get this wrong), what if i want to reuse it in areas no JFX is available? Anyways Eclipse Databinding works like a charme and so I don’t care about their custom JFX-Solution when I have to bind my model-instances.

What I really really like and always hoped we could do also with SWT in Eclipse 4.x is to theme an application as much as I want. Now JavaFX gives me (or better the graphic artist) this freedom.

So this is the UI I’ve written without CSS:

And with some CSS (you know I’m not a graphic artist):

If you already read some of my blog entries the UI you see here should be quite familiar to you because there’s also a Swing and SWT version available.

Naturally the application you see above is not simply a JavaFX application it mixes various Eclipse Technologies into it:

  • Equinox
  • Eclipse Databinding
  • EMF + EMF-Databinding + EMF-Edit

Naturally I’ve hit some road blocks with JavaFX:

  • Loading stylesheets is only possible through the global-classpath and filesystem but not if you are in an OSGi-Env – I worked around this using Buddy-Classloading
  • Application-Lifecycle-Handling: This is a know bug and I had work around it by registering a Shutdown-Hook
  • Rendering artefacts (at least on my Virtual-Windows7 Desktop) when resizing, …

But beside that I have to say that I’m quite impressed by what I see and I think JavaFX 2.0 has found a new follower when it comes to writing UIs. This makes me a bit sorry about SWT because compared to what JavaFX provides to me SWT is light years behind.

Posted in e(fx)clipse, e4, Eclipse | 23 Comments

My RCP-Self-Update is not working

Not sure how many people have been running into this problem but because it happened to one of my coworkers today I thought I should blog about it.

The problem was the following: We added the p2-update possibility to an application at the end of our product development like it is shown in the cloud example found in rt-CVS, we correctly added the p2.inf-File and exported the application but die Update did succeeded because there’ve been no repositories configured when the application was exported.

It took us some time to figure out what he did wrong and the solution though obvious, logic and simple is something others could easily miss also when exporting from the Eclipse IDE.

We forgot to check the “Generate metadata repository”

Like I said: Obvious, logic and simple to fix but my coworked nearly gave up. So should the export wizard when finding a p2.inf in the project not at least warn if the “Generate metadata repository” is not checked?

Posted in Eclipse | 1 Comment

Eclipse-TFS-Plugin and ignoring files

I have the pleasure to work with Microsofts Team Foundation Server (TFS) and the Eclipse Plugin provided by them (former known as Teamprise). I won’t talk about how bad it feels to work with TFS compared to Subversion and even CVS because of the good tooling integration into Eclipse – not to talk if you are used to stuff like git. But you can’t imaging how lucky you are if you use an OSS VCS like the ones above.

Anyways – today I added EclEmma to get code coverage while running the JUnit-Tests and TFS-plugin now thought that it had to checkin a file eclemma wrote to my projects bin folder – argh. So I searched something like svn:ignore (the Subclipse Eclipse Integration provides a Menu-Contribution dear TFS-Plugin authors). Apparently the TFS-Plugin has no such option so I had search the docs find the solution. All you need to do is add a .tpignore-file in my project root with the following content:

/bin/
/bin/.*

which will ignore everything below the bin-folder.

Posted in Eclipse | 3 Comments

Jax 2011: EMF-Databinding talk

I had the pleasure to present EMF-Databinding to interested people on the Model Day at Jax 2011. I’m desperately sorry that people have been unable to install my sources but there has been a misunderstanding I’ll apologize for.

Everyone who was at the tutorial should already have the slides and sources but for those who don’t.

Here they are:

To make the stuff run you’d ideally use Eclipse SDK 4.1M7 or Eclipse SDK 3.7M7 (and install e4 stuff as mentioned in the slides)

Posted in EMF, Talks & Conferences | Leave a comment

Interesting new feature in EMF-Databinding

I’ve invested sometime into EMF-Databinding to add a new quite interesting feature i guess. Currently we have to problem that if your nested path crosses a multi-valued feature (=java.util.List) at some point the only solution today is to create a volatile transient feature which observes your EList and fire change events but this really clutters your Ecore-Model.

Let’s take a look at an example model

you’d like to present in an UI like this:

Until EMF 2.7M7 you’d have to modify your EMF-model like this:

So that you could e.g. write something like this to get access to the private address’ city property:

import static at.bestsolution.e4.addressbook.model.addressbook.AddressbookPackage.Literals.*;

// ...

IEMFValueProperty mProp = EMFProperties.value(FeaturePath.fromList(PERSON__PRIVATE_ADDRESS,ADDRESS__CITY));

// or in longer builder type syntax
IEMFValueProperty mProp = EMFProperties.value(PERSON__PRIVATE_ADDRESS).value(ADDRESS__CITY);

With the new feature I’ve added to IEMFListProperty#value(ListElementAccess) one now does not have to create those volatile transient features any more but can write the long form like this:

IEMFValueProperty mProp = EMFProperties.list(PERSON__ADDRESSES).value(
  new ElementAccessImpl(AddressType.PRIVATE)
);

// ...
private class ElementAccessImpl extends ListElementAccess<Address> {
 private AddressType type;

 public ElementAccessImpl(AddressType type) {
  this.type = type;
 }

 @Override
 public int getReadValueIndex(List<Address> list) {
  int i = 0;
  for (Address o : list) {
   if (o.getType() == type) {
    return i;
   }
   i++;
  }
  return -1;
 }

 @Override
 public int getWriteValueIndex(List<Address> list) {
  int i = 0;
  for (Address o : list) {
   if (o.getType() == type) {
    return i;
   }
   i++;
  }
  return -1;
 }
}

I’d like to note that this feature is an experimental one and we don’t guarantee to break it e.g. by pushing it upstream to Eclipse Databinding but you are free to give it a try and report usefulness, problems, like, dislike, … .

BTW did you notice that the screenshot from the above application was taken from a Swing-Application? How can that be? Isn’t Eclipse Databinding (and because of that EMF Databinding ) only useful within SWT driven apps (e.g. Eclipse RCP ones)?

Without saying too much: No – because many core Eclipse technologies OSGi, Databinding, EMF, Eclipse 4 Application Platform to name some can be used with any UI-Technology

Posted in EMF | 7 Comments

EclipseCon2011: Day one and I’m done

Yeah. Day one is over (at least all my presentations are done) and I’m ready to enjoy EclipseCon in the next 3 days because I’ve no more talks this week. I think the talks I’ve delivered today have been received quite well.

  • Eclipse 4.x RCP Tutorial: Kai will upload our slides later on his blog. We had around 100 attendees and I think most of them liked our tutorial
  • Single Sourceing for Eclipse 4.x and 3.x: I think I got the message around. The slides can be looked at once more following the link
Posted in Talks & Conferences | Leave a comment

Equinox, Hibernate and Concurrency

I’ve been hunting a deadlock in an application of a customer we support with our RCP, EMF and OSGi know-how and turned out be a class-loader problem because Hibernate uses Class.forName().

The application is a pure OSGi-Application acting as an Application Server which is used to process database informations in an asynchronous fashion and heavily uses OSGi-DS to wire up the complete application. The problems we’ve been facing only happened at start up where many threads are accessing database informations in a highly concurrent fashion.

The deadlock information from the JVM looked like this:

Found one Java-level deadlock:
=============================
"Thread-23":
  waiting to lock monitor 0x18b30eac (object 0x09c93230, a org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader),
  which is held by "Thread-17"
"Thread-17":
  waiting to lock monitor 0x1977f16c (object 0x09c92fd0, a org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader),
  which is held by "Thread-12"
"Thread-12":
  waiting to lock monitor 0x18b30eac (object 0x09c93230, a org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader),
  which is held by "Thread-17"

where the threads where calling the following methods:

“Thread-23”:

        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
        at org.hibernate.impl.SessionFactoryImpl.getImplementors(SessionFactoryImpl.java:825)
        at org.hibernate.hql.QuerySplitter.concreteQueries(QuerySplitter.java:123)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:92)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
        at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)

“Thread-17”:

        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:468)
        - waiting to lock <0x09c92fd0> (a org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader)
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:449)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
        at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:393)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:469)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
        at org.eclipse.osgi.internal.loader.buddy.DependentPolicy.loadClass(DependentPolicy.java:54)
        at org.eclipse.osgi.internal.loader.buddy.PolicyHandler.doBuddyClassLoading(PolicyHandler.java:135)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
        at org.eclipse.osgi.internal.loader.buddy.DependentPolicy.loadClass(DependentPolicy.java:54)
        at org.eclipse.osgi.internal.loader.buddy.PolicyHandler.doBuddyClassLoading(PolicyHandler.java:135)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
        at org.hibernate.impl.SessionFactoryImpl.getImplementors(SessionFactoryImpl.java:825)
        at org.hibernate.hql.QuerySplitter.concreteQueries(QuerySplitter.java:123)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:92)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)

“Thread-12”:

        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:468)
        - waiting to lock <0x09c93230> (a org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader)
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:449)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
        at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:393)
        at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:33)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:466)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at com.bizerba.basic.resource.teneo.TeneoHbDataStoreProvider$ChangeInformationInterceptor.afterTransactionBegin(TeneoHbDataStoreProvider.java:148)
        at org.hibernate.impl.SessionImpl.afterTransactionBegin(SessionImpl.java:1479)
        at org.hibernate.jdbc.JDBCContext.afterTransactionBegin(JDBCContext.java:259)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:107)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)

So what did we do to fix the problem once we managed to get to the bottom of it? We asked at the equinox IRC-Channel for help and Tom Watson pointed me to a bug 212262 describing more or less the problem we are seeing. As described in the bug we’ve added jvm options:

-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass

and ran our test-suite the whole night and could not reproduce the locks since then.

So if you happen to run Hibernate (other libraries who use Class.forName() might have the same problem) inside the Equinox-OSGi-Container (I have no idea if other OSGi-Implementation might face the same problem) and your system is doing many things in a concurrent way you should consider setting those 2 options to avoid deadlocks.

Posted in Uncategorized | Leave a comment