I would like my uiBinder to use a ClientBundle which will provide some runtime customized labels. Kind of a TextResource but not from a text file !
I tried with GwtCreateResource but from the DevGuide it seems like it's not possible. Am I right ? (create() and name() are the only methods available)
What I would like to achieve is something like this:
client bundle:
public interface MyWidgetResources extends ClientBundle {
GwtCreateResource<WidgetLabels> labels();
@Source("lol.css")
CssResource style();
}
labels class:
public final class MyWidgetLabels {
public String title() {
return load("mywidget-title");
}
public String banner() {
return load("mywidget-banner");
}
private String load(String key) {
// load from external..
}
}
uiBinder:
<ui:with type="com.package.MyWidgetResources" field="res"/>
<gwt:SimplePanel>
<gwt:Label text="{res.labels.title}"></gwt:Label>
<gwt:Label text="{res.labels.banner}"></gwt:Label>
</gwt:SimplePanel>
My code looks like this already but res.label.title
does not work because GwtCreateResource can only serve as class instantiator (res.labels.create().title()
).
Is there a solution for me ? Maybe with a custom ResourceGenerator ?
As long as
MyWidgetLabels
can be created by GWT.create, you can put anything you want into that type, and you can make it behave however you'd like. You will need thecreate
reference in your uibinder as you suggested at the end of the post to actually build the object, so your lines will look about like this:Each
.
separated piece (except the first, which is a ui:field/@UiField) is a no-arg method to be called - you declaredlabels()
inMyWidgetResources
,create()
already existed inGwtCreateResource
, and you createdtitle()
in your ownMyWidgetLabels
type.Since that first piece is a ui:field/@UiField, you could have another that references
res.labels.create
as something likelabels
so that later you could instead say:Finally, yes, you could build your own ResourceGenerator which would enable you to do whatever you wanted to emit the type in question, as long as you extended the
ResourcePrototype
type and had agetName()
method.