/**
   * NOTE: this method is extremely similar to updateSchedule, when modifying this method, consider
   * modifying updateSchedule in a similar way.
   */
  @SuppressWarnings("fallthrough")
  private void createSchedule() {
    // TODO, List<Schedule> is probably not what we will get back
    AsyncCallback<Object> responseCallback =
        new AsyncCallback<Object>() {
          public void onSuccess(Object o) {
            scheduleCreatorDialog.hide();
            loadJobsTable();
          }

          public void onFailure(Throwable caught) {
            MessageDialogBox messageDialog =
                new MessageDialogBox(
                    ExceptionParser.getErrorHeader(caught.getMessage()),
                    ExceptionParser.getErrorMessage(caught.getMessage(), caught.getMessage()),
                    false,
                    false,
                    true);
            messageDialog.center();
          }
        }; // end responseCallback

    // TODO sbarkdull scheduleCreatorDialog -> scheduleEditorDialog
    DualModeScheduleEditor scheduleEditor = scheduleCreatorDialog.getScheduleEditor();

    String cronStr = scheduleEditor.getCronString();
    Date startDate = scheduleEditor.getStartDate();
    Date endDate = scheduleEditor.getEndDate();

    if (null == cronStr) { // must be a repeating schedule
      String startTime =
          scheduleEditor
              .getStartTime(); // format of string should be: HH:MM:SS AM/PM, e.g. 7:12:28 PM
      startDate = TimeUtil.getDateTime(startTime, startDate);
      endDate = (null != endDate) ? TimeUtil.getDateTime(startTime, endDate) : null;
    }

    ScheduleEditor.ScheduleType rt = scheduleEditor.getScheduleType();

    // TODO sbarkdull, if we want to support creation of scheduler schedules, we need to supply
    // a UI mechanism like a checkbox to allow user to identify scheduler vs subscription,
    // and then test the value of the check box instead of the following "true".
    ISchedulerServiceAsync schedSvc =
        scheduleEditor.isSubscriptionSchedule()
            ? PacServiceFactory.getSubscriptionService()
            : PacServiceFactory.getSchedulerService();

    switch (rt) {
      case RUN_ONCE:
        schedSvc.createRepeatSchedule(
            scheduleEditor.getName().trim(),
            scheduleEditor.getGroupName().trim(),
            scheduleEditor.getDescription().trim(),
            startDate,
            endDate,
            "0" /*repeat count*/, //$NON-NLS-1$
            "0" /*repeat time*/, //$NON-NLS-1$
            scheduleCreatorDialog
                .getSolutionRepositoryActionSequenceEditor()
                .getActionsAsString()
                .trim(),
            responseCallback);
        break;
      case SECONDS: // fall through
      case MINUTES: // fall through
      case HOURS: // fall through
      case DAILY: // fall through
      case WEEKLY: // fall through
      case MONTHLY: // fall through
      case YEARLY:
        if (null == cronStr) {
          String repeatInterval =
              Long.toString(TimeUtil.secsToMillisecs(scheduleEditor.getRepeatInSecs()));
          schedSvc.createRepeatSchedule(
              scheduleEditor.getName().trim(),
              scheduleEditor.getGroupName().trim(),
              scheduleEditor.getDescription().trim(),
              startDate,
              endDate,
              null /*repeat count*/,
              repeatInterval.trim(),
              scheduleCreatorDialog
                  .getSolutionRepositoryActionSequenceEditor()
                  .getActionsAsString()
                  .trim(),
              responseCallback);
          break;
        } else {
          // fall through to case CRON
        }
      case CRON:
        schedSvc.createCronSchedule(
            scheduleEditor.getName().trim(),
            scheduleEditor.getGroupName().trim(),
            scheduleEditor.getDescription().trim(),
            startDate,
            endDate,
            cronStr.trim(),
            scheduleCreatorDialog
                .getSolutionRepositoryActionSequenceEditor()
                .getActionsAsString()
                .trim(),
            responseCallback);
        break;
      default:
        throw new RuntimeException(
            Messages.getString("invalidRunType", rt.toString())); // $NON-NLS-1$
    }
  }
  private void updateSchedule() {

    AsyncCallback<Object> updateScheduleResponseCallback =
        new AsyncCallback<Object>() {
          public void onSuccess(Object o) {
            scheduleCreatorDialog.hide();
            loadJobsTable();
          }

          public void onFailure(Throwable caught) {
            MessageDialogBox messageDialog =
                new MessageDialogBox(
                    ExceptionParser.getErrorHeader(caught.getMessage()),
                    ExceptionParser.getErrorMessage(caught.getMessage(), caught.getMessage()),
                    false,
                    false,
                    true);
            messageDialog.center();
          }
        };
    final List<Schedule> scheduleList = schedulesListCtrl.getSelectedSchedules();
    Schedule oldSchedule = scheduleList.get(0);
    DualModeScheduleEditor scheduleEditor = scheduleCreatorDialog.getScheduleEditor();

    ISchedulerServiceAsync schedSvc =
        scheduleEditor.isSubscriptionSchedule()
            ? PacServiceFactory.getSubscriptionService()
            : PacServiceFactory.getSchedulerService();

    String cronStr = scheduleEditor.getCronString();
    Date startDate = scheduleEditor.getStartDate();
    Date endDate = scheduleEditor.getEndDate();

    if (null == cronStr) { // must be a repeating schedule
      String startTime =
          scheduleEditor
              .getStartTime(); // format of string should be: HH:MM:SS AM/PM, e.g. 7:12:28 PM
      startDate = TimeUtil.getDateTime(startTime, startDate);
      endDate = (null != endDate) ? TimeUtil.getDateTime(startTime, endDate) : null;
    }

    ScheduleEditor.ScheduleType rt = scheduleEditor.getScheduleType();
    switch (rt) {
      case RUN_ONCE:
        schedSvc.updateRepeatSchedule(
            oldSchedule.getJobName(),
            oldSchedule.getJobGroup(),
            oldSchedule.getSchedId(),
            scheduleEditor.getName().trim(),
            scheduleEditor.getGroupName().trim(),
            scheduleEditor.getDescription().trim(),
            startDate,
            endDate,
            "0" /*repeat count*/, //$NON-NLS-1$
            "0" /*repeat time*/, //$NON-NLS-1$
            scheduleCreatorDialog
                .getSolutionRepositoryActionSequenceEditor()
                .getActionsAsString()
                .trim(),
            updateScheduleResponseCallback);
        break;
      case SECONDS: // fall through
      case MINUTES: // fall through
      case HOURS: // fall through
      case DAILY: // fall through
      case WEEKLY: // fall through
      case MONTHLY: // fall through
      case YEARLY:
        if (null == cronStr) {
          String repeatInterval =
              Long.toString(TimeUtil.secsToMillisecs(scheduleEditor.getRepeatInSecs()));
          schedSvc.updateRepeatSchedule(
              oldSchedule.getJobName(),
              oldSchedule.getJobGroup(),
              oldSchedule.getSchedId(),
              scheduleEditor.getName().trim(),
              scheduleEditor.getGroupName().trim(),
              scheduleEditor.getDescription().trim(),
              startDate,
              endDate,
              null /*repeat count*/,
              repeatInterval.trim(),
              scheduleCreatorDialog
                  .getSolutionRepositoryActionSequenceEditor()
                  .getActionsAsString()
                  .trim(),
              updateScheduleResponseCallback);
          break;
        } else {
          // fall through to case CRON
        }
      case CRON:
        schedSvc.updateCronSchedule(
            oldSchedule.getJobName(),
            oldSchedule.getJobGroup(),
            oldSchedule.getSchedId(),
            scheduleEditor.getName().trim(),
            scheduleEditor.getGroupName().trim(),
            scheduleEditor.getDescription().trim(),
            startDate,
            endDate,
            cronStr.trim(),
            scheduleCreatorDialog
                .getSolutionRepositoryActionSequenceEditor()
                .getActionsAsString()
                .trim(),
            updateScheduleResponseCallback);
        break;
      default:
        throw new RuntimeException(
            Messages.getString("invalidRunType", rt.toString())); // $NON-NLS-1$
    }
  }