Custom element parsers for UiBinder

581 views
Skip to first unread message

ggeorg

unread,
Jan 6, 2010, 3:00:44 PM1/6/10
to Google Web Toolkit Contributors

Ray Ryan

unread,
Jan 6, 2010, 3:45:33 PM1/6/10
to google-web-tool...@googlegroups.com
Nice work!

Short answer is you can't yet (I know, not what you wanted to hear). We're not crazy about the internal API yet, and we haven't settled on a registration mechanism. I don't have an ETA, and I can't promise it will make GWT 2.1 (although you've certainly just made the need a lot more apparent).

A nit: we've tried to keep a convention of using lower case names for XML elements that don't correspond to runtime objects, so <l:BoxLayoutData> should probably be <l:boxLayoutData>.

If you want to get this out the door in the meantime, I'm afraid you'll have to copy and paste UiBinderGenerator and UiBinderWriter, and provide some gwt.xml magic to let your generator run instead of ours for GWT.create calls on UiBinder.class. 

Another alternative is to do some classpath cheating. Patch UiBinderWriter to register your parsers, and put your version in the Mosaic jar. If your users put your jar in the classpath before gwt's, you should be good to go. 

rjrjr

ggeorg

unread,
Jan 6, 2010, 4:31:55 PM1/6/10
to Google Web Toolkit Contributors
Hi,

thanks for the reply.

> A nit: we've tried to keep a convention of using lower case names for XML
> elements that don't correspond to runtime objects, so <l:BoxLayoutData> should
> probably be <l:boxLayoutData>.

OK, I will do the required changes to keep the same convention.

> If you want to get this out the door in the meantime, I'm afraid you'll have
> to copy and paste UiBinderGenerator and UiBinderWriter, and provide some
> gwt.xml magic to let your generator run instead of ours for GWT.create calls
> on UiBinder.class.

I tried to rename UiBinderGenerator and UiBinderWriter but there is a
problem with the
ElementParser.parse(XMLElement elem, String fieldName, JClassType
type, UiBinderWriter writer)
it requires a UiBinderWriter.

Extending UiBinderWriter is also not possible since all register
methods are private.

> Another alternative is to do some classpath cheating. Patch UiBinderWriter
> to register your parsers, and put your version in the Mosaic jar. If your
> users put your jar in the classpath before gwt's, you should be good to go.

Maybe I keep this for simplicity. This is what I do so far.

Can I post a patch for GWT-2.1 as a temporary solution, that allows
registration of custom handlers, until you provide a final API for
UiBinder generator?

Thanks,
George.

Ray Ryan

unread,
Jan 6, 2010, 5:04:46 PM1/6/10
to google-web-tool...@googlegroups.com
How could I stop you? :-)

Would you making an issue tracker entry about this and putting the patch there? 

ggeorg

unread,
Jan 6, 2010, 5:07:17 PM1/6/10
to Google Web Toolkit Contributors
OK, sure.
Thanks.

Sami Jaber

unread,
Jan 6, 2010, 5:19:50 PM1/6/10
to google-web-tool...@googlegroups.com
Please Ray, when you have anything in terms of design doc regarding the Element Custom Parser API (what a cool name, ECP ;-)), let us know thru the list.
The options that will be made here are going to engage all the third party framework that will stick on it...
btw, keep up the good work George, Mosaic is really cool  (do you still have any dependency with incubator projects components? this project is supposed to disappear ...)

Sami

On Wed, Jan 6, 2010 at 11:04 PM, Ray Ryan <rj...@google.com> wrote:
How could I stop you? :-)

Would you making an issue tracker entry about this and putting the patch there? 


ggeorg

unread,
Jan 6, 2010, 5:47:39 PM1/6/10
to Google Web Toolkit Contributors
Hi Sami,

yes I still use the ScrollTable and PagingScrollTable. I am thing
about forking them if they do not appear in the main GWT trunk very
soon.

George.

ggeorg

unread,
Jan 8, 2010, 11:30:34 AM1/8/10
to Google Web Toolkit Contributors
Hi Ray,

Please have a look at:

http://code.google.com/p/google-web-toolkit/issues/detail?id=4461

the attached patch is the simplest patch I could make. It adds support
for adding custom ElementParser(s) to UiBinder by tagging each widgets
that is using a custom parser with the @ElementParserToUse annotation,
e.g.: for GWT Mosaic's LayoutPanel the code is:

@ElementParserToUse(className =
"org.gwt.mosaic.ui.elementparsers.LayoutPanelParser")
public class LayoutPanel extends AbsolutePanel implements
HasLayoutManager,
HasAnimation {
...
}

----

After applying the patch, the UiBinderWriter.registerParsers() looks
like this:

private void registerParsers() {
// TODO(rjrjr): Allow third-party parsers to register themselves
// automagically

addElementParser("com.google.gwt.dom.client.Element",
"com.google.gwt.uibinder.elementparsers.DomElementParser");

// Register widget parsers.
addWidgetParser("UIObject");
addWidgetParser("HasText");
addWidgetParser("HasHTML");
addWidgetParser("HasWidgets");
addWidgetParser("HTMLPanel");
addWidgetParser("DockPanel");
addWidgetParser("StackPanel");
addWidgetParser("DisclosurePanel");
addWidgetParser("TabPanel");
addWidgetParser("MenuItem");
addWidgetParser("MenuBar");
addWidgetParser("RadioButton");
addWidgetParser("CellPanel");
addWidgetParser("CustomButton");
addWidgetParser("DialogBox");
addWidgetParser("LayoutPanel");
addWidgetParser("DockLayoutPanel");
addWidgetParser("StackLayoutPanel");
addWidgetParser("TabLayoutPanel");

// Register custom widget parsers... (almost automagically)

Collection<OwnerField> uiFields = ownerClass.getUiFields();

if (uiFields == null) {
return;
}

for (OwnerField uiField : uiFields) {
JClassType fieldType = uiField.getType().getRawType().isClass();
String uiClassName = fieldType.getQualifiedSourceName();

if (elementParsers.containsKey(uiClassName)) {
continue;
}

if (fieldType != null
&& fieldType.isAnnotationPresent(ElementParserToUse.class))
{
String parserClassName = fieldType.getAnnotation
(ElementParserToUse.class).className();
if (parserClassName != null && parserClassName.length() > 0) {
addElementParser(uiClassName, parserClassName);
}
}
}
}


Kind Regards,
George.


On Jan 7, 12:04 am, Ray Ryan <rj...@google.com> wrote:

Miroslav Pokorny

unread,
Jan 8, 2010, 4:09:03 PM1/8/10
to google-web-tool...@googlegroups.com, Google Web Toolkit Contributors
In your ElementParserToUse annontation why not pass the class instead
of classname which enforces some typesafety.

On 09/01/2010, at 3:30 AM, ggeorg <georgopoul...@gmail.com>
wrote:

> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors

ggeorg

unread,
Jan 8, 2010, 4:18:03 PM1/8/10
to Google Web Toolkit Contributors
Because the ElementParser is not in the client package.

On Jan 8, 11:09 pm, Miroslav Pokorny <miroslav.poko...@gmail.com>
wrote:


> In your ElementParserToUse annontation why not pass the class instead  
> of classname which enforces some typesafety.
>

> On 09/01/2010, at 3:30 AM, ggeorg <georgopoulos.georg...@gmail.com>  

Daniel Dietrich

unread,
Jan 19, 2010, 7:01:49 PM1/19/10
to Google Web Toolkit Contributors
Hi George,

in your solution parsing of an annotated widget will not be custom
if the widget is not injected into a field, right?

Here's a different idea:

http://cafebab3.blogspot.com/2010/01/non-intrusive-gwt-2-mod-2nd-part.html

Perhaps it is useful for you...

Kind regards

Daniel

G. Georgopoulos

unread,
Jan 21, 2010, 10:52:38 AM1/21/10
to google-web-tool...@googlegroups.com
Hi Daniel,

I think if you do not inject it into a field, you don't need the custom
parser to be registered at all, but I am not sure about that.

I will check your code later today.

Thanks,
George.

>> if (parserClassName != null&& parserClassName.length()> 0) {

Reply all
Reply to author
Forward
0 new messages