refactor: first attempt at dependency injection
also some more renaming and improving date-picker dialog
This commit is contained in:
@@ -2,12 +2,12 @@ package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.CropList;
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonCropList;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
@@ -19,21 +19,25 @@ import java.util.Optional;
|
||||
* The Gardenplan model manages the crops in the gardenplan.
|
||||
*/
|
||||
public class Garden {
|
||||
private CropList cropList;
|
||||
private final ObservableList<Crop> plantedCrops = FXCollections.observableArrayList();
|
||||
private GardenSchedule gardenSchedule;
|
||||
private final CropList cropList;
|
||||
private final ListProperty<Crop> plantedCrops = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||
private final GardenSchedule gardenSchedule;
|
||||
|
||||
/**
|
||||
* Constructor of Gardenplan model
|
||||
*
|
||||
* @param gardenSchedule holds a reference to the task list object.
|
||||
*/
|
||||
public Garden(GardenSchedule gardenSchedule) throws IOException {
|
||||
public Garden(GardenSchedule gardenSchedule, CropList cropList) throws IOException {
|
||||
this.gardenSchedule = gardenSchedule;
|
||||
cropList = new JsonCropList();
|
||||
this.cropList = cropList;
|
||||
plantedCrops.addAll(cropList.getCrops());
|
||||
}
|
||||
|
||||
public ListProperty<Crop> getPlantedCrops() {
|
||||
return plantedCrops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Crop with a {@link Plant} and the planting date of the plant. Then let the Tasklistmodel create the
|
||||
* gardening {@link Task} for the crop. Store the crop in the gardenplan file and the cache.
|
||||
|
||||
@@ -12,19 +12,14 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GardenSchedule {
|
||||
private TaskList taskList;
|
||||
private PlantList plantList;
|
||||
private final TaskList taskList;
|
||||
private final PlantList plantList;
|
||||
|
||||
/**
|
||||
* Comparators to create sorted Task List
|
||||
*/
|
||||
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
|
||||
|
||||
public GardenSchedule(){
|
||||
taskList = new JsonTaskList();
|
||||
plantList = new JsonPlantList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create Database Objects.
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ch.zhaw.gartenverwaltung.models;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
@@ -16,7 +15,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlantListModel {
|
||||
private PlantList plantList;
|
||||
private final PlantList plantList;
|
||||
private HardinessZone currentZone;
|
||||
|
||||
/**
|
||||
@@ -28,11 +27,6 @@ public class PlantListModel {
|
||||
/**
|
||||
* Constructor to create Database Object.
|
||||
*/
|
||||
public PlantListModel() {
|
||||
plantList = new JsonPlantList();
|
||||
setDefaultZone();
|
||||
}
|
||||
|
||||
public PlantListModel(PlantList plantList) {
|
||||
this.plantList = plantList;
|
||||
setDefaultZone();
|
||||
|
||||
Reference in New Issue
Block a user