protected JSONObject getJsonComplexTrigger(
     ScheduleType scheduleType,
     MonthOfYear month,
     WeekOfMonth weekOfMonth,
     List<DayOfWeek> daysOfWeek,
     Date startDate,
     Date endDate) {
   JSONObject trigger = new JSONObject();
   trigger.put(
       "uiPassParam",
       new JSONString(scheduleEditorWizardPanel.getScheduleType().name())); // $NON-NLS-1$
   if (month != null) {
     JSONArray jsonArray = new JSONArray();
     jsonArray.set(0, new JSONString(Integer.toString(month.ordinal())));
     trigger.put("monthsOfYear", jsonArray); // $NON-NLS-1$
   }
   if (weekOfMonth != null) {
     JSONArray jsonArray = new JSONArray();
     jsonArray.set(0, new JSONString(Integer.toString(weekOfMonth.ordinal())));
     trigger.put("weeksOfMonth", jsonArray); // $NON-NLS-1$
   }
   if (daysOfWeek != null) {
     JSONArray jsonArray = new JSONArray();
     int index = 0;
     for (DayOfWeek dayOfWeek : daysOfWeek) {
       jsonArray.set(index++, new JSONString(Integer.toString(dayOfWeek.ordinal())));
     }
     trigger.put("daysOfWeek", jsonArray); // $NON-NLS-1$
   }
   addJsonStartEnd(trigger, startDate, endDate);
   return trigger;
 }
 /**
  * @param valueOfSunday int used to adjust the starting point of the weekday sequence. If this
  *     value is 0, Sun-Sat maps to 0-6, if this value is 1, Sun-Sat maps to 1-7, etc.
  * @return String comma separated list of numeric days of the week.
  */
 public String getCheckedDaysAsString(int valueOfSunday) {
   StringBuilder sb = new StringBuilder();
   for (DayOfWeek d : getCheckedDays()) {
     sb.append(Integer.toString(d.value() + valueOfSunday)).append(","); // $NON-NLS-1$
   }
   sb.deleteCharAt(sb.length() - 1);
   return sb.toString();
 }
 private ListBox createDayOfWeekListBox() {
   ListBox l = new ListBox();
   for (int ii = 0; ii < DayOfWeek.length(); ++ii) {
     DayOfWeek day = DayOfWeek.get(ii);
     l.addItem(Messages.getString(day.toString()));
   }
   return l;
 }
 private void setLastDayNameOfMonthNameRecurrence(String[] recurrenceTokens) {
   setTemporalState(TemporalValue.YEARLY);
   yearlyEditor.setNthDayNameOfMonthName();
   yearlyEditor.setMonthOfYear1(MonthOfYear.get(Integer.parseInt(recurrenceTokens[5]) - 1));
   yearlyEditor.setWeekOfMonth(WeekOfMonth.LAST);
   yearlyEditor.setDayOfWeek(DayOfWeek.get(Integer.parseInt(recurrenceTokens[4]) - 1));
 }
    public WeeklyRecurrenceEditor() {
      setStyleName("weeklyRecurrencePanel"); // $NON-NLS-1$

      Label l = new Label(Messages.getString("schedule.recurEveryWeek"));
      everyWeekOnLabel = new ErrorLabel(l);
      l.setStyleName("startLabel"); // $NON-NLS-1$
      add(everyWeekOnLabel);

      FlexTable gp = new FlexTable();
      gp.setCellPadding(0);
      gp.setCellSpacing(0);
      // add Sun - Wed
      final int ITEMS_IN_ROW = 4;
      for (int ii = 0; ii < ITEMS_IN_ROW; ++ii) {
        DayOfWeek day = DayOfWeek.get(ii);
        CheckBox cb = new CheckBox(Messages.getString(day.toString()));
        cb.setStylePrimaryName(DOW_CHECKBOX);
        gp.setWidget(0, ii, cb);
        dayToCheckBox.put(day, cb);
      }
      // Add Thur - Sat
      for (int ii = ITEMS_IN_ROW; ii < DayOfWeek.length(); ++ii) {
        DayOfWeek day = DayOfWeek.get(ii);
        CheckBox cb = new CheckBox(Messages.getString(day.toString()));
        cb.setStylePrimaryName(DOW_CHECKBOX);
        gp.setWidget(1, ii - 4, cb);
        dayToCheckBox.put(day, cb);
      }
      add(gp);
      configureOnChangeHandler();
    }
 /**
  * @param valueOfSunday int used to adjust the starting point of the weekday sequence. If this
  *     value is 0, Sun-Sat maps to 0-6, if this value is 1, Sun-Sat maps to 1-7, etc.
  * @return String comma separated list of numeric days of the week.
  */
 public void setCheckedDaysAsString(String strDays, int valueOfSunday) {
   String[] days = strDays.split(","); // $NON-NLS-1$
   for (String day : days) {
     int intDay = Integer.parseInt(day) - valueOfSunday;
     DayOfWeek dayOfWeek = DayOfWeek.get(intDay);
     CheckBox cb = dayToCheckBox.get(dayOfWeek);
     cb.setChecked(true);
   }
 }
  @SuppressWarnings("deprecation")
  public JsJobTrigger getJsJobTrigger() {
    JsJobTrigger jsJobTrigger = JsJobTrigger.instance();

    ScheduleType scheduleType = scheduleEditorWizardPanel.getScheduleType();
    Date startDate = scheduleEditorWizardPanel.getStartDate();
    String startTime = scheduleEditorWizardPanel.getStartTime();

    int startHour = getStartHour(startTime);
    int startMin = getStartMin(startTime);
    int startYear = startDate.getYear();
    int startMonth = startDate.getMonth();
    int startDay = startDate.getDate();
    Date startDateTime = new Date(startYear, startMonth, startDay, startHour, startMin);

    Date endDate = scheduleEditorWizardPanel.getEndDate();
    MonthOfYear monthOfYear = scheduleEditor.getRecurrenceEditor().getSelectedMonth();
    List<DayOfWeek> daysOfWeek = scheduleEditor.getRecurrenceEditor().getSelectedDaysOfWeek();
    Integer dayOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedDayOfMonth();
    WeekOfMonth weekOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedWeekOfMonth();

    if (isBlockoutDialog) {
      jsJobTrigger.setBlockDuration(calculateBlockoutDuration());
    } else {
      // blockDuration is only valid for blockouts
      jsJobTrigger.setBlockDuration(new Long(-1));
    }

    if (scheduleType == ScheduleType.RUN_ONCE) { // Run once types
      jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setRepeatInterval(0);
      jsJobTrigger.setRepeatCount(0);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
    } else if ((scheduleType == ScheduleType.SECONDS)
        || (scheduleType == ScheduleType.MINUTES)
        || (scheduleType == ScheduleType.HOURS)) {
      int repeatInterval = 0;
      try { // Simple Trigger Types
        repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval());
      } catch (Exception e) {
        // ignored
      }
      jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setRepeatInterval(repeatInterval);
      jsJobTrigger.setRepeatCount(-1);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
      if (endDate != null) {
        jsJobTrigger.setNativeEndTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
      }
    } else if (scheduleType == ScheduleType.DAILY) {
      if (scheduleEditor.getRecurrenceEditor().isEveryNDays()) {
        int repeatInterval = 0;
        try { // Simple Trigger Types
          repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval());
        } catch (Exception e) {
          // ignored
        }
        jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
        jsJobTrigger.setRepeatInterval(repeatInterval);
        jsJobTrigger.setRepeatCount(-1);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      } else {
        JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
        int i = 0;
        for (DayOfWeek dayOfWeek : daysOfWeek) {
          jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
        }
        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek);
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      }
    } else if (scheduleType == ScheduleType.CRON) { // Cron jobs
      jsJobTrigger.setType("cronJobTrigger"); // $NON-NLS-1$
    } else if ((scheduleType == ScheduleType.WEEKLY) && (daysOfWeek.size() > 0)) {
      JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
      int i = 0;
      for (DayOfWeek dayOfWeek : daysOfWeek) {
        jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
      }
      JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, startHour);
      JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, startMin);
      JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, 0);

      jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek);
      jsJobTrigger.setHourRecurrences(hours);
      jsJobTrigger.setMinuteRecurrences(minutes);
      jsJobTrigger.setSecondRecurrences(seconds);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
      if (endDate != null) {
        jsJobTrigger.setNativeEndTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
      }
    } else if ((scheduleType == ScheduleType.MONTHLY)
        || ((scheduleType == ScheduleType.YEARLY) && (monthOfYear != null))) {
      jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$

      if (dayOfMonth != null) {
        JsArrayInteger jsDaysOfMonth = (JsArrayInteger) JavaScriptObject.createArray();
        jsDaysOfMonth.set(0, dayOfMonth);

        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        if (monthOfYear != null) {
          JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray();
          jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1);
          jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear);
        }
        jsJobTrigger.setDayOfMonthRecurrences(jsDaysOfMonth);
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      } else if ((daysOfWeek.size() > 0) && (weekOfMonth != null)) {
        JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
        int i = 0;
        for (DayOfWeek dayOfWeek : daysOfWeek) {
          jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
        }

        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        if (monthOfYear != null) {
          JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray();
          jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1);
          jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear);
        }
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setQualifiedDayOfWeek(daysOfWeek.get(0).name());
        jsJobTrigger.setDayOfWeekQualifier(weekOfMonth.name());
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      }
    }
    return jsJobTrigger;
  }
 public void setDayOfWeek(DayOfWeek day) {
   dayOfWeekLb.setSelectedIndex(day.value());
 }
 public DayOfWeek getDayOfWeek() {
   return DayOfWeek.get(dayOfWeekLb.getSelectedIndex());
 }
 private void setLastDayNameOfMonthRecurrence(String[] recurrenceTokens) {
   setTemporalState(TemporalValue.MONTHLY);
   monthlyEditor.setNthDayNameOfMonth();
   monthlyEditor.setWeekOfMonth(WeekOfMonth.LAST);
   monthlyEditor.setDayOfWeek(DayOfWeek.get(Integer.parseInt(recurrenceTokens[4]) - 1));
 }