refactor: first attempt at dependency injection
also some more renaming and improving date-picker dialog
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Pest;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
@@ -20,13 +21,23 @@ import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class CropDetailController {
|
||||
private Crop crop = null;
|
||||
private final PlantListModel plantListModel = new PlantListModel();
|
||||
private final GardenSchedule gardenSchedule = new GardenSchedule();
|
||||
private final Garden garden = new Garden(gardenSchedule);
|
||||
private Crop crop;
|
||||
private PlantList plantList;
|
||||
private GardenSchedule gardenSchedule;
|
||||
private Garden garden;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName());
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void injectDependencies(Garden garden, PlantList plantList, GardenSchedule gardenSchedule) {
|
||||
this.garden = garden;
|
||||
this.plantList = plantList;
|
||||
this.gardenSchedule = gardenSchedule;
|
||||
}
|
||||
@FXML
|
||||
private ImageView imageView;
|
||||
|
||||
@@ -63,9 +74,6 @@ public class CropDetailController {
|
||||
@FXML
|
||||
private Label spacing_label;
|
||||
|
||||
public CropDetailController() throws IOException {
|
||||
}
|
||||
|
||||
@FXML
|
||||
void editTaskList(ActionEvent event) {
|
||||
|
||||
@@ -87,9 +95,11 @@ public class CropDetailController {
|
||||
|
||||
}
|
||||
|
||||
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
|
||||
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
||||
this.crop = crop;
|
||||
Plant plant = plantListModel.getFilteredPlantListById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(0);
|
||||
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId())
|
||||
.orElseThrow(PlantNotFoundException::new);
|
||||
|
||||
cropName_label.setText(plant.name());
|
||||
description_label.setText(plant.description());
|
||||
light_label.setText(String.valueOf(plant.light()));
|
||||
@@ -104,12 +114,20 @@ public class CropDetailController {
|
||||
createPestList(plant);
|
||||
}
|
||||
|
||||
private void createTaskLists(Crop crop) throws IOException {
|
||||
List<Task> taskList = gardenSchedule.getTaskListForCrop(crop.getCropId().get());
|
||||
for (Task task : taskList) {
|
||||
Label label = new Label(task.getDescription());
|
||||
growthPhases_vbox.getChildren().add(label);
|
||||
}
|
||||
private void createTaskLists(Crop crop) {
|
||||
crop.getCropId().ifPresent(id -> {
|
||||
List<Task> taskList;
|
||||
try {
|
||||
taskList = gardenSchedule.getTaskListForCrop(id);
|
||||
for (Task task : taskList) {
|
||||
Label label = new Label(task.getDescription());
|
||||
growthPhases_vbox.getChildren().add(label);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO: Alert
|
||||
LOG.log(Level.SEVERE, "Could not get task list for crop", e.getCause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createPestList(Plant plant) {
|
||||
|
||||
Reference in New Issue
Block a user