Package org.mbhcare.client

Source Code of org.mbhcare.client.AppController

package org.mbhcare.client;

import org.mbhcare.client.Home.HomeViewImpl;
import org.mbhcare.client.Login.LoginViewImpl;
import org.mbhcare.client.presenter.HomePresenter;
import org.mbhcare.client.presenter.LoginPresenter;
import org.mbhcare.client.presenter.MainPresenter;
import org.mbhcare.client.presenter.Presenter;
import org.mbhcare.client.view.MainViewImpl;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HasWidgets;

public class AppController implements Presenter, ValueChangeHandler<String> {
 
  private HasWidgets container;
  private MainPresenter mainPresenter;
  private LoginPresenter loginPresenter;
  private HomePresenter homePresenter;
 
  public AppController() {
    mainPresenter = new MainPresenter(new MainViewImpl());
    loginPresenter = new LoginPresenter(new LoginViewImpl());
    homePresenter = new HomePresenter(new HomeViewImpl());
   
    bind();
  }
 
  private void bind() {
    History.addValueChangeHandler(this);
  }
 
  public void go(final HasWidgets container) {
    this.container = container;
   
    if("".equals(History.getToken())) {
      History.newItem("main/patients");
    } else
      History.fireCurrentHistoryState();
    }
  }

  @Override
  public void onValueChange(ValueChangeEvent<String> event) {
    String token = event.getValue();
   
    if(token != null) {
      Presenter presenter = mainPresenter;
     
      if(token.startsWith("main")) {       
         presenter = mainPresenter;
      } else if(token.startsWith("home")) {
        presenter = homePresenter;
      } else if(token.startsWith(LoginPresenter.VIEW_LOGIN)) {
        presenter = loginPresenter;
      }
      presenter.go(container);
    }
  }
}
TOP

Related Classes of org.mbhcare.client.AppController

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.