connection task list model and garden plan model with controllers

This commit is contained in:
giavaphi 2022-11-08 21:03:01 +01:00
parent 802f238d69
commit ced2645bd7
6 changed files with 104 additions and 35 deletions

View File

@ -1,5 +1,7 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Plant;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
@ -7,6 +9,8 @@ import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
public class CropDetailController {
private Crop crop = null;
private Plant plant = null;
@FXML
private Button area_button;
@ -21,10 +25,10 @@ public class CropDetailController {
private Label description_label;
@FXML
private VBox growthPahses_vbox;
private VBox growthPhases_vbox;
@FXML
private Label lacation_label;
private Label location_label;
@FXML
private Label light_label;
@ -61,4 +65,8 @@ public class CropDetailController {
}
public void setPlantFromCrop(Crop crop) {
this.crop = crop;
this.plant = null;
}
}

View File

@ -1,30 +1,39 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.Crop;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
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 javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.*;
public class MyPlantsController implements Initializable {
MainFXMLController mainController;
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
@FXML
private VBox myPlants_vbox;
public MyPlantsController() throws IOException {
}
@FXML
void addPlant(ActionEvent event) throws IOException {
mainController.loadPane("Plants.fxml");
@ -32,12 +41,21 @@ public class MyPlantsController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
//ToDo
List<Crop> cropList = getCropList();
loadCropList();
}
private void loadCropList() {
List<Crop> cropList = new LinkedList<>();
try {
cropList = getCropList();
} catch (IOException e) {
e.printStackTrace();
}
createPlantView(cropList);
}
private void createPlantView(List<Crop> crops) {
myPlants_vbox.getChildren().clear();
for(Crop crop : crops) {
HBox hBox = createPlantView(crop);
myPlants_vbox.getChildren().add(hBox);
@ -48,15 +66,15 @@ public class MyPlantsController implements Initializable {
mainController = controller;
}
private List<Crop> getCropList() {
//ToDo method to get cropList
//Method to get Crop List
List<Crop> cropList = new LinkedList<>();
private List<Crop> getCropList() throws IOException {
List<Crop> cropList;
cropList = gardenplanmodel.getCrops();
return cropList;
}
private HBox createPlantView(Crop crop) {
//ToDo add dynamic design
//ToDo add good design
//ToDo get plant information from crop
HBox hBox = new HBox();
Label label = new Label("Placeholder");
Button details = new Button("Details");
@ -71,9 +89,17 @@ public class MyPlantsController implements Initializable {
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
//ToDo uncomment when new FXML exists
Parent root;
FXMLLoader fxmlLoader = new FXMLLoader(Objects.requireNonNull(getClass().getResource("CropDetail.fxml")));
try {
mainController.loadPane("CropDetail.fxml");
root = fxmlLoader.load();
CropDetailController controller = fxmlLoader.getController();
controller.setPlantFromCrop(crop);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(true);
stage.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
@ -86,13 +112,17 @@ public class MyPlantsController implements Initializable {
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
showConfirmation(crop);
try {
showConfirmation(crop);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return event;
}
private void showConfirmation(Crop crop) {
private void showConfirmation(Crop crop) throws IOException {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete Crop");
alert.setHeaderText("Are you sure want to delete this Crop?");
@ -101,7 +131,10 @@ public class MyPlantsController implements Initializable {
Optional<ButtonType> option = alert.showAndWait();
if (option.get() == ButtonType.OK) {
//ToDo Method to remove crop
//ToDo uncomment, when error from JsonTaskDatabase.java loadTaskListFromFile() is fixed.
//gardenplanmodel.removeCrop(crop);
loadCropList();
System.out.println("Delete Crop");
}
}
}

View File

@ -1,5 +1,7 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task;
import javafx.beans.property.ListProperty;
@ -15,6 +17,7 @@ import javafx.scene.control.ListView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.LinkedList;
@ -23,6 +26,8 @@ import java.util.ResourceBundle;
public class MyScheduleController implements Initializable {
private Crop selectedCrop = null;
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
@ -74,16 +79,29 @@ public class MyScheduleController implements Initializable {
@FXML
private ListView<Crop> scheduledPlants_listview;
public MyScheduleController() throws IOException {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
//ToDo method to load crop list
List<Crop> cropList = new LinkedList<>();
List<Crop> cropList;
try {
cropList = gardenplanmodel.getCrops();
cropListProperty.addAll(cropList);
} catch (IOException e) {
e.printStackTrace();
}
setCellFactoryListView();
scheduledPlants_listview.itemsProperty().bind(cropListProperty);
lookForSelectedListEntries();
setDayLabels();
information_label.setText("");
loadTaskList();
try {
loadTaskList();
} catch (IOException e) {
e.printStackTrace();
}
}
private void lookForSelectedListEntries() {
@ -91,7 +109,11 @@ public class MyScheduleController implements Initializable {
@Override
public void changed(ObservableValue<? extends Crop> observable, Crop oldValue, Crop newValue) {
selectedCrop = newValue;
loadTaskList();
try {
loadTaskList();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
@ -122,13 +144,13 @@ public class MyScheduleController implements Initializable {
});
}
private void loadTaskList() {
//ToDo load task list according to selectedCrop
private void loadTaskList() throws IOException {
List<List<Task>> taskLists = new LinkedList<>();
//ToDo uncomment, when error from JsonTaskDatabase.java loadTaskListFromFile() is fixed.
if (selectedCrop != null) {
//taskLists = taskListModel.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
} else {
//taskLists = taskListModel.getTasksUpcomingWeek();
}
if (!taskLists.isEmpty()) {
viewTaskListOfDay(day1_pane, taskLists.get(0));

View File

@ -1,5 +1,9 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.taskList.PlantNotFoundException;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
import ch.zhaw.gartenverwaltung.types.Plant;
import javafx.beans.value.ChangeListener;
@ -11,6 +15,7 @@ import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.util.Callback;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.List;
@ -18,6 +23,8 @@ import java.util.ResourceBundle;
public class SelectSowDayController implements Initializable {
private Plant selectedPlant = null;
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
@FXML
private DatePicker datepicker;
@ -31,6 +38,8 @@ public class SelectSowDayController implements Initializable {
@FXML
private RadioButton sow_radio;
public SelectSowDayController() throws IOException {}
/**
* close the date selector window
* @param event event
@ -46,8 +55,7 @@ public class SelectSowDayController implements Initializable {
* @param event event
*/
@FXML
void save(ActionEvent event) {
//ToDo save plant and sow date to crop/gardenplan model
void save(ActionEvent event) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
LocalDate sowDate;
if (sow_radio.isSelected()) {
sowDate = datepicker.getValue();
@ -55,8 +63,8 @@ public class SelectSowDayController implements Initializable {
//ToDo method to get current lifecycle group in plant
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
}
System.out.println(sowDate);
System.out.println(selectedPlant);
//ToDo uncomment, when error from JsonTaskDatabase.java loadTaskListFromFile() is fixed.
//gardenplanmodel.plantAsCrop(selectedPlant, sowDate);
closeWindow();
}

View File

@ -1,10 +1,7 @@
package ch.zhaw.gartenverwaltung.taskList;
import ch.zhaw.gartenverwaltung.Config;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase;
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
import ch.zhaw.gartenverwaltung.io.TaskDatabase;
import ch.zhaw.gartenverwaltung.io.*;
import ch.zhaw.gartenverwaltung.types.*;
import java.io.IOException;
@ -26,6 +23,7 @@ public class TaskListModel {
public TaskListModel(){
taskDatabase = new JsonTaskDatabase();
plantDatabase = new JsonPlantDatabase();
}
/**

View File

@ -85,7 +85,7 @@
<Insets bottom="10.0" />
</VBox.margin>
</Label>
<VBox fx:id="growthPahses_vbox" prefHeight="135.0" prefWidth="879.0">
<VBox fx:id="growthPhases_vbox" prefHeight="135.0" prefWidth="879.0">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
@ -126,7 +126,7 @@
<Insets right="40.0" />
</HBox.margin>
</Label>
<Label fx:id="lacation_label" text="Label">
<Label fx:id="location_label" text="Label">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>