-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToDoController.java
822 lines (600 loc) · 29.3 KB
/
ToDoController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import model.SubTask;
import model.Task;
import model.ToDoList;
import java.time.LocalDate;
import static javafx.scene.input.KeyEvent.KEY_PRESSED;
/**
* Controller for ToDoView.fxml
*
* @author Karan Patel
*/
public class ToDoController {
//ObservableList to hold all lists in the program
private ObservableList<ToDoList> toDoListModel = FXCollections.observableArrayList();
public ObservableList<ToDoList> getData(){
return toDoListModel;
}
//if a task is selected, saves note for task selected by the user
//if task not selected by a user, function does nothing
public void saveCurrentSelectedTaskNote(){
Task selectedTask = incompleteTaskListView.getSelectionModel().getSelectedItem();
if(selectedTask != null){
selectedTask.setNote(taskNoteTextArea.getText());
}
}
public void initialize(){
//disabling toDoListTasksInfoVBox and taskInfoVBox after the view loads up for the first time
//user needs to have a ToDoList from todoListView selected for toDoListTasksInfoVBox to be enabled
toDoListTasksInfoVBox.disableProperty().setValue(true);
//user needs to have a task from the incompleteTaskListView selected for taskInfoVBox to be enabled
taskInfoVBox.disableProperty().setValue(true);
//setting editableProperty to false so that user cannot enter a date in custom format and needs to select date from datepicker
taskDueDatePicker.editableProperty().setValue(false);
todoListView.itemsProperty().set(toDoListModel);
setPriorityTogglesUserData();
setPlaceHolder();
setSelectionModel();
setCellFactory();
setAddToDoListButtonAndFieldHandler();
setAddTaskButtonAndFieldHandler();
setAddSubTaskButtonAndField();
setTaskCompleteOrIncomplete();
setSubTaskComplete();
setSelectedToDoListListener();
updateTaskView();
//whenever date is changed for a task, the modified task is saved
ChangeListener<? super LocalDate> dateChangeListener = ((observable1, oldValue1, newValue1) -> {
saveTaskInfo(incompleteTaskListView.getSelectionModel().getSelectedItem());
});
//listener will be triggered when a new task is selected from the incompleteTaskListView and load newly selected task's data into the view
incompleteTaskListView.getSelectionModel().selectedItemProperty().addListener(((observable, oldValue, newValue) -> {
if (oldValue == null) {
clearTaskInfoVBoxData(dateChangeListener);
setTaskInfoVBoxData(newValue, dateChangeListener);
taskInfoVBox.disableProperty().setValue(false);
} else if (newValue == null) {
taskInfoVBox.disableProperty().setValue(true);
saveTaskInfo(oldValue);
clearTaskInfoVBoxData(dateChangeListener);
} else {
saveTaskInfo(oldValue);
clearTaskInfoVBoxData(dateChangeListener);
setTaskInfoVBoxData(newValue, dateChangeListener);
}
}));
}
//setting user data for priority toggles
private void setPriorityTogglesUserData(){
lowPriorityToggle.setUserData(1);
mediumPriorityToggle.setUserData(2);
highPriorityToggle.setUserData(3);
}
//setting place holder for todoListView, subTaskListView, completeTaskListView and incompleteTaskListView
private void setPlaceHolder() {
todoListView.setPlaceholder(new Label("Add a new To Do list from below ..."));
subTaskListView.setPlaceholder(new Label("No subtask to display"));
completeTaskListView.setPlaceholder(new Label("No complete task to display"));
incompleteTaskListView.setPlaceholder(new Label("No incomplete task. Enjoy your day !"));
}
//setting selection model for todoListView, completeTaskListView, incompleteTaskListView and subTaskListView
private void setSelectionModel(){
todoListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
completeTaskListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
incompleteTaskListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
subTaskListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
}
//setting cell factory for todoListView, incompleteTaskListView and completeTaskListView
private void setCellFactory(){
todoListView.setCellFactory(e -> new CustomToDoListViewCell());
incompleteTaskListView.setCellFactory(e -> new CustomTaskListViewCell());
completeTaskListView.setCellFactory(e -> new CustomTaskListViewCell());
}
//Cell factory for todoListView
//When in edit mode, an option for editing represented ToDO List's name and deleting it is displayed by the cell
private class CustomToDoListViewCell extends ListCell<ToDoList>{
@Override
protected void updateItem(ToDoList item, boolean empty) {
super.updateItem(item, empty);
updateViewModel();
}
private void updateViewModel(){
setText(null);
setGraphic(null);
if(isEditing()){
VBox mainBox = new VBox();
HBox changeToDoListNamebox = new HBox();
TextField listNameField = new TextField();
listNameField.setPromptText("Enter new list name ...");
Button setNameChange = new Button("Set");
changeToDoListNamebox.getChildren().addAll(listNameField, setNameChange);
Button deleteList = new Button("Delete List");
Button cancelEdit = new Button("Cancel");
if(getItem() != null){
listNameField.setText(getItem().getListName());
}
setNameChange.setOnAction(e -> {
if(!getItem().getListName().equals(setNameChange.getText())){
commitEdit(new ToDoList(listNameField.getText(), getItem().getCompleteTaskList(), getItem().getIncompleteTaskList()));
todoListView.getSelectionModel().select(getIndex());
}
});
deleteList.setOnAction(e -> {
int item_to_delete_index = getIndex();
int size_of_data_model = toDoListModel.size();
if(size_of_data_model > 1){
if(item_to_delete_index == 0){
todoListView.getSelectionModel().select(1);
}else{
todoListView.getSelectionModel().select(--item_to_delete_index);
}
}
//remove deleted list from toDoListModel
toDoListModel.remove(getIndex());
});
cancelEdit.setOnAction(e -> {
cancelEdit();
});
mainBox.getChildren().addAll(changeToDoListNamebox, deleteList, cancelEdit);
setGraphic(mainBox);
}else{
if(getItem() != null){
setText(getItem().getListName());
}
}
}
@Override
public void startEdit() {
super.startEdit();
updateViewModel();
}
@Override
public void cancelEdit() {
super.cancelEdit();
updateViewModel();
}
}
//Cell factory for incompleteTaskListView and completeTaskListView
//cell factory displays cell with following information about a task(if available):
//Task name, task priority and task due date
private class CustomTaskListViewCell extends ListCell<Task>{
@Override
protected void updateItem(Task item, boolean empty) {
super.updateItem(item, empty);
updateViewModel();
}
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);
}
}
}
//event handler for newToDoListTextField and addTodoListButton
//event handlers will help the user to add new ToDo list to the program
private void setAddToDoListButtonAndFieldHandler(){
newToDoListTextField.addEventHandler(KEY_PRESSED, (event) -> {
//if enter pressed, save To Do List
if (event.getCode().equals(KeyCode.ENTER)) {
if (!newToDoListTextField.getText().isEmpty()) {
ToDoList toAdd = new ToDoList(newToDoListTextField.getText());
//add new list to the top
toDoListModel.add(0, toAdd);
newToDoListTextField.clear();
//select the newly added list
todoListView.getSelectionModel().select(toAdd);
newTaskTextField.requestFocus();
}
}
});
//if addTodoListButton button pressed, add the new ToDo list in the newToDoListTextField to the program
addTodoListButton.setOnAction(event -> {
if (!newToDoListTextField.getText().isEmpty()) {
ToDoList toAdd = new ToDoList(newToDoListTextField.getText());
//add new list to the top
toDoListModel.add(0, toAdd);
newToDoListTextField.clear();
//select the newly added list
todoListView.getSelectionModel().select(toAdd);
newTaskTextField.requestFocus();
}
});
}
//adding event handler for newToDoListTextField and addTodoListButton in the function
//event handlers will help the user to add new Task to the program
private void setAddTaskButtonAndFieldHandler(){
//add new task to the program if newTaskTextField has focus and enter is pressed
//new task added has the same name as the newTaskTextField's Text property
newTaskTextField.addEventHandler(KEY_PRESSED, event -> {
if(event.getCode().equals(KeyCode.ENTER)){
if(!newTaskTextField.getText().isEmpty()){
incompleteTaskListView.getSelectionModel().clearSelection();
int selectedToDoListIndex = todoListView.getSelectionModel().getSelectedIndex();
toDoListModel.get(selectedToDoListIndex).getIncompleteTaskList().add(0, new Task(newTaskTextField.getText()));
incompleteTaskListView.getSelectionModel().select(0);
newTaskTextField.clear();
}
}
});
//if addTaskButton clicked, add the ew event to the program
addTaskButton.setOnAction(event -> {
if(!newTaskTextField.getText().isEmpty()){
incompleteTaskListView.getSelectionModel().clearSelection();
int selectedToDoListIndex = todoListView.getSelectionModel().getSelectedIndex();
toDoListModel.get(selectedToDoListIndex).getIncompleteTaskList().add(0, new Task(newTaskTextField.getText()));
incompleteTaskListView.getSelectionModel().select(0);
newTaskTextField.clear();
}
});
}
//adding event handler for addSubTaskField and addSubTaskButton
//event handlers will enable the user to add new sub tasks to a selected task
private void setAddSubTaskButtonAndField(){
//if addSubTaskField has focus and if enter pressed, add sub task to the program given that addSubTaskField is not empty
addSubTaskField.addEventHandler(KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
if (!addSubTaskField.getText().isEmpty()) {
incompleteTaskListView.getSelectionModel().getSelectedItem().getSubTasks().add(0, new SubTask(addSubTaskField.getText()));
subTaskListView.getSelectionModel().select(-1);
addSubTaskField.clear();
}
}
});
//if addSubTaskButton pressed, add sub task to the program
addSubTaskButton.setOnAction(event -> {
if (!addSubTaskField.getText().isEmpty()) {
incompleteTaskListView.getSelectionModel().getSelectedItem().getSubTasks().add(0, new SubTask(addSubTaskField.getText()));
subTaskListView.getSelectionModel().select(-1);
addSubTaskField.clear();
}
});
}
//adding setOnMouseClicked event handler for incompleteTaskListView and completeTaskListView so that a task can be marked as
//complete or incomplete
//if a task in the incompleteTaskListView is double clicked, it will be marked as completed and moved to completeTaskListView and vice versa
private void setTaskCompleteOrIncomplete(){
incompleteTaskListView.setOnMouseClicked(event -> {
if (event.getClickCount() >= 2) {
int selectedToDoList_Index = todoListView.getSelectionModel().getSelectedIndex();
int selectedTaskEvent_Index = incompleteTaskListView.getSelectionModel().getSelectedIndex();
if (selectedToDoList_Index >= 0 && selectedTaskEvent_Index >= 0) {
Task selectedTask = toDoListModel.get(selectedToDoList_Index).getIncompleteTaskList().get(selectedTaskEvent_Index);
toDoListModel.get(selectedToDoList_Index).getIncompleteTaskList().remove(selectedTaskEvent_Index);
selectedTask.setComplete(true);
toDoListModel.get(selectedToDoList_Index).getCompleteTaskList().add(0, selectedTask);
}
}
});
completeTaskListView.setOnMouseClicked(event -> {
if (event.getClickCount() >= 2) {
int selectedToDoList_Index = todoListView.getSelectionModel().getSelectedIndex();
int selectedTaskEvent_Index = completeTaskListView.getSelectionModel().getSelectedIndex();
if (selectedToDoList_Index >= 0 && selectedTaskEvent_Index >= 0) {
Task selectedTask = toDoListModel.get(selectedToDoList_Index).getCompleteTaskList().get(selectedTaskEvent_Index);
toDoListModel.get(selectedToDoList_Index).getCompleteTaskList().remove(selectedTaskEvent_Index);
selectedTask.setComplete(false);
toDoListModel.get(selectedToDoList_Index).getIncompleteTaskList().add(0, selectedTask);
}
}
});
}
//adding setOnMouseClicked event handler for subTaskListView so that a sub task can be marked complete
//when a sub task in the subTaskListView is clicked more than twice, the sub task task will be marked complete and removed out of the subTaskListView
private void setSubTaskComplete(){
subTaskListView.setOnMouseClicked(event -> {
if (event.getClickCount() >= 2) {
incompleteTaskListView.getSelectionModel().getSelectedItem().getSubTasks().remove(subTaskListView.getSelectionModel().getSelectedItem());
subTaskListView.getSelectionModel().select(-1);
}
});
}
//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);
}
});
}
//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());
}
}
//updates view based on following actions :
//when a user changes a task's priority, modified task is saved
//when a user types in the taskNameTextField, enable the saveNewTaskNameButton
//added listener for saveNewTaskNameButton (when a user clicks it, the task is updated) and clearDueDate
private void updateTaskView(){
int selectedToDoListIndex = todoListView.getSelectionModel().getSelectedIndex();
int selectedTaskIndex = incompleteTaskListView.getSelectionModel().getSelectedIndex();
EventHandler<ActionEvent> toggleAction = observable -> {
saveTaskInfo(incompleteTaskListView.getSelectionModel().getSelectedItem());
};
lowPriorityToggle.setOnAction(toggleAction);
mediumPriorityToggle.setOnAction(toggleAction);
highPriorityToggle.setOnAction(toggleAction);
taskNameTextField.setOnKeyPressed(event -> {
saveNewTaskNameButton.disableProperty().setValue(false);
});
saveNewTaskNameButton.setOnAction(event -> {
saveTaskInfo(incompleteTaskListView.getSelectionModel().getSelectedItem());
});
clearDueDate.setOnAction(event -> {
taskDueDatePicker.setValue(null);
saveTaskInfo(incompleteTaskListView.getSelectionModel().getSelectedItem());
});
}
//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());
}
//clears data for taskInfoVBox's nodes/components
private void clearTaskInfoVBoxData(ChangeListener<? super LocalDate> dateChangeListener){
taskNameTextField.clear();
taskDueDatePicker.valueProperty().removeListener(dateChangeListener);
taskDueDatePicker.setValue(null);
priority_toggle_group.selectToggle(null);
subTaskListView.setItems(null);
addSubTaskField.clear();
taskNoteTextArea.clear();
}
//if showHideCompletedTaskButton clicked, show the completeTaskListView if it is hidden and vice versa
@FXML
private void showHideCompletedTask(){
if(completeTaskListView.disabledProperty().get()){
completeTaskListView.disableProperty().setValue(false);
completeTaskListView.setVisible(true);
showHideCompletedTaskButton.setText("Hide Completed Tasks");
}else{
completeTaskListView.disableProperty().setValue(true);
completeTaskListView.setVisible(false);
showHideCompletedTaskButton.setText("Show Completed Tasks");
}
}
//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");
}
}
@FXML
private Button clearDueDate;
@FXML
private Button saveNewTaskNameButton;
@FXML
private Label messageLabel;
@FXML
private VBox toDoListTasksInfoVBox;
@FXML
private ListView<ToDoList> todoListView;
@FXML
private Button addTodoListButton;
@FXML
private TextField newTaskTextField;
@FXML
private ListView<Task> incompleteTaskListView;
@FXML
private Button showHideCompletedTaskButton;
@FXML
private ListView<Task> completeTaskListView;
@FXML
private VBox taskInfoVBox;
@FXML
private TextField taskNameTextField;
@FXML
private DatePicker taskDueDatePicker;
@FXML
private ToggleButton lowPriorityToggle;
@FXML
private ToggleGroup priority_toggle_group;
@FXML
private ToggleButton mediumPriorityToggle;
@FXML
private ToggleButton highPriorityToggle;
@FXML
private ListView<SubTask> subTaskListView;
@FXML
private TextField addSubTaskField;
@FXML
private TextArea taskNoteTextArea;
@FXML
private Button addSubTaskButton;
@FXML
private Button addTaskButton;
@FXML
private Button deleteTaskButton;
@FXML
private TextField newToDoListTextField;
}