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 regs = vehicle.registrations(); if (regs == null) { return; } Optional 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; } }