If I want to extend the functionality of an existing widget using
code, I have the following two options:
1. Extend the class directly.
2. Extend Composite, include an instance of the base class using
initWidget, and forward any required methods.
Each method has its own merits, depending on the exact requirements.
However, using the UIBuilder approach, I can only seem to do the
second method. The problem with the first appears to be that
"createAndBindUi" requires an existing class to be passed in, but
returns a new Widget, and the only way to incorporate this is by
method 2.
For example, to create a decorator panel with a caption using the
UIBuilder, I can do the following (method 2):
<ui:UiBinder xmlns... >
<g:DecoratorPanel>
<g:HTMLPanel>
<div>Caption Here</div>
</g:HTMLPanel>
</g:DecoratorPanel>
</ui:UiBinder>
public class MyPanel extends Composite {
interface Binder extends UiBinder<DecoratorPanel, MyPanel> {}
private static final Binder binder = GWT.create(Binder.class);
public MyPanel() {
initWidget(binder.createAndBindUi(this));
}
}
But not by extending the class directly.
Actually, this is not strictly true. Given the same ui.xml file, the
following code does exactly what I want:
public class MyPanel extends DecoratorPanel {
interface Binder extends UiBinder<DecoratorPanel, MyPanel> {}
private static final Binder binder = GWT.create(Binder.class);
public MyPanel() {
replaceElement(binder.createAndBindUi(this).getElement());
}
}
But to call "replaceElement" I have to put my class in the
"com.google.gwt.user.client.ui" package to access the method (which is
declared with package visibility) and ignore the javadoc warning:
"This method exists only to support a specific use-case in Image, and
should not be used by other classes."
Which is obviously not an ideal solution.
Is there any reason "replaceElement" is restricted? Or any other way
to achieve the same result?
Cheers,
Barney
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.