Wednesday, January 20, 2010

Non-intrusive GWT 2 mod [2nd part]

As mentioned in the last post I want to describe how to register custom element parsers for GWT 2.0 ui binding. I use a Java Annotation @ElementParserToUse(className="your.Parser") (as suggested a few days ago by George Georgopoulos (ggeorg)). This Annotation is added to custom widgets which should be parsed in a custom way.

Element Parsers are registered on-demand (if not registered yet) by adding the highlighted lines to UiBinderWriter.getParserForClass(JClassType uiClass):

Additionally the following method has to be added to UiBinderWriter:

Note

The method getParserForClass(JClassType uiClass) is called within getParsersForClass(JClassType type) which iterates the class hierarchy of the current Widget (corresponding to the current .ui.xml element). Because of the class hierarchy is created by a breadth-first search algorithm it is ensured that parsers are returned from most specific to most general (in oo manner). That means that custom parsers do their job first. That's necessary because xml artifacts are consumed by the ui binder framework (at least they should be) and so there's no second chance to parse them.

In the next post [3rd part] I will introduce custom parsers for the Ext GWT Widgets shown in the post GWT 2 Declarative Layout: Beyond UIBinder.

1 comment:

  1. I found this quite useful. Current state of GWT SDK is actually locking us into either GWT's own widgets, or single element Widgets. Thank you

    Have you considered posting this patch for review to GWT devs?

    ReplyDelete