예제 #1
0
  // deletes the selected task when the button is pressed
  @FXML
  private void deleteTask(ActionEvent e) {

    ToDoList selectedList = todoListView.getSelectionModel().getSelectedItem();
    Task toDelete = incompleteTaskListView.getSelectionModel().getSelectedItem();

    if (!selectedList.getIncompleteTaskList().remove(toDelete)) {
      System.err.println("Task not deleted");
    }
  }
예제 #2
0
  // function adds a listner to todoListView's selected item so that the user selected todo list can
  // be tracked and
  // completeTaskListView and incompleteTaskListView can be updated with selected todo list's
  // corresponding tasks
  private void setSelectedToDoListListener() {

    ObservableList<ToDoList> selectedToDoListTask =
        todoListView.getSelectionModel().getSelectedItems();

    // listener to monitor change in selected To Do list
    selectedToDoListTask.addListener(
        (Observable e) -> {
          ToDoList selectedToDo = todoListView.getSelectionModel().getSelectedItem();

          // if an item is selected
          if (selectedToDo != null) {

            if (toDoListTasksInfoVBox.disabledProperty().get()) {
              toDoListTasksInfoVBox.disableProperty().set(false);
            }

            // set incompleteTaskListView to selected item's incomplete task list
            incompleteTaskListView.itemsProperty().setValue(selectedToDo.getIncompleteTaskList());

            // set completeTaskListView to selected item's complete task list
            completeTaskListView.itemsProperty().setValue(selectedToDo.getCompleteTaskList());

            incompleteTaskListView.requestFocus();

            incompleteTaskListView.getSelectionModel().clearSelection();

          } else {
            // if no item is selected
            incompleteTaskListView.setItems(null);
            completeTaskListView.setItems(null);
            toDoListTasksInfoVBox.disableProperty().set(true);
            taskInfoVBox.disableProperty().set(true);
          }
        });
  }
예제 #3
0
  // saves the task information from taskInfoVBox form to the task passed in as argument
  private void saveTaskInfo(Task task) {

    // to track if the task's attributes have been changed
    boolean differentTaskName = false, differentDueDate = false, differentPriority = false;

    if (task == null) {
      return;
    }

    // if different title
    if (!task.getTaskTitle().equals(taskNameTextField.getText())) differentTaskName = true;

    // if different due date
    if (task.getTaskDueDate() == null) {
      if (taskDueDatePicker.getValue() != null) {
        differentDueDate = true;
      }
    } else {

      if (taskDueDatePicker.getValue() == null) {
        differentDueDate = true;
      }

      if (taskDueDatePicker.getValue() != null) {
        if (!(task.getTaskDueDate().isEqual(taskDueDatePicker.getValue()))) differentDueDate = true;
      }
    }

    int currentTaskPriority = task.getPriority();

    // if no priority selected for the task
    if (priority_toggle_group.getSelectedToggle() == null) {
      if (currentTaskPriority != 0) {
        differentPriority = true;
      }
    } else {
      // if different priority
      if (currentTaskPriority != (int) priority_toggle_group.getSelectedToggle().getUserData())
        differentPriority = true;
    }

    // if task attributes have been changed, replace current task with new task with updated task
    // attributes
    if (differentTaskName || differentDueDate || differentPriority) {

      Task replacementTask = new Task();

      replacementTask.setTaskTitle(taskNameTextField.getText());
      replacementTask.setTaskDueDate(taskDueDatePicker.getValue());
      if (priority_toggle_group.getSelectedToggle() == null) {
        replacementTask.setPriority(0);
      } else {
        replacementTask.setPriority((int) priority_toggle_group.getSelectedToggle().getUserData());
      }
      replacementTask.setSubTasks(task.getSubTasks());
      replacementTask.setNote(taskNoteTextArea.getText());

      int currentListIndex = -1, currentTaskIndex = -1; // to track current index
      int replacementListIndex = -1,
          replacementTaskIndex = -1; // to track index where replacement task will placed at

      found:
      {
        for (ToDoList currentList : toDoListModel) {

          currentListIndex++;
          currentTaskIndex = -1;

          for (Task currentTask : currentList.getIncompleteTaskList()) {
            currentTaskIndex++;

            // if task's unique ID matches current task, assign the current task's list index and
            // task index to the replacement index variables
            // and break out of the loop
            if (currentTask.getUniqueID() == task.getUniqueID()) {
              replacementListIndex = currentListIndex;
              replacementTaskIndex = currentTaskIndex;

              break found;
            }
          }
        }
      }

      // if found the task to replace with
      if (replacementListIndex != -1 && replacementTaskIndex != -1) {
        toDoListModel
            .get(replacementListIndex)
            .getIncompleteTaskList()
            .set(replacementTaskIndex, replacementTask);

        // if task to be replaced is the first task in the first to do list, select the replaced
        // task and update
        // incompleteTaskListView
        // code below help to get around a bug in selection model for list view
        if (replacementListIndex == 0 && replacementTaskIndex == 0) {
          todoListView.getSelectionModel().select(replacementListIndex);
          incompleteTaskListView.getSelectionModel().select(replacementListIndex);
        }
      }

    }
    // if task's priority, name and due date have not been changed, then only update the task's (one
    // that is passed in as argument) note
    else {

      task.setNote(taskNoteTextArea.getText());
    }
  }