display List of Crops, get detail of crop and display taskList

This commit is contained in:
giavaphi 2022-11-10 22:50:49 +01:00
parent 0e40bc6304
commit 8e23124c6b
7 changed files with 115 additions and 34 deletions

View File

@ -1,16 +1,34 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Pest;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.List;
public class CropDetailController {
private Crop crop = null;
private Plant plant = null;
private final PlantListModel plantListModel = new PlantListModel();
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
@FXML
private ImageView imageView;
@FXML
private Button area_button;
@ -45,6 +63,9 @@ public class CropDetailController {
@FXML
private Label spacing_label;
public CropDetailController() throws IOException {
}
@FXML
void editTaskList(ActionEvent event) {
@ -52,7 +73,8 @@ public class CropDetailController {
@FXML
void goBack(ActionEvent event) {
Stage stage = (Stage) imageView.getScene().getWindow();
stage.close();
}
@FXML
@ -65,8 +87,46 @@ public class CropDetailController {
}
public void setPlantFromCrop(Crop crop) {
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
this.crop = crop;
this.plant = null;
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
cropName_label.setText(plant.name());
description_label.setText(plant.description());
light_label.setText(String.valueOf(plant.light()));
soil_label.setText(plant.soil());
spacing_label.setText(plant.spacing());
if (plant.image() != null) {
imageView.setImage(plant.image());
}
area_label.setText("");
location_label.setText("");
createTaskLists(crop);
createPestList(plant);
}
private void createTaskLists(Crop crop) throws IOException {
List<Task> taskList = taskListModel.getTaskListForCrop(crop.getCropId().get());
for (Task task : taskList) {
Label label = new Label(task.getDescription());
growthPhases_vbox.getChildren().add(label);
}
}
private void createPestList(Plant plant) {
List<Pest> pests = plant.pests();
for (Pest pest : pests) {
Label label = new Label(pest.name() + ":");
label.setStyle("-fx-font-weight: bold");
HBox hBox = new HBox();
hBox.fillHeightProperty();
Label label1 = new Label(pest.description());
label1.setAlignment(Pos.TOP_LEFT);
label1.setWrapText(true);
label1.setMaxWidth(600);
label1.setMaxHeight(100);
Button button = new Button("Get Counter Measures");
hBox.getChildren().addAll(label1, button);
pests_vbox.getChildren().addAll(label, hBox);
}
}
}

View File

@ -1,8 +1,11 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Plant;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
@ -14,7 +17,9 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
@ -27,6 +32,7 @@ public class MyPlantsController implements Initializable {
MainFXMLController mainController;
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
private final PlantListModel plantListModel = new PlantListModel();
@FXML
private VBox myPlants_vbox;
@ -41,10 +47,15 @@ public class MyPlantsController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
loadCropList();
//ToDo update, when new crops are added
try {
loadCropList();
} catch (HardinessZoneNotSetException | IOException e) {
e.printStackTrace();
}
}
private void loadCropList() {
private void loadCropList() throws HardinessZoneNotSetException, IOException {
List<Crop> cropList = new LinkedList<>();
try {
cropList = getCropList();
@ -54,7 +65,7 @@ public class MyPlantsController implements Initializable {
createPlantView(cropList);
}
private void createPlantView(List<Crop> crops) {
private void createPlantView(List<Crop> crops) throws HardinessZoneNotSetException, IOException {
myPlants_vbox.getChildren().clear();
for(Crop crop : crops) {
HBox hBox = createPlantView(crop);
@ -72,16 +83,27 @@ public class MyPlantsController implements Initializable {
return cropList;
}
private HBox createPlantView(Crop crop) {
//ToDo add good design
//ToDo get plant information from crop
HBox hBox = new HBox();
Label label = new Label("Placeholder");
private HBox createPlantView(Crop crop) throws HardinessZoneNotSetException, IOException {
//ToDo add better design
Plant plant = plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0);
HBox hBox = new HBox(10);
ImageView imageView = new ImageView();
imageView.setPreserveRatio(false);
imageView.setFitHeight(100);
imageView.setFitWidth(100);
imageView.maxHeight(100);
if (plant.image() != null) {
imageView.setImage(plant.image());
}
hBox.setMinHeight(100);
Label label = new Label(plant.name());
label.setMaxWidth(2000);
HBox.setHgrow(label, Priority.ALWAYS);
Button details = new Button("Details");
Button delete = new Button("delete");
details.setOnAction(getGoToCropDetailEvent(crop));
delete.setOnAction(getDeleteCropEvent(crop));
hBox.getChildren().addAll(label, details, delete);
hBox.getChildren().addAll(imageView, label, details, delete);
return hBox;
}
@ -100,7 +122,7 @@ public class MyPlantsController implements Initializable {
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(true);
stage.showAndWait();
} catch (IOException e) {
} catch (IOException | HardinessZoneNotSetException e) {
e.printStackTrace();
}
}
@ -114,7 +136,7 @@ public class MyPlantsController implements Initializable {
public void handle(ActionEvent event) {
try {
showConfirmation(crop);
} catch (IOException e) {
} catch (IOException | HardinessZoneNotSetException e) {
e.printStackTrace();
}
}
@ -122,7 +144,7 @@ public class MyPlantsController implements Initializable {
return event;
}
private void showConfirmation(Crop crop) throws IOException {
private void showConfirmation(Crop crop) throws IOException, HardinessZoneNotSetException {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete Crop");
alert.setHeaderText("Are you sure want to delete this Crop?");
@ -131,10 +153,8 @@ public class MyPlantsController implements Initializable {
Optional<ButtonType> option = alert.showAndWait();
if (option.get() == ButtonType.OK) {
//ToDo uncomment, when error from JsonTaskDatabase.java loadTaskListFromFile() is fixed.
//gardenplanmodel.removeCrop(crop);
gardenplanmodel.removeCrop(crop);
loadCropList();
System.out.println("Delete Crop");
}
}
}

View File

@ -1,6 +1,8 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.gardenplan.Gardenplanmodel;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
import ch.zhaw.gartenverwaltung.taskList.TaskListModel;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task;
@ -28,6 +30,7 @@ public class MyScheduleController implements Initializable {
private Crop selectedCrop = null;
private final TaskListModel taskListModel = new TaskListModel();
private final Gardenplanmodel gardenplanmodel = new Gardenplanmodel(taskListModel);
private final PlantListModel plantListModel = new PlantListModel();
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
@ -84,7 +87,6 @@ public class MyScheduleController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
//ToDo method to load crop list
List<Crop> cropList;
try {
cropList = gardenplanmodel.getCrops();
@ -138,7 +140,11 @@ public class MyScheduleController implements Initializable {
if (empty || crop == null) {
setText(null);
} else {
setText("placeholder");
try {
setText(plantListModel.getFilteredPlantListById(Config.getCurrentHardinessZone(), crop.getPlantId()).get(0).name());
} catch (HardinessZoneNotSetException | IOException e) {
e.printStackTrace();
}
}
}
});
@ -146,11 +152,10 @@ public class MyScheduleController implements Initializable {
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());
taskLists = taskListModel.getTasksUpcomingWeekForCrop(selectedCrop.getCropId().get());
} else {
//taskLists = taskListModel.getTasksUpcomingWeek();
taskLists = taskListModel.getTasksUpcomingWeek();
}
if (!taskLists.isEmpty()) {
viewTaskListOfDay(day1_pane, taskLists.get(0));
@ -167,7 +172,7 @@ public class MyScheduleController implements Initializable {
//ToDo update pane with task list
VBox vBox = new VBox();
for (Task task : tasks) {
Label label = new Label("placeholder");
Label label = new Label(task.getDescription());
vBox.getChildren().add(label);
}
pane.getChildren().add(vBox);

View File

@ -63,8 +63,7 @@ public class SelectSowDayController implements Initializable {
//ToDo method to get current lifecycle group in plant
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
}
//ToDo uncomment, when error from JsonTaskDatabase.java loadTaskListFromFile() is fixed.
//gardenplanmodel.plantAsCrop(selectedPlant, sowDate);
gardenplanmodel.plantAsCrop(selectedPlant, sowDate);
closeWindow();
}

View File

@ -21,11 +21,10 @@ public class Task {
* default constructor
* (used by Json deserializer)
*/
public Task(long cropId){
public Task(){
name= "";
description= "";
startDate = LocalDate.now();
this.cropId = cropId;
}
public Task(String name, String description, LocalDate startDate, long cropId) {

View File

@ -77,7 +77,7 @@
</Label>
</children>
</GridPane>
<ImageView fitHeight="300.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true" HBox.hgrow="NEVER" />
<ImageView fx:id="imageView" fitHeight="300.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true" HBox.hgrow="NEVER" />
</children>
</HBox>
<Label text="Growth Phases:">

View File

@ -7,9 +7,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="655.0" prefWidth="1175.0" xmlns="http://javafx.com/javafx/17"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.MyPlantsController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="655.0" prefWidth="1175.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.MyPlantsController">
<children>
<VBox layoutY="49.0" prefHeight="655.0" prefWidth="1175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@ -21,7 +19,7 @@
<Insets bottom="10.0" />
</VBox.margin>
</Label>
<VBox fx:id="myPlants_vbox" prefHeight="200.0" prefWidth="100.0" VBox.vgrow="ALWAYS" />
<VBox fx:id="myPlants_vbox" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="100.0" VBox.vgrow="ALWAYS" />
<Button fx:id="addPlant_button" mnemonicParsing="false" onAction="#addPlant" prefHeight="45.0" prefWidth="155.0" text="Add new Plant">
<VBox.margin>
<Insets top="10.0" />