示例#1
0
  /** Shows all data */
  protected void showData() {

    try {
      unbindPresenters();

      // workouts
      if (data.getWorkouts() != null) {
        for (WorkoutModel w : data.getWorkouts()) {
          // if only link
          if (showOnlyLinks) {
            final WorkoutLinkPresenter wp =
                new WorkoutLinkPresenter(
                    rpcService,
                    eventBus,
                    (WorkoutLinkDisplay) GWT.create(WorkoutLinkView.class),
                    w,
                    false);
            addNewPresenter(wp);
          } else {
            final WorkoutPresenter wp =
                new WorkoutPresenter(
                    rpcService, eventBus, (WorkoutDisplay) GWT.create(WorkoutView.class), w);
            addNewPresenter(wp);
          }
        }
      }

      // nutrition
      if (data.getNutrition() != null) {
        // if only link
        if (showOnlyLinks) {
          // set date
          data.getNutrition().setDate(CommonUtils.getDateGmt(data.getDate()));
          final NutritionDayLinkPresenter wp =
              new NutritionDayLinkPresenter(
                  rpcService,
                  eventBus,
                  (NutritionDayLinkDisplay) GWT.create(NutritionDayLinkView.class),
                  data.getNutrition());
          addNewPresenter(wp);
        } else {
          final NutritionDayPresenter wp =
              new NutritionDayPresenter(
                  rpcService,
                  eventBus,
                  (NutritionDayDisplay) GWT.create(NutritionDayView.class),
                  data.getUser().getUid(),
                  CommonUtils.getDateGmt(data.getDate()),
                  data.getNutrition());
          addNewPresenter(wp);
        }
      }

      if (data.getMeasurements() != null) {
        // measurement
        for (MeasurementValueModel m : data.getMeasurements()) {
          final MeasurementValueLinkPresenter wp =
              new MeasurementValueLinkPresenter(
                  rpcService,
                  eventBus,
                  (MeasurementValueLinkDisplay) GWT.create(MeasurementValueLinkView.class),
                  m);
          addNewPresenter(wp);
        }
      }

      // cardio
      if (data.getCardios() != null) {
        for (CardioValueModel m : data.getCardios()) {
          final CardioValueLinkPresenter wp =
              new CardioValueLinkPresenter(
                  rpcService,
                  eventBus,
                  (CardioValueLinkDisplay) GWT.create(CardioValueLinkView.class),
                  m);
          addNewPresenter(wp);
        }
      }

      // run
      if (data.getRuns() != null) {
        for (RunValueModel m : data.getRuns()) {
          final RunValueLinkPresenter wp =
              new RunValueLinkPresenter(
                  rpcService,
                  eventBus,
                  (RunValueLinkDisplay) GWT.create(RunValueLinkView.class),
                  m);
          addNewPresenter(wp);
        }
      }

    } catch (Exception e) {
      Motiver.showException(e);
    }
  }
示例#2
0
  @Override
  public void onBind() {
    display.setDate(data.getDate());
    display.showOnlyLinks(showOnlyLinks);

    // EVENT: workout value removed
    addEventHandler(
        WorkoutRemovedEvent.TYPE,
        new WorkoutRemovedEventHandler() {
          @Override
          public void onWorkoutRemoved(WorkoutRemovedEvent event) {
            // if this day
            boolean found = false;
            for (WorkoutModel m : data.getWorkouts()) {
              if (event.getWorkout().equals(m)) {
                data.getWorkouts().remove(m);
                found = true;
                break;
              }
            }
            // check if day empty
            if (found) {
              stopIfEmpty();
            }
          }
        });
    // EVENT: cardio value removed
    addEventHandler(
        CardioValueRemovedEvent.TYPE,
        new CardioValueRemovedEventHandler() {
          @Override
          public void onCardioValueRemoved(CardioValueRemovedEvent event) {
            // if this day
            boolean found = false;
            for (CardioValueModel m : data.getCardios()) {
              if (event.getCardioValue().equals(m)) {
                data.getCardios().remove(m);
                found = true;
                break;
              }
            }
            // check if day empty
            if (found) {
              stopIfEmpty();
            }
          }
        });
    // EVENT: run value removed
    addEventHandler(
        RunValueRemovedEvent.TYPE,
        new RunValueRemovedEventHandler() {
          @Override
          public void onRunValueRemoved(RunValueRemovedEvent event) {
            // if this day
            boolean found = false;
            for (RunValueModel m : data.getRuns()) {
              if (event.getRunValue().equals(m)) {
                data.getRuns().remove(m);
                found = true;
                break;
              }
            }
            // check if day empty
            if (found) {
              stopIfEmpty();
            }
          }
        });
    // EVENT: measurement value removed
    addEventHandler(
        MeasurementValueRemovedEvent.TYPE,
        new MeasurementValueRemovedEventHandler() {
          @Override
          public void onMeasurementValueRemoved(MeasurementValueRemovedEvent event) {
            // if this day
            boolean found = false;
            for (MeasurementValueModel m : data.getMeasurements()) {
              if (event.getMeasurementValue().equals(m)) {
                data.getMeasurements().remove(m);
                found = true;
                break;
              }
            }
            // check if day empty
            if (found) {
              stopIfEmpty();
            }
          }
        });
  }