Skip to content

Instantly share code, notes, and snippets.

@spg
Last active December 18, 2015 00:59
Show Gist options
  • Save spg/5700772 to your computer and use it in GitHub Desktop.
Save spg/5700772 to your computer and use it in GitHub Desktop.
// ===== USAGE
private void fetchevent() {
eventService.getEvent(id, new MethodCallbackImpl<Event>() {
@Override
public String getErrorMessage() {
return "Could not fetch event " + id;
}
@Override
public void onSuccess(Event event) {
displayEvent(event);
}
});
}
// ===== THE ABSTRACT CLASS
package com.sceneverse.shozon.client.util;
import org.fusesource.restygwt.client.Method;
import org.fusesource.restygwt.client.MethodCallback;
import com.google.gwt.user.client.Window;
public abstract class MethodCallbackImpl<T> implements MethodCallback<T> {
@Override
public void onSuccess(Method method, T result) {
onSuccess(result);
}
@Override
public void onFailure(Method method, Throwable throwable) {
String message = getErrorMessage();
Window.alert(message);
}
public abstract String getErrorMessage();
public abstract void onSuccess(T result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment