Saturday, January 17, 2009

Getting started with UFaceKit and QT

QT and UFaceKit

So the big news this week in opensource space was the announcement of Nokia to release their C++ cross-platform widget toolkit under LGPL. This is great and people now once more start to request a SWT-Port for QT. I don't know if any company is going to invest the development resources into such a port at least I haven't heard anything.

From UFaceKit point of view the announcement is great because we've been working since some time on an UFaceKit-Implementation for QT. Today I invested some time to implement features to render the AddressBook-Application i showed you in my last blog entry

Below is the application rendered using the CleanlooksStyle on MacOSX:



The only change to the code I showed you last week is how the application is launched.
For SWT the launcher looks like this:
public class Launcher {
public static void main(String[] args) {
final Display display = new Display();

Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
JFaceFactory factory = new JFaceFactory();
Workbench workbench = new Workbench(factory);
workbench.open();

while( ! workbench.isDisposed() ) {
if( ! display.readAndDispatch() ) {
display.sleep();
}
}
}
});
}
}

And for QT:
public class Launcher {
public static void main(String[] args) {
QApplication.initialize(new String[0]);
QApplication.setStyle(new QCleanlooksStyle());

Realm.runWithDefault(QTObservables.getRealm(), new Runnable() {
public void run() {
QTFactory factory = new QTFactory();
Workbench workbench = new Workbench(factory);
workbench.open();
QApplication.exec();
}
});
}
}


And now with styles applied the whole application looks like this:



I'm still in the process to make myself familiar with the QT-API and how I'm supposed to use and implement certain functions. Even if you don't want to use our UFaceKit-API the work we are doing here is interesting to you probably because we provide for example QTObservables for use with Eclipse-Databinding and a Combo/List/Table/Tree-Viewer implementation for QT-Controls.

UFaceKit Dokuware

I was asked to provide instructions how to get the applications I show in my blog running the locally and play with them. I've opened a new section in the Eclipse-Wiki holding all informations about our project - outlining our goals, instructions how to get the current code base running, and hopefully much more information soon.

Wednesday, January 14, 2009

Pimp your application L&F with UFaceKit

Does your application look like this or hopefully a bit better than this really ugly example?

Making applications look nice and still not cluttering your code with these theming informations is something not provided out of the box by Eclipse. Still the situation is changing since the E4-Team is working on "native" SWT-CSS integration (Kevin McGuire and Kai Tödter) - if I'm not mistaken the code should in theory also work in 3.x.

But besides E4 there's another project called UFaceKit which provides a high-level widget-toolkit API (the application above is written with UFaceKit in about ~250 Lines of code) and part of this high-level abstraction is direct support for Declarative-Styleing.

Let's at first take a look at the above application. I've split it into 3 Classes:

When coding with UFaceKit and you choose to use the SWT-Implementation (we also provide Swing and QT though SWT is the most stable and feature rich) you get the native platform L&F (as you see above) but the application is not really visually appealing.

If you don't have support for declarative styling you'd now have to clutter your code with themeing informations (e.g. setting background-colors, ...) and your code is soon getting unmaintainable. The Web-Guys already found this out for a while and invented CascadingStyleSheets (CSS). So why not learning from them and bring CSS (I more like the term Declarative-Styleing) to the world of Java-Desktops.

As mentionned before the E4-Team is working on CSS support and so does UFaceKit but this is not the only thing. UFaceKit abstracts styling support and you can plug-in your own declarative syntax. Out of the box we support:

  • CSS: Like you know it from Web-Development. We currently don't support all features from CSS2 but only the most important ones

  • USML: UFaceKitStylingMarkupLanguage is a very simply XML-Definition for css-like styles which has the adavantage that it doesn't add any dependencies like CSS-Support does


As state we don't suppport all features CSS2 defines but a subset of the most important things:

  • ID-Definitions like #myelement { }

  • Class-Definitions like .mylabel { }

  • Element-Definitions like UILabel { }

  • Support for pseudo-Attributes like :hover, :focus

  • Support for attribute-selectors like .mylabel[@value >= 10]


Let's see what we can achieve by adding this styling support our application.


Amazing isn't it? No single line of application code has changed between those screenshots! As you might noticed I've used Kai Tödters E4-Example application as master and the data is backed up in XMI useing the EMF-Toolchain.

What can you expect in future from UFaceKit:

  • Working on better support for Swing (many Styling things are missing)

  • Working on better support for QT (some styling and control things are missing)

  • Finishing implementation of current API functions

  • Adding JUnit-Test, ...

  • Declarative Syntax to describe and visual design your UI using EMF

  • ...


As you see there's much work that needs to be done and if you are interested in helping out you are more than welcome.

Thursday, January 08, 2009

Where do you go (JFace)Viewers

The presence


Today I thought about a problem of JFace-Viewers when it comes to clever memory management like it is provided for example by CDO. CDO has a very clever memory management concept where objects are swapped out of the memory if they are not referenced in application code.

When using CDO in conjunction with JFace-Viewers this concept doesn't work because JFace-Viewers restore the model element into the TableItem/TreeItem-data-slot and so CDOs clever memory management is not working and the whole model resides in memory.

Inspired by Ed's efforts to minimize the memory footprint of EObject (see bug 252501), I started to think how we could improve on the other side of the fence. I've started today implementing a set of specialized viewer classes which makes it possible for you to take advantage of the clever memory management supplied for example by CDO.

The idea is simple. Instead of restoring the real object in the viewer the object gets translated into a key value (in case of CDO it could the a CDOID) and so CDO can free memory ASAP. The code is available from the UFaceKit-Repository because the scope of UFaceKit is also to provide higherlevel utilities for current Eclipse-Technologies beside inventing it's own high-level API.

The future


The Viewer-Concept provided by JFace for StructuredControls (Combo, List, Table, Tree, TreeTable) is one of the most used concept in Eclipse-Applications and although they are very powerful and we fixed many deficiencies we could provide much better useablility and user experience in E4.

Some of them coming to my mind are:

  • No Toolkit-Independence we can only target SWT like controls

  • Usage of Java5 generics

  • Multiple different APIs to achieve solve a problem

  • Problem with memory intensive models

  • (Fill in your favorite problem)



If you are a regular reader of my blog you know that in my UFaceKit-Project I've already written a JFace-Viewer like implementation for other widget toolkits (QT, Swing). I've today restarted think whether this would be a good thing for E4 in general and so I filed bug 260451.

I'd like to see Eclipse-Viewer getting a project like Eclipse-Databinding which is split into a general and toolkit specific part and integrate itself seamless into the concepts provided by Eclipse-Databinding. I'd invite all of you to take part in a renewed implementation of the viewer concept by adding yourself to bug 260451 and take part in the design discussion hopefully takeing place there.

The intial list of points I'd mentionned in the bug are:

  • Cross-Toolkit like Eclipse-Databinding I'd like to see Viewers getting split
    a Toolkit-Neutral and Toolkit-Specific API so that implementation for e.g.
    Swing, QT, ... can be created.

  • Better support for big model graphs (e.g. better support for CDO) (see bug
    260422
    )

  • Revised inline editing

  • Direct-Databinding support

  • Builtin support Async-Programming (see bug 253777)

  • Support for Java5-Generics

  • Builtin databinding support (e.g. a Viewer could direclty implement the
    IObservableValue interface)