Background to QxWT and GWT-Generator integration

One of the very nice feature of the GWT-Compiler is that one can plug oneself into it and create classes dynamically. At the last 2 evenings I digged a bit into it because I was in need of creating qooxdoo-class dynamically.

Short background to qooxdoo

Before I start explaining the small generator we first need to understand how qooxdoo works and how QxWT interfaces with it.

Let’s at first take a look at the JavaScript world and how a Label-Widget is defined (this is not 100% the real JS-Code but only shows the parts we are interested in for now):

qx.Class.define("qx.ui.basic.Label",
  extend : qx.ui.core.Widget,

  properties : {
    value : {
      check : "String",
      event : "changeValue",
      nullable : true
    }
    // more properties
  }
  // more definitions
);

The above defines a class mydemo.Person which has a property name which is of type String and can be null and in addition when the value is changed an event changeName is delivered to interested parties.

When using this newly defined class in plain JavaScript one can use it like this:

var l = new qx.ui.basic.Label();
l.setValue("Tom Schindl");
alert(p.getValue());

This works because qooxdoo dynamically generates accessor-methods for properties.

Short background to QxWT

Now the whole thing about GWT is that you don’t have to have JavaScript knowledge (though understanding the main JavaScript concepts is helps naturally) to write Web-Applications and if you want to work with a “native” library like qooxdoo you need some library which exposes the native-objects and data-types as Java-Objects/data-types and that’s exactly what QxWT does for qooxdoo.

The process is quite easy. QxWT defines a Java-Class for every JavaScript-class the qooxdoo framework defines itself. So you’ll find in the downloaded sources a class org.ufacekit.qx.wrapper.ui.basic.QxLabel, org.ufacekit.qx.wrapper.ui.core.QxWidget, … and the class definition looks like this:

public class QxLabel extends QxWidget implements IQxStringForm {
}

When we compare the inheritance of the JavaScript and Java-Classes we’ll notice that QxWT reflects the JavaScript inheritance 1:1 to Java.

qooxdoo QxWT

The next important thing we need to know is how to restore Native-JavaScript-Objects in our Java-Class. To make this possible GWT provides us a class named com.google.gwt.core.client.JavaScriptObject. The central point for QxWT to restore this native object is in the class QxObject because fairly all classes in QxWT inherit from there:

public class QxObject implements IQxObject, IMQxBinding {
   private JavaScriptObject nativeObject;
   // ...
   /**
    * <p>
    * <b>PLEASE NOTE: Only for internal use</b>
    * </p>
    * Create a new QxWT wrapping a native Qooxdoo-Object
    * 
    * @param nativeObject
    *            the native widget to wrap
    */
    public QxObject(JavaScriptObject nativeObject) {
      this.nativeObject = nativeObject;
      QxHelper.setAssociatedObject(nativeObject, this);
    }

    /**
     * @return Get the wrapped Qooxdoo-Instance
     */
    public JavaScriptObject getNativeObject() {
      return nativeObject;
    }
}

Please note that we also store a reference to the Java-Object in the Java-Script-Object (Line 15) like this:

public class QxHelper {
  /**
   * Associate a Java-Object with a JavaScript one
   * 
   * @param o
   *            the js object
   * @param obj
   *            the java object
   */
  public static native void setAssociatedObject(JavaScriptObject o, Object obj) /*-{
    o._gwt = obj;
  }-*/;
}

because sometimes we need to find our way back from JavaScript to Java.

The only thing we need to do now is to create an qooxdoo-Instance whenever we create a Java-Instance of a QxWT-Class which is naturally done best in the constructor:

public class QxLabel extends QxWidget implements IQxStringForm {
  public QxLabel() {
    super(createNativeObject());
  }

  private static native JavaScriptObject createNativeObject() /*-{
    return new $wnd.qx.ui.basic.Label();
  }-*/;
}

You might have noticed this your own but when binding to native code inside your Java-Classes you simply define the method as native and write your JavaScript inside the /*-{ }-*/ comment.

The last step in the QxWT-Port is to provide wrapper methods for all API-methods defined by the qooxdoo class which looks like this for the value attribute of QxLabel:

public class QxLabel extends QxWidget implements IQxStringForm {
  public native void setValue(String value) /*-{
    var self = this.@org.ufacekit.qx.wrapper.core.QxObject::getNativeObject()();
    self.setValue(value);
  }-*/;

  public native String getValue() /*-{
    var self = this.@org.ufacekit.qx.wrapper.core.QxObject::getNativeObject()();
    return self.getValue();
  }-*/;
}

As you see we are retrieving the native-qooxdoo-instance through the getNativeObject()-call and afterwards simply call the desired method on the JavaScript-object.

The GWT-Generator

The above described implementation works well and is used in QxWT for all classes which are defined by qooxdoo but it fails if you need to create your own qooxdoo classes e.g. to present your domain model. You might ask why you want to define you domain model in JavaScript if you are working in Java where you can define it as well.

The reason to define the Domain-Model in terms of qooxdoo-classes is to leverage the databinding possibilities coming with qooxdoo itself (there’s upcoming for support for Eclipse Databinding for QxWT but sometimes it might be more natural to use the possibilities coming with qooxdoo itself).

But writing your domain classes in JavaScript and writing a wrapper violates the no JavaScript policy GWT sold you as an advantage. And now at this very point the GWT-Generator steps in. If you look at the code I demonstrated above you’ll notice that the process of creating qooxdoo-class and the java-wrapper could be automated by simply defining some meta-data in your Java-Code and generate the needed bits from it.

So here we go to bring meta informations into Java-Code Java5 introduced the concept of annotations. So we define 2 of them:

@Target(ElementType.TYPE)
public @interface QxClass {
  /**
   * @return Java super class
   */
  String javaSuperClass() default "org.ufacekit.qx.wrapper.core.QxObject";
  /**
   * @return javascript base class
   */
  String jsBaseClass() default "qx.core.Object";

  /**
   * @return the properties
   */
  QxProperty[] properties();
}

to annotate interfaces who will be implemented the generated classes and

public @interface QxProperty {
  /**
   * @return name of the property
   */
  String name();

  /**
   * @return the value to check for e.g. String, ...
   */
  String check();

  /**
   * @return the event
   */
  String event();

  /**
   * @return whether property can be null
   */
  boolean nullable() default false;
	
  /**
   * @return initial value
   */
  String init() default "N/A";
}

The user of QxWT now only has to define an interface like this

@QxClass(properties = {
  @QxProperty(check = "String", event = "changeName", name = "name", nullable = true),
  @QxProperty(check = "String", event = "changeEmote", name = "emote"),
  @QxProperty(check = "Boolean", event = "changeOnline", name = "online", init = "true")		
})
public interface Person extends IQxObject {

  public String getName();

  public void setName(String name);
	
  public String getEmote();

  public void setEmote(String emote);

  public boolean isOnline();

  public void setOnline(boolean online);

  public void toggleOnline();
}

and use it like this:

Person person = GWT.create(Person.class); 
person.setName("Tom Schindl");
person.setEmote("embarrassed");
person.setOnline(false);

This blog now got much longer than I expected so we are looking into how the generator works internally in one of the next posts about QxWT explaining how this objects can be bound directly to QxWT-controls

Posted in QxWT | 3 Comments

Looking back and into the future – Part I

Part I – The Validation

I thought today that I’ll look back on my work in Eclipse space and the final summary is double-edged. There are some things I think I made a good job in the Eclipse Ecosystem, some where my performance was acceptable and some where I can completely failed.

This is my personal report card for 2009 (in no particular order):

  • Telling people about e4 and that it’s not only about bringing Eclipse to the web TOTAL SUCCESS
  • Finding a business model for investing time into coding for e4 (I think that some interesting things won’t be part of e4 1.0 but well that’s something I can’t change). I think I can count my commits on 2 hands TOTAL FAILURE
  • Bringing qooxdoo to Java developers through QxWT TOTAL SUCCESS
  • Getting out a build of UFaceKit and nearing release 1.0.0 of the SWT-Port PARTIAL SUCCESS
  • Advertising Eclipse Databinding and porting it to EMF PARTIAL SUCCESS
  • Finding the time to work on 3.x (when reading blogs like this from Eugene Ostroukhov my willingness to invest spare time on it is equal to 0) TOTAL FAILURE
  • Getting Nebula back into a better state and release 1.0.0 of some really mature widgets PARTIAL SUCCESS
  • Taking part in the Eclipse Architectual Council TOTAL FAILURE
  • Answering question on eclipse.platform.swt, eclipse.platform, eclipse.platform.jface, … SUCCESS (if one can talk about success here)

Looking at this report you can see that from my personal feeling it was quite a intermingled year and that some actions need to be taken to get a better report next year.

I haven’t made up those points before writing this summary so it’s probably too early to draw conclusions but looking at the above I guess I’m going to step back from some of the positions (3.x committer ship, nebula-project lead, newsgroup-support on platform.* and e4 committer ship come to my mind) I filled in the Eclipse Ecosystem.

A more in depth look on possible moves and impacts they might have is going to be part of Part II of this blog series in few days.

Posted in Eclipse | 3 Comments

QxWT 1.0.0.1 released

After releasing version 1.0.0.0 in alignment with qooxdoo 1.0. I’ve worked in the last weeks on improving and fixing the QxWT experience for adopters.

Release 1.0.0.1 holds ~30 bugfixes and new features. The most important new features are:

  • Support for qooxdoo-Forms
  • Improved Table-Setup (back and forth conversion between Java and JavaScript is improved)
  • A frist start for databinding (but this is not finished yet)

I’ve also ported many of the qooxdoo-Demos to QxWT and you can use it as an example for getting started with QxWT beside that I plan to write a getting started guide to help you get started even quicker.

The next release of QxWT (1.0.0.2) is scheduled for End of February 2010 and will hold finished support for qooxdoo-Databinding and improved runtime performance by leveraging the qooxdoo compiler and linker toolchain.

Posted in Announcements, QxWT | 2 Comments

QxWT 1.0.0.0 released

Just like the qooxdoo-Team who today released Version 1.0 of their JavaScript library BestSolution.at and UFaceKit.org are proud to annouce (see official announcement here) the availability of QxWT 1.0.0.0 which exposes this fantastic JavaScript-framework to the GWT-community.

I know that there’s a bunch of other GWT-UI-libraries but I think QxWT provides features not offered by other libraries available. For me and probably others the dual licensing under LGPL and EPL of both qooxdoo and QxWT is very important because this gives adopters the possibility to use it in commercial as well as opensource applications.

Though not the complete qooxdoo-API is wrapped in 1.0.0.0 (~90% of the JavaScript-API available) one can write full featured GWT-Applications with the current set of provided APIs. Take a look at the set of QxWT-Demos available from here.

From a technical point of view QxWT is leveraging the GWT-JSNI calling interface to expose the qooxdoo-JavaScript-API to GWT-Java-Developers. The JS-API is reflected in most cases 1:1 to Java but is GWT/Java-nized in some situations (e.g. usage of Java-Enums, integration into the GWT-Event framework) to make the API more natural for Java-Devs.

Future plans for QxWT:

  • Wrap the rest of qooxdoo-JS-API
  • Improved runtime size by adding post processing step
  • Keep up-to-date with qooxdoo-Releases

To finish this release post I’d like to mention that the release of QxWT is going to build the foundation for other projects already in the queue, some of the available as opensource (like the UFaceKit-port for QxWT) others probably available under commercial licenses.

I hope you’ll give QxWT a spin and report back. Your findings and problems. To collect your feedback we’ve set up a QxWT-Forum.

The current sources are build and tested with GWT 2.0 but should in theory run as well on GWT >= 1.5 though I’d highly recommend the usage of GWT 2.0 because of the many improvements on GWT-Development.

Posted in Announcements, QxWT | 11 Comments

e4 presentation in Zurich on Jan 14th 2010

The JavaUserGroup Switzerland invited me a month ago to give at talk on e4. We’ve now fixed the date and place for the presentation:

Location: Technopark Zurich, Room Fortran
Date: Jan 14th, 2010 – 17:00 – 18:15h: Talk incl. Q/A

The official announcement can be found here. I’m looking forward to Zürich talking about e4 and meeting new people.

Posted in e4, Talks & Conferences | 2 Comments

e4 – some random thoughts (2nd iteration)

At the Vienna DemoCamp it once more became apparent how important e4 is going to be to not loose the whole “Eclipse RCP” market segement. I already blogged some time ago about the problems I have to justify spending workhours on e4.

After the Vienna DemoCamp I reread my blog and restarted a discussion in my own company how I could spend work time on it. The problem is that my company is quite small and it is impossible to let me work on e4 without gaining any money but my two collegues (we are 3 people owning the company + 4 employees) made the offer that for every payed work hours I could allocate for e4-development work we’ll add 50% as our investment which means for every hour I could get sponsorship I could work 1.5 hours on e4 in my worktime.

Now I don’t know how likely it is that I could find sponsors for at least an hour but I want to blog about this possibility because say I manage (because of what ever reason) to get payed for 2 days I could spend 3.

The questions are:

  • Why you should at least spend one penny/cent/… for e4 and/or the core platform so I repeat it once more:

    If you care about Eclipse Technologies in RCP-Space you might get in touch with e4 (contribute, make someone contribute on behalf of you, …) and make it as powerful as possible else you’ll be outperformed by other platforms even in the short term.

    Naturally this is my personal opinion but I worked with some of the competitors in the last weeks and though they are not there yet they’ll be in 1.5 years when e4 1.1 is going to be released. So if some feature you desperately need is not in e4 1.0 you are in trouble because you won’t get it until August 2011.
  • Why should you spend the money on me?
    • You get 50% more than you pay – not a too bad deal, right?
    • I’m a committer already, I know the code base, I know the dev team and they know me. So I could be productive starting from day 1

I would have told this above at the DemoCamp in Hamburg but because of bad wheather conditions in Austria I’m not able to make it there. So while this is probably not the ideal forum with the lack of others I wrote this blog.

Posted in e4 | 2 Comments

Hamburg DemoCamp without me

As nice as it is to live in the center of the alps as bad it can be. We’ve been waiting for snow now for more than 1 month and guess what happened this night? It started snowing and so all flight from Innsbruck got canceled.

So the demo camp will happen without me which really makes me sad because I would have enjoyed meeting new people and presenting them e4.

At least here are the Slides I would have used for the presentation.

Posted in e4, Eclipse, Talks & Conferences | 1 Comment

Vienna DemoCamp

Amazing. Yes it was really amazing to see how much Eclipse-RCP is used in Austria. I got in touch with many people and talked with them about e4 and the vision behind it.

Many of them said that the flexible theming and rendering is something they really need to use Eclipse-RCP-Technology as their target platform (even fairly conservative ones like banks) else the pressure from RIA-Platforms like Silverlight and Flex is getting too big.

My 10 minute presentation was quite well received and I enjoyed my time in Vienna and looking forward now to next demo camp in Hamburg.

Posted in e4, Eclipse, Talks & Conferences | 1 Comment

On DemoCamp-Tour

I’m on the road since yesterday for a week of DemoCamps. The first one is in my homelands capital Vienna on Monday 30th of (M)November and the second one in Hamburg on Firday 4th of December the month following (M)November.

Looking at the number of people registered (77! people in Vienna and 101! people in Hamburg) I think those 2 events (as well as all other DemoCamps all over the world) are a good opportunity to meet people who are not at the big conferences. I’ll spread the word a bit about e4 and show people why we believe in it, what we did and what we plan to do until the 1.0 ships. So it is not late to sign up for the free DemoCamps and meet people of the Eclipse Hall of Fame like Chris Aniszczyk and Jeff McAffer for example in Vienna.

Speaking about presentations I submitted a talk/tutorial proposal for EclipseCon 2010. The deadline for proposals is 20 days from now so don’t miss it and submit your proposal so that people can give feedback which helps the program committee to choose your talk.

Posted in Eclipse, Talks & Conferences | Leave a comment

QxWT 0.8.2.0 Released

I’m happy to announce the 0.8.2.0-Release (yes 4 digit version) of QxWT. I decided to use a 4 digit version because then the first 3 digits reflect the qooxdoo version and the 4th is for bugfixes which are purely QxWT specific.

There’s is a know problem on Linux-Hosted mode which is a problem with the qooxdoo sources but I didn’t investigated why the old mozilla used there fails but instead suggest to use the upcoming GWT 2.0.

I’ve now started working towards 0.8.3 and the first test suggest that I can provide 0.8.3 builds and release candidates quite quickly but this heavily depends on the time I can spend because I’m going to travel a bit in the next weeks.

Posted in Announcements, QxWT | Leave a comment