diff options
Diffstat (limited to 'src/main')
3 files changed, 107 insertions, 7 deletions
diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java new file mode 100644 index 0000000..01c04d3 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/application/MainApplication.java @@ -0,0 +1,52 @@ +package at.ac.tuwien.sepm.assignment.groupphase.application; + +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.userInterface.CreateOperationController; +import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; +import javafx.application.Application; +import javafx.application.Platform; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; + +@Component +@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase") +public class MainApplication extends Application { + + private static AnnotationConfigApplicationContext configApplicationContext; + + public static void main(String[] args) { + Application.launch(MainApplication.class, args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + primaryStage.setTitle("Einsatz erstellen"); + primaryStage.centerOnScreen(); + primaryStage.setOnCloseRequest(event -> Platform.exit()); + + configApplicationContext = new AnnotationConfigApplicationContext(MainApplication.class); + final var fxmlLoader = configApplicationContext.getBean(SpringFXMLLoader.class); + primaryStage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/CreateOperationController.fxml")))); + + CreateOperationController controller = + configApplicationContext.getBean(CreateOperationController.class); + controller.updateList(); + primaryStage.show(); + primaryStage.toFront(); + } + + @Override + public void stop() throws Exception { + super.stop(); + configApplicationContext.close(); + } +} 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 38f6849..ae99088 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 @@ -11,12 +11,18 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader; +import java.io.IOException; +import java.lang.invoke.MethodHandles; import java.time.Instant; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import javafx.collections.FXCollections; +import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; @@ -25,11 +31,16 @@ import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @Controller public class CreateOperationController { + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public AnchorPane apCreateOperation; public TextField txtCode; public TextField txtAddress; @@ -44,9 +55,11 @@ public class CreateOperationController { OperationService operationService = new OperationServiceImpl(new DBOperationDAO(new JDBCConnectionManager())); private final VehicleService vehicleService; + private final SpringFXMLLoader fxmlLoader; - public CreateOperationController(VehicleService vehicleService) { + public CreateOperationController(VehicleService vehicleService, SpringFXMLLoader fxmlLoader) { this.vehicleService = vehicleService; + this.fxmlLoader = fxmlLoader; } @FXML @@ -174,4 +187,38 @@ public class CreateOperationController { alert.showAndWait(); updateList(); } + + public void onRegistrationLinkClicked(ActionEvent actionEvent) { + throw new UnsupportedOperationException(); + } + + public void onEmployeeLinkClicked(ActionEvent actionEvent) { + openNewWindow("createNewEmployee.fxml"); + } + + public void onVehicleLinkClicked(ActionEvent actionEvent) { + openNewWindow("createCar.fxml"); + } + + private void openNewWindow(String fxmlFileName) { + + Stage stage = new Stage(); + try { + stage.setScene( + new Scene( + (Parent) + fxmlLoader.load( + getClass() + .getResourceAsStream( + "/fxml/" + fxmlFileName)))); + } catch (IOException e) { + LOG.error("Could not open new window: {}", e); + } + + stage.setTitle("Einsatz erstellen"); + stage.centerOnScreen(); + stage.showAndWait(); // important to call wait so that updateList is executed afterwards + + updateList(); + } } diff --git a/src/main/resources/fxml/CreateOperationController.fxml b/src/main/resources/fxml/CreateOperationController.fxml index 949d4ec..1ba6498 100644 --- a/src/main/resources/fxml/CreateOperationController.fxml +++ b/src/main/resources/fxml/CreateOperationController.fxml @@ -1,6 +1,7 @@ <?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.control.TextField?> @@ -59,21 +60,21 @@ </Button> </children> </AnchorPane> - <Label layoutX="55.0" layoutY="38.0" text="Anmeldungen" textFill="WHITE"> + <Hyperlink layoutX="55.0" layoutY="38.0" onAction="#onRegistrationLinkClicked" text="Anmeldungen" textFill="WHITE"> <font> <Font size="15.0" /> </font> - </Label> - <Label layoutX="802.0" layoutY="38.0" text="Personen" textFill="WHITE"> + </Hyperlink> + <Hyperlink layoutX="802.0" layoutY="38.0" onAction="#onEmployeeLinkClicked" text="Personen" textFill="WHITE"> <font> <Font size="15.0" /> </font> - </Label> - <Label layoutX="877.0" layoutY="38.0" text="Fahrzeuge" textFill="WHITE"> + </Hyperlink> + <Hyperlink layoutX="877.0" layoutY="38.0" onAction="#onVehicleLinkClicked" text="Fahrzeuge" textFill="WHITE"> <font> <Font size="15.0" /> </font> - </Label> + </Hyperlink> <AnchorPane fx:id="apActiveOperations" layoutX="973.0" layoutY="69.0" prefHeight="243.0" prefWidth="207.0" style="-fx-background-color: white;"> <children> <ListView fx:id="lvActiveOperations" layoutX="4.0" layoutY="74.0" prefHeight="242.0" prefWidth="200.0" style="-fx-background-color: white;" /> |