Hi guys,
Martin's GinUiBinder patch [1] just landed into master branch.
[1]
http://gerrit.ovirt.org/#/c/34954/
This patch allows the use of dependency injection for widgets
declared in GWT UiBinder templates.
Let's take a look at AbstractVmPopupWidget.ui.xml template:
<vm:SerialNumberPolicyWidget ui:field="serialNumberPolicyEditor"/>
Inside the "owner" widget, AbstractVmPopupWidget class:
@UiField(provided = true) // we need manual instantiation
public SerialNumberPolicyWidget serialNumberPolicyEditor;
We use "provided = true" in order to manually instantiate
SerialNumberPolicyWidget, because this widget accepts some
constructor parameters:
public SerialNumberPolicyWidget(
CommonApplicationTemplates applicationTemplates,
...
)
So in AbstractVmPopupWidget, we need to do following:
serialNumberPolicyEditor = new SerialNumberPolicyWidget(...)
The "provided = true" + "new SerialNumberPolicyWidget(...)"
is essentially a boilerplate that adds to overall complexity.
Now, let's revisit above example using GinUiBinder. First,
in AbstractVmPopupWidget class:
@UiField // no need for manual instantiation
public SerialNumberPolicyWidget serialNumberPolicyEditor;
Then, in SerialNumberPolicyWidget class:
@Inject // inject dependencies into this widget
public SerialNumberPolicyWidget(
CommonApplicationTemplates applicationTemplates,
...
)
And finally, we can remove following line:
// this is no longer needed, GinUiBinder handles it for us
serialNumberPolicyEditor = new SerialNumberPolicyWidget(...)
The complete example can be seen here:
http://gerrit.ovirt.org/#/c/34954/4/frontend/webadmin/modules/gwt-common/...
I encourage every UI maintainer to revisit existing code with
regard to @UiField(provided = true) and refactor/improve it to
take advantage of @Inject in specific widget classes.
Let me (or Martin) know if you have any questions.
Regards,
Vojtech