Ejemplo n.º 1
0
  // sets data for taskInfoVBox's nodes/components using task's data (passed as argument)
  private void setTaskInfoVBoxData(
      Task task, ChangeListener<? super LocalDate> dateChangeListener) {

    saveNewTaskNameButton.disableProperty().setValue(true);

    taskNameTextField.setText(task.getTaskTitle());

    if (task.getTaskDueDate() != null) {
      taskDueDatePicker.setValue(task.getTaskDueDate());
    }

    taskDueDatePicker.valueProperty().addListener(dateChangeListener);

    int taskPriority = task.getPriority();

    switch (taskPriority) {
      case 1:
        {
          lowPriorityToggle.setSelected(true);
          break;
        }
      case 2:
        {
          mediumPriorityToggle.setSelected(true);
          break;
        }
      case 3:
        {
          highPriorityToggle.setSelected(true);
          break;
        }
    }

    subTaskListView.setItems(task.getSubTasks());

    taskNoteTextArea.setText(task.getNote());
  }
Ejemplo n.º 2
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());
    }
  }
Ejemplo n.º 3
0
    private void updateViewModel() {

      setText(null);
      setGraphic(null);

      if (getItem() != null) {

        BorderPane mainBox = new BorderPane();
        mainBox.setPadding(new Insets(3.0, 5.0, 3.0, 3.0));

        VBox taskNameDisplay = new VBox();
        taskNameDisplay.setAlignment(Pos.CENTER_LEFT);
        Text taskNameText = new Text();
        taskNameDisplay.getChildren().addAll(taskNameText);

        HBox priorityDueDateDisplay = new HBox();
        priorityDueDateDisplay.setAlignment(Pos.CENTER_RIGHT);
        Text taskPriorityText = new Text();
        Text taskDueDateText = new Text();
        taskPriorityText.setScaleX(1.25);
        taskPriorityText.setScaleY(1.25);
        priorityDueDateDisplay.setSpacing(40);
        priorityDueDateDisplay.getChildren().addAll(taskDueDateText, taskPriorityText);

        mainBox.leftProperty().set(taskNameDisplay);
        mainBox.rightProperty().set(priorityDueDateDisplay);

        mainBox.setMargin(mainBox.getLeft(), new Insets(0, 20, 0, 0));

        Task currentTask = getItem();
        int currentTaskPriority = currentTask.getPriority();

        // setting task name to be displayed by the cell
        taskNameText.setText(currentTask.getTaskTitle());

        // setting task due date to be displayed by the cell
        if (currentTask.getTaskDueDate() != null) {

          LocalDate currentDueDate = currentTask.getTaskDueDate();
          taskDueDateText.setText(
              currentDueDate.getMonthValue()
                  + "/"
                  + currentDueDate.getDayOfMonth()
                  + "/"
                  + currentDueDate.getYear());
        }

        // setting task priority to be displayed by the cell
        switch (currentTaskPriority) {
          case 1:
            {
              taskPriorityText.setText("!");
              taskPriorityText.setFill(Color.web("#28ae33"));
              break;
            }
          case 2:
            {
              taskPriorityText.setText("!!");
              taskPriorityText.setFill(Color.web("#babf23"));
              break;
            }
          case 3:
            {
              taskPriorityText.setText("!!!");
              taskPriorityText.setFill(Color.web("#ee0606"));
              break;
            }
          default:
            {
            }
        }

        if (!currentTask.getComplete()) {
          taskNameText.setStrikethrough(false);
        } else {
          // if task is completed, strike out the task name

          mainBox.setOpacity(0.5);
          taskNameText.setStrikethrough(true);
        }

        setText(null);
        setGraphic(mainBox);
      }
    }