Thursday, September 23, 2010

Custom Widget ui Binder and a constructor that takes other widgets

I've got a custom widget (code below) that takes in two widget's as a
constructor. I'd like to use this widget in UI Binder. I can see
from the docs (http://code.google.com/webtoolkit/doc/latest/
DevGuideUiBinder.html#Using_a_widget
) that it's pretty easy to do this
if the constructor is a set of strings, but how would I do this if I
want the constructor args to be Widget. I'm sure this isn't right,
but I'm looking for something like this:

<my:FocusChangeWidget ui:field='nameField'>
<g:Label>Doctor Suess</g:Label>
<g:TextBox ui:field="nameInputField"/>
</my:FocusChangeWidget>

Here's the code so you can see what I'm referring to:

public class FocusChangeWidget extends Composite {

private FocusPanel container = new FocusPanel(); // the container for
the custom widget
Widget displayWidget; // the main display widget and what we display
first
Widget changeWidget; // what we display when we get focus

public FocusChangeWidget (Widget displayWidget, Widget changeWidget)
{
this.displayWidget = displayWidget;
this.changeWidget = changeWidget;
container.add(displayWidget);
initWidget(container);
container.addFocusHandler(new FocusChangedHandler());
}


private class FocusChangedHandler implements FocusHandler {

@Override
public void onFocus(FocusEvent event) {
container.clear();
container.add(changeWidget);
}

}
}

--
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