getView().setSubmitHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (checkLogin() == null) return;
getEventBus().fireEvent(new LoadingOverlayEvent(true));
NewCommentAction newCommentAction = new NewCommentAction(getComment());
dispatcher.execute(newCommentAction, new AsyncCallback<Comments>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Sorry, server error, retry later.");
Window.alert(caught.toString());
getEventBus().fireEvent(new LoadingOverlayEvent(false));
}
@Override
public void onSuccess(Comments newComment) {
Window.alert("New comment success: " + newComment.getComment());
getView().setExistingComment(null);
if (submission != null) {
submission.success(newComment);
}
getEventBus().fireEvent(new LoadingOverlayEvent(false));
}
});
}
});
getView().setVoteHandler(new VoteEvent() {
@Override
public void vote(boolean up) {
SessionInformation sessionInformation = checkLogin();
if (sessionInformation == null) return;
getEventBus().fireEvent(new LoadingOverlayEvent(true));
String loggedInUser = sessionInformation.getEmailAddress();
CommentVoteAction commentVoteAction = new CommentVoteAction(loggedInUser, comment.getUri(), up);
dispatcher.execute(commentVoteAction, new AsyncCallback<CommentVoteResult>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Sorry, server error, retry later.");
Window.alert(caught.toString());
getEventBus().fireEvent(new LoadingOverlayEvent(false));
}
@Override
public void onSuccess(CommentVoteResult result) {
switch (result.getResult()) {
case ALREADY_VOTED:
Window.alert("You already voted!");
break;
case SUCCESS:
comment.setVoting(result.getVotes());
setExistingComment(comment);
break;
}
getEventBus().fireEvent(new LoadingOverlayEvent(false));
}
});
}
});
}