コード例 #1
0
  /**
   * This method populates the form from a schedule time value object.
   *
   * @param sv The ScheduleValue object to populate the form from.
   */
  public void populateFromSchedule(ScheduleValue sv, Locale userLocale)
      throws IllegalArgumentException {

    this.populateStartDate(sv.getStart(), userLocale);
    Date end = sv.getEnd();
    int ival = sv.getInterval();
    if (null != end && ival > 0) {
      this.setWantEndDate(true); // performs validation on end date
      this.populateEndDate(sv.getEnd(), userLocale);
      endTime = END_ON_DATE;
    } else {
      endTime = END_NEVER;
    }

    // won't ever be editing an "immediate"
    this.startTime = START_ON_DATE;

    if (sv instanceof ScheduleSingleValue) {
      ScheduleSingleValue ssv = (ScheduleSingleValue) sv;
      recurInterval = RECUR_NEVER;
      return;
    } else if (sv instanceof ScheduleDailyValue) {
      ScheduleDailyValue sdv = (ScheduleDailyValue) sv;
      this.recurInterval = RECUR_DAILY;
      this.numDays = new Integer(sdv.getInterval()).toString();
      if (sdv.getEveryWeekDay()) {
        recurrenceFrequencyDaily = EVERY_WEEKDAY;
      } else {
        recurrenceFrequencyDaily = EVERY_DAY;
      }
      return;
    } else if (sv instanceof ScheduleWeeklyValue) {
      ScheduleWeeklyValue swv = (ScheduleWeeklyValue) sv;
      this.recurInterval = RECUR_WEEKLY;
      this.numWeeks = new Integer(swv.getInterval()).toString();
      ArrayList tmpDays = new ArrayList();
      for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
        if (swv.isDaySet(i)) {
          tmpDays.add(new Integer(i));
        }
      }
      recurrenceDay = new Integer[tmpDays.size()];
      recurrenceDay = (Integer[]) tmpDays.toArray(recurrenceDay);
      return;
    } else if (sv instanceof ScheduleMonthlyValue) {
      ScheduleMonthlyValue smv = (ScheduleMonthlyValue) sv;
      this.recurInterval = RECUR_MONTHLY;
      this.numMonths = new Integer(smv.getInterval()).toString();

      if (smv.isOffset()) {
        // "3rd Sunday"
        this.recurrenceWeek = new Integer(smv.getWeekOfMonth());
        this.monthlyRecurrenceDay = new Integer(smv.getDayOfWeek());
        this.recurrenceFrequencyMonthly = ON_DAY;
      } else {
        // "31st of October"
        this.recurrenceFrequencyMonthly = ON_EACH;
        this.eachDay = new Integer(smv.getDay());
      }
      return;
    }
  }