-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskView.java
More file actions
81 lines (66 loc) · 2.53 KB
/
TaskView.java
File metadata and controls
81 lines (66 loc) · 2.53 KB
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
package com.electroniccalendar.electroniccalendar;
import com.electroniccalendar.electroniccalendar.api.TasksApiClient;
import com.electroniccalendar.electroniccalendar.model.TaskA;
import javafx.concurrent.Task;
import javafx.scene.layout.VBox;
import javafx.scene.control.*;
import java.util.List;
public class TaskView extends VBox {
private ListView<TaskA> taskList;
private TextField taskTitle;
private TextArea taskDescription;
private ComboBox<String> priorityBox;
private Button addTaskButton;
private TasksApiClient apiClient = new TasksApiClient();
private Long currentUserId;
public TaskView() {
taskList = new ListView<>();
taskTitle = new TextField();
taskDescription = new TextArea();
priorityBox = new ComboBox<>();
addTaskButton = new Button("Добавить задачу");
priorityBox.getItems().addAll("Низкий", "Средний", "Высокий");
setSpacing(10);
getChildren().addAll(taskList, taskTitle, taskDescription, priorityBox, addTaskButton);
addTaskButton.setOnAction(e -> addNewTask());
}
private void addNewTask() {
TaskA newTask = new TaskA();
newTask.setTitle(taskTitle.getText());
newTask.setDescription(taskDescription.getText());
newTask.setPriority(priorityBox.getValue());
newTask.setUserId(currentUserId);
apiClient.createTask(newTask);
loadTasks();
}
private void loadTasks() {
Task<List<TaskA>> loadTask = new Task<>() {
@Override
protected List<TaskA> call() throws Exception {
return apiClient.getAllTasks(currentUserId);
}
};
loadTask.setOnSucceeded(event -> {
List<TaskA> tasks = loadTask.getValue();
taskList.getItems().clear();
taskList.getItems().addAll(tasks);
});
new Thread(loadTask).start();
}
public void setCurrentUserId(Long userId) {
this.currentUserId = userId;
}
{
taskList.setCellFactory(listView -> new ListCell<TaskA>() {
@Override
protected void updateItem(TaskA taskA, boolean empty) {
super.updateItem(taskA, empty);
if (empty || taskA == null) {
setText(null);
} else {
setText(taskA.getTitle() + " - " + taskA.getStatus());
}
}
});
}
}