Compare commits
4 Commits
b0369e3174
...
e22cb0b24d
Author | SHA1 | Date |
---|---|---|
giavaphi | e22cb0b24d | |
giavaphi | 1c83fc4694 | |
giavaphi | df19edb25a | |
giavaphi | 6b7a6f095d |
|
@ -104,16 +104,16 @@ public class CropDetailController {
|
||||||
* open dialog to set area
|
* open dialog to set area
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void setArea() {
|
void setArea() throws IOException {
|
||||||
|
openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* open dialog to set location
|
* open dialog to set location
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void setLocation() {
|
void setLocation() throws IOException {
|
||||||
|
openTextFieldDialog("set Location", "Location", location_label.getText(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,6 +218,7 @@ public class CropDetailController {
|
||||||
setIconToButton(edit, "editIcon.png");
|
setIconToButton(edit, "editIcon.png");
|
||||||
setIconToButton(delete, "deleteIcon.png");
|
setIconToButton(delete, "deleteIcon.png");
|
||||||
edit.setOnAction(getEditTaskEvent(task));
|
edit.setOnAction(getEditTaskEvent(task));
|
||||||
|
delete.setOnAction(deleteTask(task));
|
||||||
|
|
||||||
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
|
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
|
||||||
return hBox;
|
return hBox;
|
||||||
|
@ -260,6 +261,12 @@ public class CropDetailController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EventHandler<ActionEvent> deleteTask(Task task) {
|
||||||
|
return (event) -> {
|
||||||
|
showDeleteTask(task);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
|
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
|
||||||
Dialog<Task> dialog = new Dialog<>();
|
Dialog<Task> dialog = new Dialog<>();
|
||||||
dialog.setTitle("Set Task");
|
dialog.setTitle("Set Task");
|
||||||
|
@ -278,6 +285,7 @@ public class CropDetailController {
|
||||||
|
|
||||||
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
|
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
|
||||||
controller.setCorp(this.crop);
|
controller.setCorp(this.crop);
|
||||||
|
controller.initSaveButton((Button) dialogPane.lookupButton(saveTask));
|
||||||
if (!newTask) {
|
if (!newTask) {
|
||||||
controller.setTaskValue(givenTask);
|
controller.setTaskValue(givenTask);
|
||||||
}
|
}
|
||||||
|
@ -300,4 +308,56 @@ 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);
|
||||||
|
controller.initSaveButton((Button) dialogPane.lookupButton(save));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDeleteTask(Task task) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Delete " + task.getName());
|
||||||
|
alert.setHeaderText("Are you sure want to delete this Task?");
|
||||||
|
|
||||||
|
alert.showAndWait()
|
||||||
|
.ifPresent(buttonType -> {
|
||||||
|
if (buttonType == ButtonType.OK) {
|
||||||
|
try {
|
||||||
|
gardenSchedule.removeTask(task);
|
||||||
|
setTaskListProperty(this.crop);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO: Show error alert
|
||||||
|
LOG.log(Level.SEVERE, "Could not remove crop.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
|
import javafx.beans.binding.Binding;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.BooleanBinding;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.DateCell;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.DatePicker;
|
|
||||||
import javafx.scene.control.TextArea;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -56,7 +58,7 @@ public class TaskFormularController implements Initializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
private Callback<DatePicker, DateCell> getDayCellFactoryStartDate() {
|
||||||
|
|
||||||
return (datePicker) -> new DateCell() {
|
return (datePicker) -> new DateCell() {
|
||||||
private final LocalDate today = LocalDate.now();
|
private final LocalDate today = LocalDate.now();
|
||||||
|
@ -71,16 +73,61 @@ public class TaskFormularController implements Initializable {
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (end_datePicker.getValue() != null && item.compareTo(end_datePicker.getValue()) > 0) {
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Callback<DatePicker, DateCell> getDayCellFactoryEndDate() {
|
||||||
|
|
||||||
|
return (datePicker) -> new DateCell() {
|
||||||
|
private final LocalDate today = LocalDate.now();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItem(LocalDate item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
|
||||||
|
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
||||||
|
setDisable(false);
|
||||||
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_datePicker.getValue() != null && item.compareTo(start_datePicker.getValue()) < 0) {
|
||||||
|
setDisable(true);
|
||||||
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initSaveButton(Button button) {
|
||||||
|
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (!newValue.matches("\\d*")) {
|
||||||
|
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
||||||
|
.or(end_datePicker.valueProperty().isNull())
|
||||||
|
.or(taskName_field.textProperty().isEmpty())
|
||||||
|
.or(description_area.textProperty().isEmpty())
|
||||||
|
.or(interval_field.textProperty().isEmpty()));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
start_datePicker.setDayCellFactory(getDayCellFactory());
|
start_datePicker.setDayCellFactory(getDayCellFactoryStartDate());
|
||||||
start_datePicker.setEditable(false);
|
start_datePicker.setEditable(false);
|
||||||
|
|
||||||
end_datePicker.setDayCellFactory(getDayCellFactory());
|
end_datePicker.setDayCellFactory(getDayCellFactoryEndDate());
|
||||||
end_datePicker.setEditable(false);
|
end_datePicker.setEditable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initSaveButton(Button button) {
|
||||||
|
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,7 +73,10 @@ public class AppLoader {
|
||||||
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
||||||
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
Pane root = loader.load();
|
Pane root = loader.load();
|
||||||
appendee.setScene(new Scene(root));
|
Scene scene = new Scene(root);
|
||||||
|
String css = Objects.requireNonNull(this.getClass().getResource("styles.css")).toExternalForm();
|
||||||
|
appendee.setScene(scene);
|
||||||
|
scene.getStylesheets().add(css);
|
||||||
Object controller = loader.getController();
|
Object controller = loader.getController();
|
||||||
annotationInject(controller);
|
annotationInject(controller);
|
||||||
return controller;
|
return controller;
|
||||||
|
|
|
@ -48,6 +48,10 @@ public class TaskTemplate {
|
||||||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
||||||
|
|
||||||
|
if (interval == null) {
|
||||||
|
this.interval = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
|
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
|
||||||
.withInterval(interval)
|
.withInterval(interval)
|
||||||
.withEndDate(endDate);
|
.withEndDate(endDate);
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
|
||||||
|
|
||||||
|
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="298.0" xmlns="http://javafx.com/javafx/17"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TextFieldFormularController">
|
||||||
|
<children>
|
||||||
|
<HBox alignment="CENTER" layoutX="153.0" layoutY="33.0" prefHeight="100.0" prefWidth="200.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="description_label" maxWidth="1.7976931348623157E308" text="Label" HBox.hgrow="ALWAYS" />
|
||||||
|
<TextField fx:id="text_area" HBox.hgrow="NEVER" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
|
@ -0,0 +1,6 @@
|
||||||
|
.button{
|
||||||
|
-fx-text-fill: rgb(49, 89, 23);
|
||||||
|
-fx-border-color: rgb(49, 89, 23);
|
||||||
|
-fx-border-radius: 5;
|
||||||
|
-fx-padding: 3 6 6 6;
|
||||||
|
}
|
Loading…
Reference in New Issue