dialog pane for location and area of crop
This commit is contained in:
@@ -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<String> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user