package com.antonytrupe.client.activity;
import com.antonytrupe.client.ClientFactory;
import com.antonytrupe.client.place.EditPlace;
import com.antonytrupe.client.ui.EditView;
import com.antonytrupe.shared.Page;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
public class EditActivity extends AbstractActivity implements
EditView.Presenter {
private ClientFactory clientFactory;
private EditPlace place;
public EditActivity(EditPlace place, ClientFactory clientFactory) {
this.place = place;
this.clientFactory = clientFactory;
}
@Override
public void goTo(Place place) {
this.clientFactory.getPlaceController().goTo(place);
}
@Override
public void start(final AcceptsOneWidget containerWidget, EventBus eventBus) {
final EditView editView = this.clientFactory.getPageEditView();
// get page content
this.clientFactory.getPageService().get(
this.place.getPageNameDecoded(), new AsyncCallback<Page>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Page result) {
editView.setPageName(result.getName());
editView.setContent(SafeHtmlUtils
.fromTrustedString(result.getContent()));
editView.setPresenter(EditActivity.this);
editView.setPageService(EditActivity.this.clientFactory
.getPageService());
containerWidget.setWidget(editView.asWidget());
}
});
}
}