diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java index e223e8b..2fe9139 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java @@ -1,16 +1,23 @@ package ch.zhaw.gartenverwaltung; +import ch.zhaw.gartenverwaltung.types.Crop; import ch.zhaw.gartenverwaltung.types.Plant; import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import java.io.IOException; import java.net.URL; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.ResourceBundle; public class MyPlantsController implements Initializable { @@ -30,14 +37,14 @@ public class MyPlantsController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { //ToDo - List myPlants = getMyPlants(); - createPlantView(myPlants); + List cropList = getCropList(); + createPlantView(cropList); } - private void createPlantView(List myPlants) { - //ToDo - for(Plant plant : myPlants) { - createPlantView(); + private void createPlantView(List crops) { + for(Crop crop : crops) { + HBox hBox = createPlantView(crop); + myPlants_vbox.getChildren().add(hBox); } } @@ -45,14 +52,60 @@ public class MyPlantsController implements Initializable { mainController = controller; } - private List getMyPlants() { - //ToDo method to get myPlantList(scheduled) - //Method to call all Plants saved - List myPlantList = new LinkedList<>(); - return myPlantList; + private List getCropList() { + //ToDo method to get cropList + //Method to get Crop List + List cropList = new LinkedList<>(); + return cropList; } - private void createPlantView() { - //ToDo FXML Panel with Plant data + private HBox createPlantView(Crop crop) { + //ToDo add dynamic design + HBox hBox = new HBox(); + Label label = new Label("Placeholder"); + Button details = new Button("Details"); + Button delete = new Button("delete"); + details.setOnAction(getGoToCropDetailEvent(crop)); + delete.setOnAction(getDeleteCropEvent(crop)); + hBox.getChildren().addAll(label, details, delete); + return hBox; + } + + private EventHandler getGoToCropDetailEvent(Crop crop) { + EventHandler event = new EventHandler() { + @Override + public void handle(ActionEvent event) { + //ToDo uncomment when new FXML exists + /*try { + mainController.loadPane(""); + } catch (IOException e) { + e.printStackTrace(); + }*/ + } + }; + return event; + } + + private EventHandler getDeleteCropEvent(Crop crop) { + EventHandler event = new EventHandler() { + @Override + public void handle(ActionEvent event) { + showConfirmation(crop); + } + }; + return event; + } + + private void showConfirmation(Crop crop) { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.setTitle("Delete Crop"); + alert.setHeaderText("Are you sure want to delete this Crop?"); + alert.setContentText("placeholder"); + + Optional option = alert.showAndWait(); + + if (option.get() == ButtonType.OK) { + //ToDo Method to remove crop + } } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java index b16445a..173c0ec 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java @@ -1,14 +1,19 @@ package ch.zhaw.gartenverwaltung; -import ch.zhaw.gartenverwaltung.types.Plant; +import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.Task; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; import java.net.URL; import java.time.LocalDate; @@ -17,7 +22,9 @@ import java.util.List; import java.util.ResourceBundle; public class MyScheduleController implements Initializable { - private Plant selectedPlant = null; + private Crop selectedCrop = null; + + private final ListProperty cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); @FXML private Label day1_label; @@ -65,28 +72,26 @@ public class MyScheduleController implements Initializable { private Label information_label; @FXML - private ListView scheduledPlants_listview; + private ListView scheduledPlants_listview; @Override public void initialize(URL location, ResourceBundle resources) { - List plantList = new LinkedList<>(); - fillListViewMyPlantsInSchedule(plantList); - getSelectedPlantTask(); + //ToDo method to load crop list + List cropList = new LinkedList<>(); + setCellFactoryListView(); + scheduledPlants_listview.itemsProperty().bind(cropListProperty); + lookForSelectedListEntries(); setDayLabels(); information_label.setText(""); + loadTaskList(); } - private void getSelectedPlantTask() { - scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + private void lookForSelectedListEntries() { + scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue observable, Plant oldValue, Plant newValue) { - if(newValue != null) { - selectedPlant = newValue; - //ToDo update day_panel with task for the day - } else { - selectedPlant = null; - //ToDo update day_panel with task for the day (all plants) - } + public void changed(ObservableValue observable, Crop oldValue, Crop newValue) { + selectedCrop = newValue; + loadTaskList(); } }); } @@ -102,23 +107,49 @@ public class MyScheduleController implements Initializable { day7_label.setText(today.plusDays(6).getDayOfWeek().toString()); } - private void fillListViewMyPlantsInSchedule(List list) { - for (Plant plant : list) { - scheduledPlants_listview.getItems().add(plant); - } - scheduledPlants_listview.setCellFactory(param -> new ListCell() { + private void setCellFactoryListView() { + scheduledPlants_listview.setCellFactory(param -> new ListCell() { @Override - protected void updateItem(Plant plant, boolean empty) { - super.updateItem(plant, empty); + protected void updateItem(Crop crop, boolean empty) { + super.updateItem(crop, empty); - if (empty || plant == null || plant.name() == null) { + if (empty || crop == null) { setText(null); } else { - setText(plant.name()); + setText("placeholder"); } } }); } + private void loadTaskList() { + //ToDo load task list according to selectedCrop + List> taskLists = new LinkedList<>(); + if (selectedCrop != null) { + + } else { + + } + if (!taskLists.isEmpty()) { + viewTaskListOfDay(day1_pane, taskLists.get(0)); + viewTaskListOfDay(day2_pane, taskLists.get(1)); + viewTaskListOfDay(day3_pane, taskLists.get(2)); + viewTaskListOfDay(day4_pane, taskLists.get(3)); + viewTaskListOfDay(day5_pane, taskLists.get(4)); + viewTaskListOfDay(day6_pane, taskLists.get(5)); + viewTaskListOfDay(day7_pane, taskLists.get(6)); + } + } + + private void viewTaskListOfDay(Pane pane, List tasks) { + //ToDo update pane with task list + VBox vBox = new VBox(); + for (Task task : tasks) { + Label label = new Label("placeholder"); + vBox.getChildren().add(label); + } + pane.getChildren().add(vBox); + } + }