SWT to JavaFX migration – Eclipse RCP Cookbook

No Comments

When developing an Eclipse RCP application in the past, you needed to use the Standard Widget Toolkit (SWT) as UI toolkit for creating and rendering the user interface. With Eclipse 4 you are not restricted to SWT anymore. The architecture separated the application model and the rendering, which allows to create an Eclipse based application using a different UI toolkit. Currently there are implementations for JavaFX and Vaadin available.

The following recipe shows the steps necessary to migrate a simple Eclipse 4 application from SWT to JavaFX using the e(fx)clipse tooling and runtime. It is based on the basic recipe introduced in a previous blog post and can also be used as basis for further recipes.



This recipe uses the Eclipse RCP Cookbook – Basic Recipe. To get started fast with this recipe, we have prepared the basic recipe for you on GitHub.

If you want to use the prepared basic recipe to follow the migration from SWT to JavaFX, import the project by cloning the Git repository:

  • File → Import → Git → Projects from Git
  • Click Next
  • Select Clone URI
  • Enter URI https://github.com/fipro78/e4-cookbook-basic-recipe.git
  • Click Next
  • Select the master branch
  • Click Next
  • Choose a directory where you want to store the checked out sources
  • Click Next
  • Select Import existing projects
  • Click Next
  • Click Finish


Step 1: Update the Target Platform

  • Open the target definition de.codecentric.eclipse.tutorial.target.target in the project de.codecentric.eclipse.tutorial.target
  • Remove the Software Site http://download.eclipse.org/releases/luna/ by selecting it in the Locations section and then clicking Remove
  • Add a new Software Site by clicking Add… in the Locations section
    • Select Software Site
    • Software Site for the e(fx)clipse 1.2.0 release build
    • Expand FX Target and check Target Platform Feature
      Note: RCP e4 Target Platform Feature only contains fx plugins for helping adding JavaFX content to e4-SWT-RCP applications
    • Uncheck Include required software
    • Click Finish 
  • Activate the target platform by clicking Set as Target Platform in the upper right corner of the Target Definition Editor


Step 2: Migrate the Application Project

  • Update the application model
    The application model itself is UI toolkit independent. But the binding addons are not. Therefore the default SWT binding addons need to be replaced with the corresponding JavaFX counterpart.

    • Open the file Application.e4xmi in the project de.codecentric.eclipse.tutorial.app
    • Expand the Addons tree node under Application
    • Remove the addon org.eclipse.e4.ui.bindings.service
    • Add a new addon
      • ID: org.eclipse.fx.ui.keybindings.e4.service
      • Class:
    • Remove the addon org.eclipse.e4.ui.workbench.bindings.model
    • Add a new addon
      • ID: org.eclipse.fx.ui.keybindings.e4.model
      • Class:
  • Update the bundle dependencies
    • Open the file MANIFEST.MF in the project de.codecentric.eclipse.tutorial.app
    • Switch to the Dependencies tab
    • Remove the following bundles from the Required Plug-ins
      • javax.inject
      • org.eclipse.core.runtime
      • org.eclipse.swt
      • org.eclipse.jface
    • Add the following bundles to the Required Plug-ins
      • org.eclipse.fx.ui.workbench.fx
      • org.eclipse.fx.ui.theme
      • org.eclipse.fx.ui.di
      • org.eclipse.fx.ui.services
      • org.eclipse.e4.core.services
      • org.eclipse.e4.core.di.extensions
    • Ensure the following bundles are set
      • org.eclipse.e4.ui.model.workbench
      • org.eclipse.e4.core.di
      • org.eclipse.e4.ui.di
      • org.eclipse.e4.core.contexts
      • org.eclipse.e4.ui.workbench
      • org.eclipse.e4.ui.services
    • Add the following packages to the Imported Packages
      • javax.annotation (1.0.0)
      • javax.inject (1.0.0)
      • javafx.*
  • Update the extension points
    • Open the file plugin.xml in the project de.codecentric.eclipse.tutorial.app
    • Switch to the Extensions tab
    • Update product extension point
      • Set application to org.eclipse.fx.ui.workbench.fx.application
    • Add a new property to the product extension point
      • Right click on the product extension point → property
      • name applicationXMI
      • value de.codecentric.eclipse.tutorial.app/Application.e4xmi

Note that e(fx)clipse does only support theme based CSS styling. Therefore the applicationCSS property of the product extension point does not have an effect in e(fx)clipse 1.2.0 and can be removed. The recommended way to configure a theme is via declarative service as explained here. Since there is no CSS styling in the basic recipe, we don’t have to perform any migration actions here.

Step 3: Migrate the Plug-in Project

  • Update the bundle dependencies
    • Open the file MANIFEST.MF in the project de.codecentric.eclipse.tutorial.inverter
    • Switch to the Dependencies tab
    • Remove the following bundles from the Required Plug-ins
      • org.eclipse.swt
      • org.eclipse.jface
    • Add the following packages to the Imported Packages
      • javafx.*

In the basic recipe, the plug-in project is the only place where we directly get in touch with JavaFX. In the part implementation, UI toolkit controls are used to create the visible part of the application. Therefore the InverterPart needs to be re-implemented for the usage of JavaFX.


Your email address will not be published. Required fields are marked *