Thursday, May 27, 2010

Re: Using HTMLPanel with UiBinder

Thanks for the reply Thomas.

Perhaps what I'm doing is premature optimisation.

I'm trying to make my widget simpler, by not using a composite. What I
have looks like this:

Foo.java:

class Foo extends ComplexPanel {
...ui binder boilerplate...
@UiField
Element childLocation;
public Foo() {
setElement(ui.createAndBindUi(this));
}

@Override
public void add(Widget child) {
// record the child widget for attachment during onLoad()
this.child = child;
}
@Override
protected void onLoad() {
addAndReplaceElement(child,
childLocation.<com.google.gwt.user.client.Element>cast());
}
private void addAndReplaceElement(Widget widget,
com.google.gwt.user.client.Element toReplace) {
... copied from HTMLPanel ...
}
}

Foo.ui.xml:

<ui:UiBinder
xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
>

<div>
...plain html...
<span ui:field="childLocation"/>
...more html...
</div>

</ui:UiBinder>

So my template is simpler than a Composite would be.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment