Пример #1
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]));
      }
    }
  }
Пример #2
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);
  }
Пример #3
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);
  }
 /** Called when the user presses enter. Creates a UserInput object and passes it to MainLogic. */
 public void onEnter() {
   feedback.setMessage(null);
   String command = commandText.getText(); // string received from user.
   commandText.setText("");
   UserInput userInput = new UserInput(command, USER_INPUT_TODAY_TAB);
   MainLogic.run(userInput);
   mainApp.showTodayOverview();
 }
Пример #5
0
 /**
  * Constructs a Delete command
  *
  * @param userInput: userInput instance from MainLogic
  */
 public Delete(UserInput userInput) {
   this.userInput = userInput;
   storage = Storage.getInstance();
   feedback = Feedback.getInstance();
   taskList = new ArrayList<Task>();
 }
 /** Displays today's date and instant feedback labels. */
 private void displayLabels() {
   todayDate.setText(MainLogic.getCurrentDate().getDateString());
   feedback = Feedback.getInstance();
   instantFeedback.setText(feedback.getMessage());
 }