Framework free!

e4 on JavaFX

Tom Schindl
© Shutterstock / Sadovski

What is e4 and why is it different on JavaFX? In this article, Tom Schindl explains how you can develop applications and write 100% framework-free business components with e4 on JavaFX.

What is it?

Many people are familiar with Eclipse RCP 3.x and most of them are also familiar with Eclipse 4 RCP, sometimes also called Eclipse 4 Application Platform (EAP), that brought modern development concepts to Rich Client developers:

  • A model representing the application state comparable to the browser DOM
  • DependencyInjection (DI) or Inversion of Control (IoC) as the new programming model to implement components that are not coupled to the application container they are running in

A less known fact is that when we designed the EAP, we took extra care to lead by example and not couple our new framework with specific UI technologies (ie SWT). Instead, we introduced the concept of a rendering engine that allows other projects/vendors/companies to provide implementations for other UI toolkits.

There have been people implementing a renderer for Vaadin, while others have taken e4 to swing, but none of them reached the maturity required to be used by enterprises class applications – except one: the JavaFX renderer developed as part of the e(fx)clipse project.

Today there are many commerical applications built on top of it from applications in the financial industry to medical applications. Another area JavaFX and hence e4 on JavaFX has gained traction, is the public sector.

There are multiple reasons to favor e4 on JavaFX over e4 on SWT, but the most important one is that one can theme/design JavaFX applications in a pixel perfect way in much less time compared to SWT and even Swing. With UX getting more and more attention even used “only” in the back office, JavaFX is the natural choice for most applications that decided to stay on the desktop as a rich client. In general, e4 on JavaFX can be used to build any application, but in reality it is primarily suited for medium sized to large projects with a lot of views, screens, …​ The framework is designed to help with saving and restoring state, provides a command and handler story and a sane service story that is fully integrated in the the DI programming model that fosters a state of the art application and component design.

What’s the difference?

The basic EAP already provides many concepts required to develop applications with minimal dependencies on the application framework, but e4 on JavaFX closes even those minimal gaps, allowing you to write 100% framework free business components.

The following examples highlight what that means:

If you want to publish information into EAP so that others can retrieve this information later by just writing @Inject in their components, you are forced to code something like this:

@Inject IEclipseContext context;

void publish(Person p) {
    context.modify( "selectedPerson", p );

This introduces a compile-time dependency to the EAP-Framework through the use of IEclipseContext. In contrast to that, e4 on JavaFX enhances the DI container, allowing you to write the following:

@Inject @ContextValue("selectedPerson")
Consumer<Person> publisher;

void publish(Person p) {
    publisher.accept( p );

What can you build?

It’s up to your imagination, but to show you that it is not only business UIs that can be built on top of it, we have started working on a alternate showcase IDE, built on top of Eclipse JDT:

e4 on JavaFX

e4 on JavaFX

Having an IDE with a dark theme is not only a really cool and fancy new feature, the interesting part is how long it takes to create such a theme. It turns out that the following ~50 lines of CSS are sufficient. The most important ones are:

.root {
    -fx-base: #4d5052;
    -fx-background: #4d5052;
    -fx-control-inner-background: #4d5052;
    -fx-text-base-color: #c7c7c7;

    -content-assist-extra-1-color: rgb(150,150,150);
    -content-assist-extra-1-color-hover: rgb(80,80,80);

/* ... stripped some lines ... */

.styled-text-area .list-view {
    -source-editor-code: #b8c4d1;
    -source-editor-operator: #b8c4d1;
    -source-editor-bracket: #b8c4d1;
    -source-editor-keyword: #d78b40;
    -source-editor-string:  #7c986c;
    -source-editor-number:  #b6c8ad;
    -source-editor-doc: #929292;
    -source-editor-api-doc: #74a567;
    -source-editor-buitin-type: rgb(255,235,121);
    -source-editor-annotation: rgb(200, 200, 200);

    -source-editor-markup-doc: #929292;
    -source-editor-markup-property-name: #b8c4d1;
    -source-editor-markup-property-value: #7c986c;
    -source-editor-markup-tag: #e9c063;
    -source-editor-markup-extra: rgb(190, 190, 190);

.content-proposal-doc {
    -fx-background-color: #4d5052;

What’s next?

As outlined above, e4 on JavaFX is enterprise ready and we are actively maintaining it, adding new features and APIs and fixing bugs in both our own and the upstream code base.

One of the bigger pieces we have been working on for a while, is to allow developers to choose their favorite IDE when working with e4 on JavaFX applications.

At JavaOne 2017 we showcased the current state of Netbeans and IntelliJ IDEA support:

e4 on JavaFX

e4 on JavaFX

A key point to support other IDEs is that we had to implement a completely different development model compared to the MANIFEST-first approach taken by PDE and maven-tycho.

In order to achieve this, we have switched to a maven-first approach by leveraging the fairly new bnd-maven-plugin that is part of the bnd-ToolSuite.

We are still supporting MANIFEST-first development styles, but we encourage our user base to favor the maven-first style, because it works in any modern IDE (Eclipse, Netbeans, IntelliJ, VS-Code) and even makes your application a better OSGi citizen.



This post was originally published in the October 2017 issue of the Eclipse Newsletter: Utility Belt: Projects and Tools

For more information and articles check out the Eclipse Newsletter.


Tom Schindl

Tom Schindl is an Eclipse Committer, e(fx)clipse project lead and the CTO of BestSolution. Read more at his blog or follow him on Twitter @tomsontom.

Leave a Reply