diff options
Diffstat (limited to 'src')
5 files changed, 364 insertions, 2 deletions
diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java index 05a548c..ce5613e 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceImpl.java @@ -5,6 +5,7 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; @@ -116,7 +117,24 @@ public class OperationServiceImpl implements OperationService {      @Override      public void complete(long operationId, Status status) -            throws InvalidOperationException, ServiceException {} +            throws InvalidOperationException, ServiceException { +        Operation operation; +        try { +            operation = operationDAO.get(operationId); +        } catch (ElementNotFoundException e) { +            throw new InvalidOperationException(e); +        } catch (PersistenceException e) { +            throw new ServiceException(e); +        } +        operation = operation.toBuilder().status(status).build(); +        try { +            operationDAO.update(operation); +        } catch (ElementNotFoundException e) { +            throw new InvalidOperationException(e); +        } catch (PersistenceException e) { +            throw new ServiceException(e); +        } +    }      @Override      public SortedList<Vehicle> rankVehicles(long operationId) diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 5b645f3..ea21691 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -47,9 +47,11 @@ public class CreateOperationController {      public TextField txtNote;      public Button btnCreateOperation;      public ListView<Vehicle> lvVehicles; -    public ListView lvActiveOperations; +    public ListView<Operation> lvActiveOperations;      public Label lblChosenVehicles;      public LinkedList<Vehicle> chosenVehicles = new LinkedList<>(); +    public AnchorPane apInvisible; +    @FXML private OperationDetailsController operationDetailsController;      // TODO: Anders?      OperationService operationService = @@ -79,6 +81,20 @@ public class CreateOperationController {                                  }                              }                          }); +        lvActiveOperations.setCellFactory( +                param -> +                        new ListCell<>() { +                            @Override +                            protected void updateItem(Operation item, boolean empty) { +                                super.updateItem(item, empty); + +                                if (empty || item == null || item.opCode() == null) { +                                    setText(null); +                                } else { +                                    setText(item.opCode()); +                                } +                            } +                        });          lvVehicles.setOnMouseClicked(                  event -> { @@ -114,6 +130,15 @@ public class CreateOperationController {                          }                      }                  }); +        lvActiveOperations.setOnMouseClicked( +                event -> { +                    if (event.getClickCount() == 2) { +                        if (lvActiveOperations.getSelectionModel().getSelectedItem() == null) { +                            return; +                        } +                        openDetailsWindow(lvActiveOperations.getSelectionModel().getSelectedItem()); +                    } +                });      }      public void updateList() { @@ -130,6 +155,17 @@ public class CreateOperationController {              alert.setContentText(e.getMessage());              alert.showAndWait();          } +        try { +            lvActiveOperations.setItems( +                    FXCollections.observableArrayList( +                            operationService.list(EnumSet.of(Status.ACTIVE)))); +        } catch (ServiceException e) { +            Alert alert = new Alert(Alert.AlertType.ERROR); +            alert.setTitle("Fehler - Einsätze"); +            alert.setHeaderText("Beim Holen der aktiven Einsätze ist ein Fehler aufgetreten."); +            alert.setContentText(e.getMessage()); +            alert.showAndWait(); +        }      }      /*private LinkedList<Vehicle> mylist() { @@ -224,4 +260,14 @@ public class CreateOperationController {          updateList();      } + +    private void openDetailsWindow(Operation operation) { +        operationDetailsController.setControllers(this, operationService, vehicleService); +        apInvisible.setVisible(true); +        operationDetailsController.initOperation(operation); +    } + +    void setVisible(boolean b) { +        apInvisible.setVisible(!b); +    }  } diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java new file mode 100644 index 0000000..cacaa29 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java @@ -0,0 +1,194 @@ +package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.EnumSet; +import javafx.collections.FXCollections; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.AnchorPane; +import org.springframework.stereotype.Controller; + +@Controller +public class OperationDetailsController { + +    public Operation operation; +    private OperationService operationService; +    private VehicleService vehicleService; +    private CreateOperationController createOperationController; +    public ListView<Vehicle> lvVehicles; +    public ListView<Operation> lvActiveOperations; +    public Label lblChosenVehicles; +    public Button btnCloseOperation; +    public Button btnCancelOperation; +    public Label lblCode, lblAdditionalInfo, lblAddress; +    public AnchorPane operationDetailsAP; + +    public OperationDetailsController() {} + +    @FXML +    public void initialize() { +        lvVehicles.setCellFactory( +                param -> +                        new ListCell<>() { +                            @Override +                            protected void updateItem(Vehicle item, boolean empty) { +                                super.updateItem(item, empty); + +                                if (empty || item == null || item.name() == null) { +                                    setText(null); +                                } else { +                                    setText(item.name()); +                                } +                            } +                        }); +        lvActiveOperations.setCellFactory( +                param -> +                        new ListCell<>() { +                            @Override +                            protected void updateItem(Operation item, boolean empty) { +                                super.updateItem(item, empty); + +                                if (empty || item == null || item.opCode() == null) { +                                    setText(null); +                                } else { +                                    setText(item.opCode()); +                                } +                            } +                        }); +        lvActiveOperations.setOnMouseClicked( +                event -> { +                    if (event.getClickCount() == 2) { +                        if (lvActiveOperations.getSelectionModel().getSelectedItem() == null) { +                            return; +                        } +                        initOperation(lvActiveOperations.getSelectionModel().getSelectedItem()); +                    } +                }); +    } + +    void setControllers( +            CreateOperationController createOperationController, +            OperationService operationService, +            VehicleService vehicleService) { +        this.operationService = operationService; +        this.createOperationController = createOperationController; +        this.vehicleService = vehicleService; +    } + +    void initOperation(Operation operation) { +        fillActiveList(); +        this.operation = operation; +        lblCode.setText(operation.opCode()); +        StringBuilder result = new StringBuilder(); +        for (int i = 0; i < operation.vehicles().size(); i++) { +            if (i != operation.vehicles().size() - 1) { +                result.append(operation.vehicles().get(i).name()).append(","); +            } else { +                result.append(operation.vehicles().get(i).name()); +            } +        } +        lblChosenVehicles.setText(result.toString()); +        lblAdditionalInfo.setText(operation.additionalInfo()); +        lblAddress.setText(operation.destination()); +        lvVehicles.setItems(FXCollections.observableArrayList(operation.vehicles())); +        operationDetailsAP.setVisible(true); +    } + +    private void fillActiveList() { +        try { +            lvActiveOperations.setItems( +                    FXCollections.observableArrayList( +                            operationService.list(EnumSet.of(Status.ACTIVE)))); +        } catch (ServiceException e) { +            Alert alert = new Alert(AlertType.ERROR); +            alert.setTitle("Fehler"); +            alert.setHeaderText("Fehler!"); +            alert.setContentText(e.getMessage()); +            alert.showAndWait(); +        } +    } + +    @FXML +    public void closeOperationClicked() { +        try { +            operationService.complete(operation.id(), Status.COMPLETED); +        } catch (InvalidOperationException | ServiceException e) { +            Alert alert = new Alert(AlertType.ERROR); +            alert.setTitle("Fehler"); +            alert.setHeaderText("Fehler!"); +            alert.setContentText(e.getMessage()); +            alert.showAndWait(); +            return; +        } +        for (Vehicle v : operation.vehicles()) { +            v = v.toBuilder().status(Vehicle.Status.FREI_FUNK).build(); +            try { +                vehicleService.update(v); +            } catch (InvalidVehicleException | ServiceException e) { +                Alert alert = new Alert(AlertType.ERROR); +                alert.setTitle("Fehler"); +                alert.setHeaderText("Fehler!"); +                alert.setContentText(e.getMessage()); +                alert.showAndWait(); +                return; +            } +        } +        Alert alert = new Alert(AlertType.CONFIRMATION); +        alert.setTitle("Erfolg"); +        alert.setHeaderText("Erfolgreich aktualisiert"); +        alert.setContentText("Der Einsatz wurde erfolgreich aktualisiert."); +        alert.showAndWait(); +        closeWindow(); +        createOperationController.updateList(); +    } + +    public void cancelOperationClicked() { +        try { +            operationService.complete(operation.id(), Status.CANCELLED); +        } catch (InvalidOperationException | ServiceException e) { +            Alert alert = new Alert(AlertType.ERROR); +            alert.setTitle("Fehler"); +            alert.setHeaderText("Fehler!"); +            alert.setContentText(e.getMessage()); +            alert.showAndWait(); +            return; +        } +        for (Vehicle v : operation.vehicles()) { +            v = v.toBuilder().status(Vehicle.Status.FREI_FUNK).build(); +            try { +                vehicleService.update(v); +            } catch (InvalidVehicleException | ServiceException e) { +                Alert alert = new Alert(AlertType.ERROR); +                alert.setTitle("Fehler"); +                alert.setHeaderText("Fehler!"); +                alert.setContentText(e.getMessage()); +                alert.showAndWait(); +                return; +            } +        } +        Alert alert = new Alert(AlertType.CONFIRMATION); +        alert.setTitle("Erfolg"); +        alert.setHeaderText("Erfolgreich aktualisiert"); +        alert.setContentText("Der Einsatz wurde erfolgreich aktualisiert."); +        alert.showAndWait(); +        closeWindow(); +        createOperationController.updateList(); +    } + +    public void closeWindow() { +        operationDetailsAP.setVisible(false); +        this.createOperationController.setVisible(true); +    } +} diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 086a5d1..99f2e22 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -91,5 +91,7 @@           </children>        </AnchorPane>        <ListView fx:id="lvVehicles" layoutX="40.0" layoutY="228.0" prefHeight="388.0" prefWidth="920.0" style="-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 5);" /> +      <AnchorPane fx:id="apInvisible" prefHeight="650.0" prefWidth="1200.0" style="-fx-background-color: rgba(0,0,0,0.7);" visible="false" /> +      <fx:include fx:id="operationDetails" source="/fxml/OperationDetails.fxml" AnchorPane.leftAnchor="54.0" AnchorPane.topAnchor="50.0" />     </children>  </AnchorPane> diff --git a/src/main/resources/fxml/OperationDetails.fxml b/src/main/resources/fxml/OperationDetails.fxml new file mode 100644 index 0000000..f4d2a17 --- /dev/null +++ b/src/main/resources/fxml/OperationDetails.fxml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Hyperlink?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.ListView?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.text.Font?> + +<AnchorPane fx:id="operationDetailsAP" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="542.0" prefWidth="1100.0" visible="false" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.OperationDetailsController"> +  <children> +    <AnchorPane prefHeight="542.0" prefWidth="1100.0" style="-fx-background-color: white;" /> +    <AnchorPane layoutX="10.0" layoutY="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="542.0" prefWidth="1000.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0"> +      <children> +        <AnchorPane layoutX="964.0" layoutY="-66.0" prefHeight="152.0" prefWidth="1100.0" style="-fx-background-color: green;" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0"> +          <children> +            <Hyperlink layoutX="1023.0" layoutY="16.0" onAction="#closeWindow" text="Zurück" textFill="WHITE"> +              <font> +                <Font size="15.0" /> +              </font> +            </Hyperlink> +            <Label layoutX="17.0" layoutY="13.0" prefHeight="34.0" prefWidth="174.0" text="Ausgewählter Einsatz:" textFill="WHITE"> +              <font> +                <Font size="17.0" /> +              </font> +            </Label> +          </children> +        </AnchorPane> +        <AnchorPane fx:id="apActiveOperations" layoutX="874.0" layoutY="50.0" prefHeight="298.0" prefWidth="200.0" style="-fx-background-color: white; -fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 5);"> +          <children> +            <ListView fx:id="lvActiveOperations" layoutX="9.0" layoutY="55.0" prefHeight="242.0" prefWidth="182.0" style="-fx-background-color: white;" /> +            <Label layoutX="9.0" layoutY="11.0" prefHeight="46.0" prefWidth="103.0" text="Aktive Einsätze"> +              <font> +                <Font name="System Bold" size="14.0" /> +              </font> +            </Label> +            <Label layoutX="150.0" layoutY="24.0" text="Archiv"> +              <font> +                <Font size="13.0" /> +              </font> +            </Label> +          </children> +        </AnchorPane> +        <ListView fx:id="lvVehicles" layoutX="16.0" layoutY="185.0" prefHeight="355.0" prefWidth="846.0" style="-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 5);" /> +        <AnchorPane fx:id="apCreateOperation" layoutX="16.0" layoutY="49.0" prefHeight="134.0" prefWidth="845.0" style="-fx-background-color: white; -fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 5, 0, 0, 5);"> +          <children> +            <Label layoutX="14.0" layoutY="14.0" prefHeight="30.0" prefWidth="62.0" text="Code"> +              <font> +                <Font size="15.0" /> +              </font> +            </Label> +            <Label layoutX="185.0" layoutY="14.0" prefHeight="30.0" prefWidth="94.0" text="Adresse"> +              <font> +                <Font size="15.0" /> +              </font> +            </Label> +            <Label layoutX="563.0" layoutY="14.0" prefHeight="30.0" prefWidth="121.0" text="Anmerkung"> +              <font> +                <Font size="15.0" /> +              </font> +            </Label> +            <Label layoutX="14.0" layoutY="96.0" prefHeight="30.0" prefWidth="102.0" text="Fahrzeuge:"> +              <font> +                <Font size="17.0" /> +              </font> +            </Label> +            <Label fx:id="lblChosenVehicles" layoutX="105.0" layoutY="96.0" prefHeight="30.0" prefWidth="418.0" text="keine ausgewählt"> +              <font> +                <Font size="17.0" /> +              </font> +            </Label> +            <Button fx:id="btnCloseOperation" layoutX="709.0" layoutY="89.0" mnemonicParsing="false" onAction="#closeOperationClicked" prefHeight="39.0" prefWidth="122.0" text="Abschließen"> +              <font> +                <Font name="System Bold" size="17.0" /> +              </font> +            </Button> +            <Button fx:id="btnCancelOperation" layoutX="575.0" layoutY="90.0" mnemonicParsing="false" onAction="#cancelOperationClicked" prefHeight="38.0" prefWidth="122.0" text="Stornieren"> +              <font> +                <Font name="System Bold" size="17.0" /> +              </font> +            </Button> +            <Label fx:id="lblCode" layoutX="14.0" layoutY="39.0" prefHeight="46.0" prefWidth="154.0"> +              <font> +                <Font name="System Bold" size="19.0" /> +              </font> +            </Label> +            <Label fx:id="lblAddress" layoutX="185.0" layoutY="39.0" prefHeight="44.0" prefWidth="374.0"> +              <font> +                <Font name="System Bold" size="19.0" /> +              </font> +            </Label> +            <Label fx:id="lblAdditionalInfo" layoutX="562.0" layoutY="39.0" prefHeight="44.0" prefWidth="272.0"> +              <font> +                <Font name="System Bold" size="19.0" /> +              </font> +            </Label> +          </children> +        </AnchorPane> +      </children> +    </AnchorPane> +  </children> +</AnchorPane>  | 
