Ejemplo n.º 1
0
  /**
   * get historyToken parameters
   *
   * <p>like domaint.tld#anchor?[var=1&var3=2&var3=3]
   *
   * @param historyToken anchor tag
   * @return hashmap of the parameters
   */
  public static Map<String, String> getHistoryTokenParameters(String historyToken) {
    // skip if there is no question mark
    if (!historyToken.contains("?")) {
      return null;
    }
    // ? position
    int questionMarkIndex = historyToken.indexOf("?") + 1;

    // get the sub string of parameters var=1&var2=2&var3=3...
    String[] arStr = historyToken.substring(questionMarkIndex, historyToken.length()).split("&");
    Map<String, String> params = new HashMap<String, String>();

    for (int i = 0; i < arStr.length; i++) {
      String[] substr = arStr[i].split("=");
      params.put(substr[0], substr[1]);
    }

    return params;
  }
Ejemplo n.º 2
0
  public void switchSection(String token) {
    popup.hide();
    tokenHistory.add(token);
    Map<String, String> parameters = getHistoryTokenParameters(token);
    AppPlace place = getPlace(token);

    if (mainPresenter != null) {
      mainPresenter.clearNotifications();
    }

    if (ClientSessionUtil.checkSession()) {
      switch (place) {
        case HOME:
          HomePresenter homePresenter = new HomePresenter(new HomeView(), eventBus);
          homePresenter.bind();
          getLayout().clear();
          getLayout().add(homePresenter.getDisplay().asWidget());
          break;
        case REQUEST:
          RequestPresenter requestPresenter = new RequestPresenter(new RequestView(), eventBus);
          requestPresenter.bind();
          getLayout().clear();
          getLayout().add(requestPresenter.getDisplay().asWidget());
          break;
        case LOGOUT:
          ClientSessionUtil.destroySession();
          eventBus.fireEvent(new LoginRequiredEvent());
          break;
        case REQUESTSTATUS:
          try {
            Integer requestId = Integer.parseInt(parameters.get("requestId"));
            RequestStatusPresenter requestStatusPresenter =
                new RequestStatusPresenter(new RequestStatusView(), eventBus);
            requestStatusPresenter.bind();
            requestStatusPresenter.showRequest(requestId);
            getLayout().clear();
            getLayout().add(requestStatusPresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Id incorrecta: No se puede cargar la solicitud", NotificationEventType.ERROR);
          }
          break;
        case EDITREQUEST:
          try {
            Integer requestId = Integer.parseInt(parameters.get("requestId"));
            RequestEditPresenter editPresenter =
                new RequestEditPresenter(new RequestEditView(), eventBus);
            editPresenter.bind();
            editPresenter.showRequest(requestId);
            getLayout().clear();
            getLayout().add(editPresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Id incorrecta: No se puede cargar la solicitud", NotificationEventType.ERROR);
          }
          break;
        case RESPONSE:
          try {
            Integer requestId = Integer.parseInt(parameters.get("requestId"));
            RequestResponsePresenter requestResponsePresenter =
                new RequestResponsePresenter(new RequestResponseView(), eventBus);
            requestResponsePresenter.bind();
            requestResponsePresenter.showRequest(requestId);
            getLayout().clear();
            getLayout().add(requestResponsePresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Id incorrecta: No se puede cargar la solicitud", NotificationEventType.ERROR);
          }
          break;
        case LIST:
          try {
            String listType = parameters.get("type");
            RequestListPresenter requestListPresenter =
                new RequestListPresenter(new RequestListView(), eventBus);
            requestListPresenter.bind();
            requestListPresenter.loadRequests(0, 100, listType);
            getLayout().clear();
            getLayout().add(requestListPresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Tipo de lista incorrecto: No se puede cargar la lista",
                NotificationEventType.ERROR);
          }
          break;
        case STATISTICS:
          StatisticsPresenter statistics = new StatisticsPresenter(new StatisticsView(), eventBus);
          statistics.bind();
          getLayout().clear();
          getLayout().add(statistics.getDisplay().asWidget());
          break;
        case ABOUTPROJECT:
          AboutProjectPresenter aboutProjectPresenter =
              new AboutProjectPresenter(new AboutProjectView(), eventBus);
          aboutProjectPresenter.bind();
          getLayout().clear();
          getLayout().add(aboutProjectPresenter.getDisplay().asWidget());
          break;
        case ASOCIATES:
          AsociatesPresenter asociatesPresenter =
              new AsociatesPresenter(new AsociatesView(), eventBus);
          asociatesPresenter.bind();
          getLayout().clear();
          getLayout().add(asociatesPresenter.getDisplay().asWidget());
          break;
        case USERPROFILE:
          UserProfileEditPresenter userProfilePresenter =
              new UserProfileEditPresenter(new UserProfileEditView(), eventBus);
          userProfilePresenter.bind();
          getLayout().clear();
          getLayout().add(userProfilePresenter.getDisplay().asWidget());
          break;
        default:
          History.newItem(AppPlace.HOME.toString());
      }
    } else {
      switch (place) {
        case HOME:
          HomePresenter homePresenter = new HomePresenter(new HomeView(), eventBus);
          homePresenter.bind();
          getLayout().clear();
          getLayout().add(homePresenter.getDisplay().asWidget());
          break;
        case REQUEST:
        case LOGIN:
          LoginPresenter loginPresenter = new LoginPresenter(new LoginView(), eventBus);
          loginPresenter.bind();
          popup.setModal(true);
          popup.setGlassEnabled(true);
          popup.clear();
          popup.add(loginPresenter.getDisplay().asWidget());
          popup.center();
          break;
        case REGISTER:
          RegisterPresenter registerPresenter = new RegisterPresenter(new RegisterView(), eventBus);
          registerPresenter.bind();
          getLayout().clear();
          getLayout().add(registerPresenter.getDisplay().asWidget());
          break;
        case RESPONSE:
          try {
            Integer requestId = Integer.parseInt(parameters.get("requestId"));
            RequestResponsePresenter requestResponsePresenter =
                new RequestResponsePresenter(new RequestResponseView(), eventBus);
            requestResponsePresenter.bind();
            requestResponsePresenter.showRequest(requestId);
            getLayout().clear();
            getLayout().add(requestResponsePresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Id incorrecta: No se puede cargar la solicitud", NotificationEventType.ERROR);
          }
          break;
        case LIST:
          try {
            String listType = parameters.get("type");
            RequestListPresenter requtesListPresenter =
                new RequestListPresenter(new RequestListView(), eventBus);
            requtesListPresenter.bind();
            requtesListPresenter.loadRequests(0, 100, listType);
            getLayout().clear();
            getLayout().add(requtesListPresenter.getDisplay().asWidget());
          } catch (Exception e) {
            showNotification(
                "Tipo de lista incorrecto: No se puede cargar la lista",
                NotificationEventType.ERROR);
          }
          break;
        case STATISTICS:
          StatisticsPresenter statistics = new StatisticsPresenter(new StatisticsView(), eventBus);
          statistics.bind();
          getLayout().clear();
          getLayout().add(statistics.getDisplay().asWidget());
          break;
        case ABOUTPROJECT:
          AboutProjectPresenter aboutProjectPresenter =
              new AboutProjectPresenter(new AboutProjectView(), eventBus);
          aboutProjectPresenter.bind();
          getLayout().clear();
          getLayout().add(aboutProjectPresenter.getDisplay().asWidget());
          break;
        case ASOCIATES:
          AsociatesPresenter asociatesPresenter =
              new AsociatesPresenter(new AsociatesView(), eventBus);
          asociatesPresenter.bind();
          getLayout().clear();
          getLayout().add(asociatesPresenter.getDisplay().asWidget());
          break;
        case PASSWORDRECOVERY:
          PasswordRecoveryPresenter passwordRecoveryPresenter =
              new PasswordRecoveryPresenter(new PasswordRecoveryView(), eventBus);
          passwordRecoveryPresenter.bind();
          getLayout().clear();
          getLayout().add(passwordRecoveryPresenter.getDisplay().asWidget());
          break;
        default:
          History.newItem(AppPlace.HOME.toString());
      }
    }
  }