From 8d3fbc06ad68b4bcbd6bf3fe1c15476103d38bf8 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Mon, 21 Nov 2022 07:03:45 +0100 Subject: [PATCH] added task list editor date cell factory --- .../TaskFormularController.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java index 46cac68..cf8e8d5 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java @@ -1,14 +1,22 @@ package ch.zhaw.gartenverwaltung; import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.GrowthPhaseType; import ch.zhaw.gartenverwaltung.types.Task; import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.DateCell; import javafx.scene.control.DatePicker; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; +import javafx.util.Callback; -public class TaskFormularController { - Crop crop; +import java.net.URL; +import java.time.LocalDate; +import java.util.ResourceBundle; + +public class TaskFormularController implements Initializable { + private Crop crop; @FXML private TextArea description_area; @@ -44,4 +52,32 @@ public class TaskFormularController { end_datePicker.setValue(task.getEndDate().get()); interval_field.setText(task.getInterval().get().toString()); } + + private Callback getDayCellFactory() { + + 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;"); + } + } + }; + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + start_datePicker.setDayCellFactory(getDayCellFactory()); + start_datePicker.setEditable(false); + + end_datePicker.setDayCellFactory(getDayCellFactory()); + end_datePicker.setEditable(false); + } }