package com.antonytrupe.client.activity;
import java.util.ArrayList;
import com.antonytrupe.client.ClientFactory;
import com.antonytrupe.client.place.HistoryPlace;
import com.antonytrupe.client.ui.DisplayView;
import com.antonytrupe.client.ui.HistoryView;
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.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
public class HistoryActivity extends AbstractActivity implements
HistoryView.Presenter, DisplayView.Presenter {
private ClientFactory clientFactory;
private HistoryPlace place;
public HistoryActivity(HistoryPlace 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 HistoryView historyView = this.clientFactory.getHistoryView();
// get page content
this.clientFactory.getPageService().getHistory(
this.place.getPageNameDecoded(),
new AsyncCallback<ArrayList<Page>>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(ArrayList<Page> result) {
// tell the view to render
historyView.setPageName(HistoryActivity.this.place
.getPageNameDecoded());
historyView
.setPresenter((HistoryView.Presenter) HistoryActivity.this);
historyView
.setPageService(HistoryActivity.this.clientFactory
.getPageService());
historyView.setHistory(result);
containerWidget.setWidget(historyView.asWidget());
}
});
}
}