diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index 7ec8652..dd7e803 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -104,16 +104,16 @@ public class CropDetailController { * open dialog to set area */ @FXML - void setArea() { - + void setArea() throws IOException { + openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false); } /** * open dialog to set location */ @FXML - void setLocation() { - + void setLocation() throws IOException { + openTextFieldDialog("set Location", "Location", location_label.getText(), true); } /** @@ -300,4 +300,36 @@ public class CropDetailController { } } + + private void openTextFieldDialog(String title, String labelDescription, String value, boolean isLocation) throws IOException { + Dialog dialog = new Dialog<>(); + dialog.setTitle(title); + dialog.setHeaderText(title); + dialog.setResizable(false); + + DialogPane dialogPane = dialog.getDialogPane(); + + ButtonType save = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE); + dialogPane.getButtonTypes().addAll(save, ButtonType.CANCEL); + + if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) { + controller.setDescription_label(labelDescription); + controller.setValueTextArea(value); + + dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null); + + dialog.showAndWait() + .ifPresent(string -> { + if (isLocation) { + System.out.println(string); + //ToDo method to set location + location_label.setText(string); + } else { + System.out.println(string); + //ToDo method to set area of crop in garden + area_label.setText(string); + } + }); + } + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java new file mode 100644 index 0000000..ebbbfe2 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java @@ -0,0 +1,27 @@ +package ch.zhaw.gartenverwaltung; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +public class TextFieldFormularController { + + @FXML + private Label description_label; + + @FXML + private TextField text_area; + + + public void setDescription_label(String string) { + description_label.setText(string); + } + + public void setValueTextArea(String string) { + text_area.setText(string); + } + + public String getValue() { + return text_area.getText(); + } +} diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml new file mode 100644 index 0000000..2d4dfdc --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + +