A week at e4 – Themeing in e4

Core Work-Items

Themeing in e4 is done using CSS like Declarative Syntax. The latest nightly builds introduce an extension point which allows people to define and contribute CSS-Files to make up a theme from different css-Files.

So now plugin-developers can contribute stylesheets which hold CSS-Definitions (classes, …) they use in their UI-Bundles. One of the interesting things in this sense is that even the latest 3.6 builds can make use of the CSS themeing support (an example is my Workbench-Modeleditor which now runs unmodified in 3.6).

The extension point is used to make up a theme in a declarative manner but IThemeManager is also registered in the OSGi-Service registry and can be access by client code e.g. to switch the UI-Theme on the fly.

In 3.x e.g. like this:

public class CSSViewPart extends ViewPart {
  private static final String CSS_CLASS_KEY = "org.eclipse.e4.ui.css.CssClassName"; //$NON-NLS-1$

  @Override
  public void createPartControl(Composite parent) {
    Bundle b = FrameworkUtil.getBundle(getClass());
    BundleContext ctx = b.getBundleContext();
    ServiceReference ref = ctx.getServiceReference(IThemeManager.class.getName());

    IThemeManager mgr = (IThemeManager) ctx.getService(ref);
    final IThemeEngine engine = mgr.getEngineForDisplay(parent.getDisplay());
    // ...
  }
}

In e4 you’d better use simply @Inject to even get the theme engine bound to the workbench instance:

public class CSSView {
  @Inject
  private IThemeManager manager;

  @Inject
  private IThemeEngine engine;
}

An example CSS-File could look like this:

.h2 {
	color: white;
    font-size: 20pt;
}

.container {
    background-color: gradient radial #575757 #101010 60%;
}

and the Java-Code to use it

final Composite p = new Composite(parent, SWT.NONE);
p.setData(CSS_CLASS_KEY, "container");
p.setBackgroundMode(SWT.INHERIT_DEFAULT);
p.setLayout(new GridLayout(2, false));

Label l = new Label(p, SWT.NONE);
l.setData(CSS_CLASS_KEY, "h2");
l.setText("This is a headline");
l.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, false, false, 2, 1));

engine.applyStyles(p, true); // Apply the CSS-Instructions of the current active theme

The last line applies the current theme CSS-Information on all elements below the given widget.

Switching between themes is quite easy using:

engine.setTheme("org.eclipse.e4.demo.contacts.dark");

Which makes the 3.x ViewPart look like this with a radial black gradient:

or a bright one:

The currently needed plug-ins from e4 and orbit are:

Model Editor

I started refactoring some code so that model modification can be run using the e4-CommandService. Beside that I added support for Main-Menu creation and fixed some other small things.

Update: Added description how to use the IThemeEngine, …

A week at e4 – Branch, Tweak, Break and Adjust

Today I thought it would nice to do a summary about the things happing at e4 I’m part of. The headline for this week could be:

“Branch, Tweak, Break and Adjust – Lock the e4-Workbench-Model so that people won’t be broken until 4.0”

Core Work-Items

So what happened: Short before EclipseCon we started collecting proposals and feedback from people what they’d like to see changed in the EMF-Workbench-Model for the release of Eclipse 4.0 (see the PMC-Announcement). Like most stuff in Eclipse the discussion happened in the public (Bugzilla on bug 305586, the e4-dev-mailing-list, and IRC).

It was a really lively discussion at a very highlevel but I think the final result is not a compromise (which happens very often if multiple experts from different domains have to draw a conclusion) but a model which has the functionality it needs to have to address different usecases.

Defining and agreeing on the model was a team and e4-community effort but this was only half of the work the e4-committer team had to do because once we aggreed that we are all satisfied with the model we had to port over all our code. We are already quite late for this changes so putting CVS-HEAD in an unstable state was out of question.

So Eric Moffatt, Paul Webster, Remy Suen and me opened branches and adjusted the workbench code there until all our test-suites, example applications and the e4-workbench running on the compat-layer have been back in shape. This work started Thursday morning Ottawa time and was finished Friday Ottawa Lunch-Time and was as said a multi-continental teameffort coordinated on IRC. Here are the lines where we coordinated our merge commits:

[19:09:34] <paulweb515> OK tests are done
[19:10:02] <paulweb515> Hmmm, we should be ready to commit in about 10 minutes
[19:10:03] <tomschindl> merged too
[19:10:15] <paulweb515> OK, emoffatt's just got one error that he needs to deal with
[19:10:18] <tomschindl> I can check in whenever you want
[19:10:29]  about 10 minutes
[19:10:35] <tomschindl> ok
[19:10:35] <paulweb515> we're sooo close :-)
[19:11:54] <tomschindl> i'm off for dinner for 10 minutes
[19:12:56] <rcjsuen> 10 minute dinner
[19:12:57] <rcjsuen> that's as fast as me
[19:18:06] <emoffatt> paulweb515: ready (I'll do the SeparatorRenderer against HEAD after :)
[19:21:54] <tomschindl> done
[19:22:17] <tomschindl> can we commit?
[19:22:27] <yarthorn> That really was ten minutes!
[19:22:31] <tomschindl> paulweb515: does the count down :-)
[19:22:36] <paulweb515> OK
[19:22:38] <paulweb515> let's do it
[19:22:46] <paulweb515> commit away, and then ACK here
[19:23:56] <tomschindl> commit is done
[19:24:07] <emoffatt> kk
[19:24:27] <paulweb515> committed

Please note that it really took me exactly 10 Minutes to have dinner – no second more no second less :-)

Model-Tooling

Since M5 my custom workbench editor is part of the release and besides adjusting to the model changes I fixed some minor things (like NLS and stuff like this) but now that the model work is done I can once more concentrate on the editor and implement missing features. So I expect to add more features to it until next week.

Time I spent on e4

Many people at EclipseCon asked me how much time I spent on Eclipse and because I was interested by myself here are the stats I collected for the last weeks:

Description Hours Total
In the morning while going by bus to work 0.25 1.25
Every day after work 3 – 5 20
on weekend 6 – 8 7
Summary / Week 28.25 h

It’s quite an impressive number. I restarted working on e4 in March which means I spent 5 weeks (EclipseCon and short holiday in between) on e4 which is a total of 141.25 h.

How long will I invest this time? Not sure – what you see above is not really a peak in my Eclipse investment but I guess the average I spent on Eclipse stuff. I’m still trying to move some of this spare time work back to my day time job but currently it’s impossible to do so because people are not used to pay for someone doing Eclipse Opensource work for the benefit of the complete Eclipse Platform Stack (Beside naturally the compan(y/ies) who employee the Platform Team).

Things I’m going to work on next in e4 are (order by priority):

  • Model Editor improvements – Finish support for missing elements, add model documentation,
  • Model-Contributions – Fix the current contribution system and my top priority: I’d like to contribute programmatically to the model
  • DI and Tooling – One of the most important things from the tooling side but too much for me to work in my spare time
  • CSS – Start discussion on how to contribute to CSS and how to make it work in a 3.x workbench (my current hack is so dirty I can’t even tell you)