/**
*
*/
package org.mbhcare.client.presenter;
import org.mbhcare.client.view.patients.PatientsView;
import org.mbhcare.client.view.patients.PatientsEditViewImpl;
import org.mbhcare.client.view.patients.PatientsListViewImpl;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HasWidgets;
/**
* @author MCOSTA
*
*/
public class PatientsPresenter implements Presenter, PatientsView.Presenter {
private static final String VIEW = MainPresenter.VIEW_PATIENTS;
private static PatientsListViewImpl patientsListView = null;
private static PatientsEditViewImpl patientsEditView = null;
private final PatientsView view;
/**
* @param view
*/
public PatientsPresenter(PatientsView view) {
this.view = view;
}
@Override
public void go(final HasWidgets container) {
container.clear();
container.add(view.asWidget());
processHistoryToken();
}
public void processHistoryToken() {
String token = History.getToken();
if(token != null) {
if (token.startsWith(VIEW + "/edit")) {
String[] parts = token.split("/");
String id = null;
if(patientsEditView == null)
patientsEditView = new PatientsEditViewImpl();
// is a edit statement?
if(parts.length > 3) id = parts[parts.length - 1];
new PatientsEditPresenter(patientsEditView, id).
go(view.getContent());
} else {
if(patientsListView == null)
patientsListView = new PatientsListViewImpl();
new PatientsListPresenter(patientsListView).
go(view.getContent());
}
}
}
}