Пример #1
0
  /** Redo the command */
  @Override
  public void redo() {
    logger.log(Level.INFO, "Command REDO DELETE");
    taskList = storage.getTaskList();
    ArrayList<Task> displayList = MainLogic.getDisplayList();
    for (int i = 0; i < userInput.getTasksToDelete().size(); i++) {
      Task task = userInput.getTasksToDelete().get(i);

      if (task.isRecurring() && userInput.getIsAll()) {
        Task t = task.getHead();
        for (int j = 0; j < t.getRecurList().size(); j++) {
          taskList.remove(t.getRecurList().get(j));
          displayList.remove(t.getRecurList().get(j));
        }
        userInput.setRecurList(t.getRecurList());
        t.setRecurList(new ArrayList<Task>());
      } else if (task.isRecurring()) {
        taskList.remove(task);
        displayList.remove(task);
        Task t = task.getHead();
        t.getRecurList().remove(task);
      } else {
        taskList.remove(task);
        displayList.remove(task);
      }
    }
    storage.saveFile();

    feedback.setMessage(MSG_SUCCESS_REDO);
  }
Пример #2
0
  /** Undo the command */
  @Override
  public void undo() {
    logger.log(Level.INFO, "Command UNDO DELETE");
    taskList = storage.getTaskList();
    ArrayList<Task> displayList = MainLogic.getDisplayList();
    for (int i = 0; i < userInput.getTasksToDelete().size(); i++) {
      Task task = userInput.getTasksToDelete().get(i);

      if (task.isRecurring() && userInput.getIsAll()) {
        Task t = task.getHead();
        for (int j = 0; j < userInput.getRecurList().size(); j++) {
          taskList.add(userInput.getRecurList().get(j));
          if (!displayList.equals(taskList)) {
            displayList.add(userInput.getRecurList().get(j));
          }
        }
        t.setRecurList(userInput.getRecurList());
      } else if (task.isRecurring()) {
        taskList.add(task);
        if (!displayList.equals(taskList)) {
          displayList.add(task);
        }
        Task t = task.getHead();
        t.getRecurList().add(task);
      } else {
        taskList.add(task);
        if (!displayList.equals(taskList)) {
          displayList.add(task);
        }
      }
    }
    storage.saveFile();

    feedback.setMessage(MSG_SUCCESS_UNDO);
  }
Пример #3
0
  /** Execute the command */
  @Override
  public void execute() {
    boolean success = false;

    logger.log(Level.INFO, "Command DELETE");
    taskList = storage.getTaskList();
    ArrayList<Task> displayList = MainLogic.getDisplayList();

    Task task = null;

    for (int i = 0; i < userInput.getTasksToDelete().size(); i++) {
      task = userInput.getTasksToDelete().get(i);
      if (task.isRecurring() && userInput.getIsAll()) {
        Task t = task.getHead();
        for (int j = 0; j < t.getRecurList().size(); j++) {
          taskList.remove(t.getRecurList().get(j));
          displayList.remove(t.getRecurList().get(j));
        }
        userInput.setRecurList(t.getRecurList());
        t.setRecurList(new ArrayList<Task>());
      } else if (task.isRecurring()) {
        taskList.remove(task);
        displayList.remove(task);
        Task t = task.getHead();
        t.getRecurList().remove(task);
      } else {
        taskList.remove(task);
        displayList.remove(task);
      }
    }

    success = true;

    if (!storage.saveFile()) {
      feedback.setMessage(MSG_FAIL_FILE_SAVE);
    } else if (success) {
      if (userInput.getDeleteNumber().size() > 1) {
        feedback.setMessage(MSG_SUCCESS_DELETE_MULTIPLE);
      } else {
        feedback.setMessage(
            String.format(
                MSG_SUCCESS_DELETE,
                getTaskTypeString(task),
                userInput.getDeleteNumber().get(0)[1]));
      }
    } else {
      if (userInput.getDeleteNumber().size() > 1) {
        feedback.setMessage(MSG_FAIL_INDEX_OOB_MULTIPLE);
        ;
      } else {
        feedback.setMessage(
            String.format(
                MSG_FAIL_INDEX_OOB,
                getTaskTypeString(task),
                userInput.getDeleteNumber().get(0)[1]));
      }
    }
  }