e(fx)clipse 1.2.0 – Themes are OSGi services


e(fx)clipse 1.2.0 is trying to get a better OSGi citizen and so we try to remove more and more Equinox/Eclipse specific stuff which means that we want to get rid of the Extension Registry in our/your code.

In 1.1.0 themes have been defined using the theme extension point org.eclipse.fx.ui.theme where you’ve been able to:

  • Define a theme
  • Contribute Stylesheets to themes

In 1.2.0 we deprecated the extension point in favor of making Themes and Stylesheets OSGi-Services you e.g. contribute through declarative services.

There are 2 main advantages:

  • We get dynamics for free so themes and stylesheets can be installed/updated/uninstalled in a running application
  • You have much more control over contributing a Stylesheet e.g. whether it applies to a given theme

A disadvantage if you want to find one is that it is a bit more work to define the theme and looks like this

<?xml version="1.0" encoding"UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.fx.code.compensator.app.default-theme">
  <implementation 
    class="org.eclipse.fx.code.compensator.app.DefaultTheme"/>
   <service>
      <provide 
       interface="org.eclipse.fx.ui.services.theme.Theme"/>
   </service>
   <reference 
     bind="registerStylesheet" 
     cardinality="0..n" 
     interface="org.eclipse.fx.ui.services.theme.Stylesheet" 
     name="Stylesheet" 
     policy="dynamic" unbind="unregisterStylesheet"/>
</scr:component>
package org.eclipse.fx.code.compensator.app;

import org.eclipse.fx.ui.services.theme.Theme;
import org.eclipse.fx.ui.theme.AbstractTheme;
import org.osgi.service.component.annotations.Component;

public class DefaultTheme extends AbstractTheme {
  public DefaultTheme() {
    super("default", "Default Theme", 
      DefaultTheme.class.getClassLoader().getResource("css/default.css"));
  }
}
This entry was posted in e(fx)clipse and tagged . Bookmark the permalink.

5 Responses to e(fx)clipse 1.2.0 – Themes are OSGi services

  1. Pingback: e(fx)clipse 1.2.0 – RRobot learned to generate declarative services | Tomsondev Blog

  2. WhoCares says:

    Hi Tom,

    great, it seams a step further to be more OSGi-ish.

    But you should check your code-makro because the XML and the Java-Class are full of " and hence hard to read.

    Regards
    WhoCares

  3. Pingback: SWT to JavaFX migration - Eclipse RCP Cookbook - codecentric Blog

  4. Pingback: Migrate E4 RCP from SWT to JavaFX using SWTonJavaFX | Christoph Keimel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s