Skip to content

Instantly share code, notes, and snippets.

@nbuesing
Last active December 26, 2015 03:39
Show Gist options
  • Select an option

  • Save nbuesing/7087667 to your computer and use it in GitHub Desktop.

Select an option

Save nbuesing/7087667 to your computer and use it in GitHub Desktop.
GwtMockitoBlogSampleWidget
public class SampleWidget implements IsWidget {
private EventBus bus = GWT.create(SimpleEventBus.class);
private VerticalPanel panel = GWT.create(VerticalPanel.class);
public SampleWidget() {
final Button button = GWT.create(Button.class);
button.setText("Click me");
final Label label = GWT.create(Label.class);
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (label.getText().equals("")) {
SampleApplicationService.App.getInstance().getMessage("Hello, World!", new MyAsyncCallback(label));
} else {
label.setText("");
}
bus.fireEvent(new MyEvent());
}
});
final HTML html = GWT.create(HTML.class);
bus.addHandler(MyEvent.getType(), new MyEvent.MyEventHandler() {
public void doSomething(MyEvent event) {
html.setHTML("event fired.");
}
});
panel.add(button);
panel.add(label);
panel.add(html);
}
private static class MyAsyncCallback implements AsyncCallback {
private Label label;
public MyAsyncCallback(Label label) {
this.label = label;
}
public void onSuccess(String result) {
label.getElement().setInnerHTML(result);
}
public void onFailure(Throwable throwable) {
label.setText("Failed to receive answer from server!");
}
}
public Widget asWidget() {
return panel;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment