Here goes... I'm doing a simple form that allows you to browse all
cities whose names start with a given string.
The ui.xml file contains a textbox, a couple of buttons, and a grid;
the relevant lines are:
<g:HTMLPanel>
<h1>CitiesUpdater</h1>
Start of City Name:
<g:TextBox u:field="cityNameStart"/>
<g:Button u:field="getCitiesButton" text="Get Cities"/>
<g:Button u:field="updateCitiesButton" text="Update Cities"/>
<hr />
<g:FlexTable u:field="cg"/>
</g:HTMLPanel>
The View includes:
@UiTemplate("CitiesUpdaterView.ui.xml")
interface Binder extends UiBinder<HTMLPanel, CitiesUpdaterView> {}
private static final Binder binder = GWT.create(Binder.class);
@UiField TextBox cityNameStart;
@UiField Button getCitiesButton;
@UiField Button updateCitiesButton;
@UiField FlexTable cg;
SimpleCallback<Object> onGetCitiesClickCallback;
SimpleCallback<Object> onUpdateCitiesClickCallback;
SimpleCallback<Object> onCityNameStartChangeCallback;
@Override
public void setOnCityNameStartChangeCallback(SimpleCallback<Object>
acb) {
onCityNameStartChangeCallback = acb;
}
@Override
public void setOnGetCitiesClickCallback(SimpleCallback<Object> acb)
{
onGetCitiesClickCallback = acb;
}
@Override
public void setOnUpdateCitiesClickCallback(SimpleCallback<Object>
acb) {
onUpdateCitiesClickCallback = acb;
}
@UiHandler("cityNameStart")
void uiOnChange(ChangeEvent event) {
onCityNameStartChangeCallback.onSuccess(null);
}
@UiHandler("getCitiesButton")
void uiOnGetClick(ClickEvent event) {
onGetCitiesClickCallback.onSuccess(null);
}
@UiHandler("updateCitiesButton")
void uiOnUpdateClick(ClickEvent event) {
onUpdateCitiesClickCallback.onSuccess(null);
}
The Presenter includes:
public CitiesUpdaterPresenter(
final String params, final CitiesUpdaterDisplay
citiesUpdaterDisplay,
final Environment environment) {
// ...
getDisplay().setOnGetCitiesClickCallback(new SimpleCallback<Object>
() {
// ...code to run, when the Get Cities button is clicked
});
getDisplay().setOnUpdateCitiesClickCallback(new
SimpleCallback<Object>() {
// ...code to run when the Update button is clicked
});
getDisplay().setOnCityNameStartChangeCallback(new
SimpleCallback<Object>() {
//...code to run whenever the CityNameStart field changes
}
So...
* the Presenter is injected with the Display (View) to use
* the Presenter injects three callbacks into the View
* the View uses @UiHandler to define three handlers
* the handlers just call the callbacks that were set by the Presenter
Note that SimpleCallback is an extension of AsyncCallback.
I hope this is clearer; I deleted as much code as possible, to make
the example simpler. Please ask again if you have any doubts or
questions.
Best regards,
F.Kereki
--
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.