Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class UserPresenter
extends Presenter<UserPresenter.MyView, UserPresenter.MyProxy>
implements UserUiHandlers {
interface MyView extends View, HasUiHandlers<UserUiHandlers> {
void displayUser(User user);
}
// ...
private final PlaceManager placeManager;
private final ResourceDelegate<UserApi> userApiResourceDelegate;
@Inject
UserPresenter(
EventBus eventBus,
MyView view,
MyProxy proxy,
PlaceManager placeManager,
ResourceDelegate<UserApi> userApiResourceDelegate) {
super(eventBus, view, proxy, RevealType.Root);
this.placeManager = placeManager;
this.userApiResourceDelegate = userApiResourceDelegate;
getView().setUiHandlers(this);
}
@Override
public void prepareFromRequest(PlaceRequest request) {
int userId = parseUserIdFromPlaceRequest(request);
userApiResourceDelegate.withCallback(new RestCallbackImpl<User>() {
@Override
public void onSuccess(User user) {
getView().displayUser(user);
}
}).getUser(userId);
}
private int parseUserIdFromPlaceRequest(PlaceRequest placeRequest) {
String idParameter = placeRequest.getParameter(NameTokens.PARAM_ID, "");
return Integer.parseInt(idParameter);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment