package com.antonytrupe.client.ui;
import com.antonytrupe.client.PageServiceAsync;
import com.antonytrupe.client.place.DisplayPlace;
import com.antonytrupe.shared.Page;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
public class RevisionViewImpl extends Composite implements EditView {
interface RevisionViewImplUiBinder extends
UiBinder<Widget, RevisionViewImpl> {
}
private static RevisionViewImplUiBinder uiBinder = GWT
.create(RevisionViewImplUiBinder.class);
@UiField
ContentViewImpl content;
@UiField
Label date, user, ipaddress;
@UiField
Button revert;
@UiField
DisclosurePanel container;
private Page revision;
private PageServiceAsync pageService;
private Presenter listener;
public RevisionViewImpl(final PageServiceAsync pageService) {
initWidget(uiBinder.createAndBindUi(this));
this.pageService = pageService;
}
@UiHandler("revert")
void onEdit(ClickEvent e) {
// do the save
this.save();
}
@Override
public void save() {
this.pageService.save(this.revision, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
@Override
public void onSuccess(Void result) {
// go to the page
RevisionViewImpl.this.listener.goTo(new DisplayPlace(
RevisionViewImpl.this.revision.getName()));
}
});
}
public void setContent(Page revision) {
this.revision = revision;
String diff = this.revision.getDiff();
if (diff != null) {
this.setContent(SafeHtmlUtils.fromTrustedString(this.revision
.getDiff()));
}
this.date.setText(this.revision.getDate().toString());
this.user.setText(this.revision.getUser());
this.ipaddress.setText(this.revision.getIpAddress());
}
@Override
public void setContent(SafeHtml content) {
this.content.setContent(content);
}
public void setOpen(boolean first) {
this.container.setOpen(first);
}
@Override
public void setPageName(String name) {
// noop
}
@Override
public void setPageService(PageServiceAsync pageService) {
this.pageService = pageService;
}
public void setPresenter(
com.antonytrupe.client.ui.HistoryView.Presenter listener) {
this.listener = (Presenter) listener;
}
@Override
public void setPresenter(Presenter listener) {
this.listener = listener;
}
}