Package org.mbhcare.client.presenter

Source Code of org.mbhcare.client.presenter.MainPresenter

/**
*
*/
package org.mbhcare.client.presenter;

import org.mbhcare.client.view.MainView;
import org.mbhcare.client.view.about.AboutViewImpl;
import org.mbhcare.client.view.diagnosis.DiagnosisViewImpl;
import org.mbhcare.client.view.patients.PatientsViewImpl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasWidgets;

/**
* @author MCOSTA
*
*/
public class MainPresenter implements Presenter, MainView.Presenter {
 
  public static final String VIEW_MAIN = "main";
  public static final String VIEW_ABOUT = VIEW_MAIN + "/about";
  public static final String VIEW_PATIENTS = VIEW_MAIN + "/patients";
  public static final String VIEW_DIAGNOSIS = VIEW_MAIN + "/diagnosis";
 
  private final MainView view;
 
    private PatientsViewImpl patientsView = null;
  private AboutViewImpl aboutView = null;
  private DiagnosisViewImpl diagnosisView = null;
 
  public MainPresenter(MainView view) {
      this.view = view;
  }

  @Override
  public void go(HasWidgets container) {
    container.clear();
    container.add(view.asWidget());
   
    processHistoryToken();
  }
 
  public void processHistoryToken() {
    String token = History.getToken();
   
    if(token != null) {     
      if (token.startsWith(VIEW_ABOUT)) {
        view.setActiveTab(null);
        GWT.runAsync(new RunAsyncCallback() {

          @Override
          public void onFailure(Throwable reason) {
            Window.alert("runAsync ERROR");
          }

          @Override
          public void onSuccess() {
            if(aboutView == null)
              aboutView = new AboutViewImpl();
           
            new AboutPresenter(aboutView).go(view.getContentPanel());
          }
         
        });
     
      } else if(token.startsWith(VIEW_PATIENTS)) {
        view.setActiveTab(0);
        GWT.runAsync(new RunAsyncCallback() {

          @Override
          public void onFailure(Throwable reason) {
            Window.alert("runAsync ERROR");
          }

          @Override
          public void onSuccess() {
            if(patientsView == null)
              patientsView = new PatientsViewImpl();
           
            new PatientsPresenter(patientsView).go(view.getContentPanel());
          }
         
        });
      } else if(token.startsWith(VIEW_DIAGNOSIS)) {
        view.setActiveTab(1);
        GWT.runAsync(new RunAsyncCallback() {

          @Override
          public void onFailure(Throwable reason) {
            Window.alert("runAsync ERROR");
          }

          @Override
          public void onSuccess() {
            if(diagnosisView == null)
              diagnosisView = new DiagnosisViewImpl();
           
            new DiagnosisPresenter(diagnosisView).go(view.getContentPanel());
          }         
        });     
     
    }
  }
 
}
TOP

Related Classes of org.mbhcare.client.presenter.MainPresenter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.