public ScheduleRecurrenceDialog(
     PromptDialogBox parentDialog,
     JsJob jsJob,
     IDialogCallback callback,
     boolean hasParams,
     boolean isEmailConfValid,
     final ScheduleDialogType type) {
   super(
       type,
       type != ScheduleDialogType.BLOCKOUT
           ? Messages.getString("editSchedule")
           : Messages.getString("editBlockoutSchedule"),
       null,
       false,
       true); //$NON-NLS-1$ //$NON-NLS-2$
   isBlockoutDialog = (type == ScheduleDialogType.BLOCKOUT);
   setCallback(callback);
   this.editJob = jsJob;
   this.parentDialog = parentDialog;
   constructDialog(
       jsJob.getFullResourceName(),
       jsJob.getOutputPath(),
       jsJob.getJobName(),
       hasParams,
       isEmailConfValid,
       jsJob);
 }
  private void handleWizardPanels(final JSONObject schedule, final JsJobTrigger trigger) {
    if (hasParams) {
      showScheduleParamsDialog(trigger, schedule);
    } else if (isEmailConfValid) {
      showScheduleEmailDialog(schedule);
    } else {
      // submit
      JSONObject scheduleRequest = (JSONObject) JSONParser.parseStrict(schedule.toString());

      if (editJob != null) {
        JSONArray scheduleParams = new JSONArray();

        for (int i = 0; i < editJob.getJobParams().length(); i++) {
          JsJobParam param = editJob.getJobParams().get(i);
          JsArrayString paramValue = (JsArrayString) JavaScriptObject.createArray().cast();
          paramValue.push(param.getValue());
          JsSchedulingParameter p = (JsSchedulingParameter) JavaScriptObject.createObject().cast();
          p.setName(param.getName());
          p.setType("string"); // $NON-NLS-1$
          p.setStringValue(paramValue);
          scheduleParams.set(i, new JSONObject(p));
        }

        scheduleRequest.put("jobParameters", scheduleParams); // $NON-NLS-1$

        String actionClass =
            editJob.getJobParamValue("ActionAdapterQuartzJob-ActionClass"); // $NON-NLS-1$
        if (!StringUtils.isEmpty(actionClass)) {
          scheduleRequest.put("actionClass", new JSONString(actionClass)); // $NON-NLS-1$
        }
      }

      RequestBuilder scheduleFileRequestBuilder =
          new RequestBuilder(RequestBuilder.POST, contextURL + "api/scheduler/job"); // $NON-NLS-1$
      scheduleFileRequestBuilder.setHeader(
          "Content-Type", "application/json"); // $NON-NLS-1$//$NON-NLS-2$
      scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

      try {
        scheduleFileRequestBuilder.sendRequest(
            scheduleRequest.toString(),
            new RequestCallback() {
              public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("error"),
                        exception.toString(),
                        false,
                        false,
                        true); //$NON-NLS-1$
                dialogBox.center();
                setDone(false);
              }

              public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                  setDone(true);
                  ScheduleRecurrenceDialog.this.hide();
                  if (callback != null) {
                    callback.okPressed();
                  }
                  if (showSuccessDialog) {
                    if (!PerspectiveManager.getInstance()
                        .getActivePerspective()
                        .getId()
                        .equals(PerspectiveManager.SCHEDULES_PERSPECTIVE)) {
                      ScheduleCreateStatusDialog successDialog = new ScheduleCreateStatusDialog();
                      successDialog.center();
                    } else {
                      MessageDialogBox dialogBox =
                          new MessageDialogBox(
                              Messages.getString("scheduleUpdatedTitle"),
                              Messages.getString(
                                  "scheduleUpdatedMessage"), //$NON-NLS-1$ //$NON-NLS-2$
                              false,
                              false,
                              true);
                      dialogBox.center();
                    }
                  }
                } else {
                  MessageDialogBox dialogBox =
                      new MessageDialogBox(
                          Messages.getString("error"), // $NON-NLS-1$
                          response.getText(),
                          false,
                          false,
                          true);
                  dialogBox.center();
                  setDone(false);
                }
              }
            });
      } catch (RequestException e) {
        MessageDialogBox dialogBox =
            new MessageDialogBox(
                Messages.getString("error"),
                e.toString(), // $NON-NLS-1$
                false,
                false,
                true);
        dialogBox.center();
        setDone(false);
      }

      setDone(true);
    }
  }
  private void setupExisting(JsJob jsJob) {
    if (jsJob != null && !jsJob.equals("")) { // $NON-NLS-1$
      JsJobTrigger jsJobTrigger = jsJob.getJobTrigger();
      ScheduleType scheduleType = ScheduleType.valueOf(jsJobTrigger.getScheduleType());
      // scheduleEditor.setScheduleName(jsJob.getJobName());
      scheduleEditor.setScheduleType(scheduleType);
      if (scheduleType == ScheduleType.CRON
          || jsJobTrigger.getType().equals("cronJobTrigger")) { // $NON-NLS-1$
        scheduleEditor.getCronEditor().setCronString(jsJobTrigger.getCronString());
      } else if (jsJobTrigger.getType().equals("simpleJobTrigger")) { // $NON-NLS-1$
        if (jsJobTrigger.getRepeatCount() == -1) {
          // Recurring simple Trigger
          int interval = jsJobTrigger.getRepeatInterval();

          scheduleEditor.setRepeatInSecs(interval);
          if (scheduleType == ScheduleType.DAILY) {
            DailyRecurrenceEditor dailyRecurrenceEditor =
                scheduleEditor.getRecurrenceEditor().getDailyEditor();
            dailyRecurrenceEditor.setEveryNDays();
          }
        }
      } else if (jsJobTrigger.getType().equals("complexJobTrigger")) { // $NON-NLS-1$
        if (scheduleType == ScheduleType.DAILY) {
          // Daily
          DailyRecurrenceEditor dailyRecurrenceEditor =
              scheduleEditor.getRecurrenceEditor().getDailyEditor();
          if (jsJobTrigger.isWorkDaysInWeek()) {
            dailyRecurrenceEditor.setEveryWeekday();
          } else {
            dailyRecurrenceEditor.setEveryNDays();
          }
        } else if (scheduleType == ScheduleType.WEEKLY) {
          int[] daysOfWeek = jsJobTrigger.getDayOfWeekRecurrences();
          WeeklyRecurrenceEditor weeklyRecurrenceEditor =
              scheduleEditor.getRecurrenceEditor().getWeeklyEditor();
          String strDays = ""; // $NON-NLS-1$
          for (int i = 0; i < daysOfWeek.length; i++) {
            strDays += Integer.toString(daysOfWeek[i]) + ","; // $NON-NLS-1$
          }
          weeklyRecurrenceEditor.setCheckedDaysAsString(strDays, 1);
        } else if (scheduleType == ScheduleType.MONTHLY) {
          MonthlyRecurrenceEditor monthlyRecurrenceEditor =
              scheduleEditor.getRecurrenceEditor().getMonthlyEditor();
          if (jsJobTrigger.isQualifiedDayOfWeekRecurrence()) {
            // Run Every on ___day of Nth week every month
            monthlyRecurrenceEditor.setDayOfWeek(
                TimeUtil.DayOfWeek.valueOf(jsJobTrigger.getQualifiedDayOfWeek()));
            monthlyRecurrenceEditor.setWeekOfMonth(
                TimeUtil.WeekOfMonth.valueOf(jsJobTrigger.getDayOfWeekQualifier()));
            monthlyRecurrenceEditor.setNthDayNameOfMonth();
          } else {
            // Run on Nth day of the month
            monthlyRecurrenceEditor.setDayOfMonth(
                Integer.toString(jsJobTrigger.getDayOfMonthRecurrences()[0]));
          }
        } else if (scheduleType == ScheduleType.YEARLY) {
          YearlyRecurrenceEditor yearlyRecurrenceEditor =
              scheduleEditor.getRecurrenceEditor().getYearlyEditor();
          if (jsJobTrigger.isQualifiedDayOfWeekRecurrence()) {
            // Run Every on ___day of Nth week of the month M yearly
            yearlyRecurrenceEditor.setDayOfWeek(
                TimeUtil.DayOfWeek.valueOf(jsJobTrigger.getQualifiedDayOfWeek()));
            yearlyRecurrenceEditor.setWeekOfMonth(
                TimeUtil.WeekOfMonth.valueOf(jsJobTrigger.getDayOfWeekQualifier()));
            yearlyRecurrenceEditor.setMonthOfYear1(
                TimeUtil.MonthOfYear.get(jsJobTrigger.getMonthlyRecurrences()[0] - 1));
            yearlyRecurrenceEditor.setNthDayNameOfMonthName();
          } else {
            // Run on Nth day of the month M yearly
            yearlyRecurrenceEditor.setDayOfMonth(
                Integer.toString(jsJobTrigger.getDayOfMonthRecurrences()[0]));
            yearlyRecurrenceEditor.setMonthOfYear0(
                TimeUtil.MonthOfYear.get(jsJobTrigger.getMonthlyRecurrences()[0] - 1));
            yearlyRecurrenceEditor.setEveryMonthOnNthDay();
          }
        }
      }
      scheduleEditor.setStartDate(jsJobTrigger.getStartTime());
      scheduleEditor.setStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.HOUR_MINUTE_SECOND)
              .format(jsJobTrigger.getStartTime()));
      if (jsJobTrigger.getEndTime() == null) {
        scheduleEditor.setNoEndDate();
      } else {
        scheduleEditor.setEndDate(jsJobTrigger.getEndTime());
        scheduleEditor.setEndBy();
      }

      if (isBlockoutDialog) {
        this.scheduleEditor.setDurationFields(jsJobTrigger.getBlockDuration());
      }
    }
  }