blob: 66b45d211df7ef801066370c592fabff190fbd83 (
plain) (
blame)
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
|
package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee.EducationLevel;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Registration;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.Status;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;
public class VehiclePaneController extends CustomListItemController {
public static VehiclePaneController createVehiclePane() throws IOException {
FXMLLoader fxmlLoader =
new FXMLLoader(VehiclePaneController.class.getResource("/fxml/vehiclePane.fxml"));
Node root = fxmlLoader.load();
VehiclePaneController result = fxmlLoader.getController();
result.rootElement = root;
return result;
}
@FXML private Label txtStatus;
@FXML private Text txtType;
@FXML private Text txtNumber;
@FXML private ImageView ivNEF;
@FXML private Text txtNEF;
@FXML private ImageView ivQualification;
@FXML private Text txtQualification;
@FXML private Text txtRooftype;
@FXML private Button btnRequest;
private Vehicle data;
public Vehicle getData() {
return data;
}
/**
* * Set the displayed data of this VehiclePane.
*
* @param vehicle The data to display.
* @param showStatusInfo If true, the highest qualification of the vehicle's active registration
* and the vehicle's status will be shown.
*/
public void setData(Vehicle vehicle, boolean showStatusInfo, boolean showRequestVehicle) {
txtType.setText(vehicle.type().name());
String constrType = vehicle.constructionType().name();
txtRooftype.setText(
constrType.substring(0, 1).toUpperCase() + constrType.substring(1).toLowerCase());
txtNumber.setText("-" + vehicle.id());
if (vehicle.hasNef()) {
ivNEF.setImage(new Image("images/NEF.png"));
txtNEF.setText("hat NEF-Halterung");
} else {
ivNEF.setImage(new Image("images/NotNEF.png"));
txtNEF.setText("keine NEF-Halterung");
}
if (showRequestVehicle) {
btnRequest.setVisible(true);
btnRequest.setManaged(true);
} else {
btnRequest.setVisible(false);
btnRequest.setManaged(false);
}
if (showStatusInfo) {
txtStatus.setText(vehicle.status().name());
if (vehicle.status() == Status.FREI_FUNK || vehicle.status() == Status.FREI_WACHE) {
txtStatus.getStyleClass().add("bg-status-green");
} else {
txtStatus.getStyleClass().add("bg-status-orange");
}
Instant now = Instant.now();
List<Registration> regs = vehicle.registrations();
if (regs == null) {
return;
}
Optional<EducationLevel> edu =
regs.stream()
.filter(reg -> reg.start().isBefore(now) && reg.end().isAfter(now))
.map(reg -> reg.employee().educationLevel())
.max(EducationLevel::compareTo);
if (!edu.isPresent()) {
return;
}
txtQualification.setText(edu.get().name());
} else {
txtQualification.setVisible(false);
txtQualification.setManaged(false);
ivQualification.setVisible(false);
ivQualification.setManaged(false);
txtStatus.setVisible(false);
}
this.data = vehicle;
}
public Button getBtnRequest() {
return btnRequest;
}
}
|