Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a69119eb7 | ||
|
|
2f69c48800 | ||
|
|
9ba252b828 | ||
|
|
90d2de65de | ||
|
|
05e7bcc2e8 | ||
|
|
09e582b8a2 | ||
|
|
2b7cec7e6a |
@@ -93,8 +93,9 @@ public class CropDetailController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
public void setPlantFromCrop(Crop crop) throws PlantNotFoundException {
|
||||||
this.crop = crop;
|
this.crop = crop;
|
||||||
|
try {
|
||||||
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId())
|
Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId())
|
||||||
.orElseThrow(PlantNotFoundException::new);
|
.orElseThrow(PlantNotFoundException::new);
|
||||||
|
|
||||||
@@ -110,6 +111,9 @@ public class CropDetailController {
|
|||||||
location_label.setText("");
|
location_label.setText("");
|
||||||
createTaskLists(crop);
|
createTaskLists(crop);
|
||||||
createPestList(plant);
|
createPestList(plant);
|
||||||
|
} catch (HardinessZoneNotSetException | IOException e) {
|
||||||
|
throw new PlantNotFoundException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTaskLists(Crop crop) {
|
private void createTaskLists(Crop crop) {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -10,10 +9,11 @@ import java.io.IOException;
|
|||||||
public class HelloApplication extends Application {
|
public class HelloApplication extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("MainFXML.fxml"));
|
AppLoader appLoader = new AppLoader();
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
|
||||||
|
appLoader.loadSceneToStage("MainFXML.fxml", stage);
|
||||||
|
|
||||||
stage.setTitle("Gartenverwaltung");
|
stage.setTitle("Gartenverwaltung");
|
||||||
stage.setScene(scene);
|
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.ChangeViewEvent;
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class MainFXMLController implements Initializable {
|
public class MainFXMLController {
|
||||||
private static final Logger LOG = Logger.getLogger(MainFXMLController.class.getName());
|
private static final Logger LOG = Logger.getLogger(MainFXMLController.class.getName());
|
||||||
private final AppLoader appLoader = new AppLoader(this);
|
|
||||||
|
@Inject
|
||||||
|
AppLoader appLoader;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button home_button;
|
private Button home_button;
|
||||||
|
|
||||||
@@ -31,29 +35,26 @@ public class MainFXMLController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button plants_button;
|
private Button plants_button;
|
||||||
|
|
||||||
public MainFXMLController() throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void goToHome() throws IOException {
|
void goToHome() {
|
||||||
showPaneAsMainView("Home.fxml");
|
showPaneAsMainView("Home.fxml");
|
||||||
styleChangeButton(home_button);
|
styleChangeButton(home_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void goToMyPlants() throws IOException {
|
void goToMyPlants() {
|
||||||
showPaneAsMainView("MyGarden.fxml");
|
showPaneAsMainView("MyGarden.fxml");
|
||||||
styleChangeButton(myGarden_button);
|
styleChangeButton(myGarden_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void goToMySchedule() throws IOException {
|
void goToMySchedule() {
|
||||||
showPaneAsMainView("MySchedule.fxml");
|
showPaneAsMainView("MySchedule.fxml");
|
||||||
styleChangeButton(mySchedule_button);
|
styleChangeButton(mySchedule_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void goToPlants() throws IOException {
|
void goToPlants() {
|
||||||
showPaneAsMainView("Plants.fxml");
|
showPaneAsMainView("Plants.fxml");
|
||||||
styleChangeButton(plants_button);
|
styleChangeButton(plants_button);
|
||||||
}
|
}
|
||||||
@@ -63,15 +64,22 @@ public class MainFXMLController implements Initializable {
|
|||||||
* set HGrow and VGrow to parent AnchorPane.
|
* set HGrow and VGrow to parent AnchorPane.
|
||||||
* Sends MainController to other Controllers.
|
* Sends MainController to other Controllers.
|
||||||
* @param fxmlFile string of fxml file
|
* @param fxmlFile string of fxml file
|
||||||
* @throws IOException exception when file does not exist
|
|
||||||
*/
|
*/
|
||||||
public void showPaneAsMainView(String fxmlFile) throws IOException {
|
public void showPaneAsMainView(String fxmlFile) {
|
||||||
|
try {
|
||||||
Pane anchorPane = appLoader.loadPane(fxmlFile);
|
Pane anchorPane = appLoader.loadPane(fxmlFile);
|
||||||
mainPane.getChildren().setAll(anchorPane);
|
mainPane.getChildren().setAll(anchorPane);
|
||||||
anchorPane.prefWidthProperty().bind(mainPane.widthProperty());
|
anchorPane.prefWidthProperty().bind(mainPane.widthProperty());
|
||||||
anchorPane.prefHeightProperty().bind(mainPane.heightProperty());
|
anchorPane.prefHeightProperty().bind(mainPane.heightProperty());
|
||||||
|
|
||||||
|
anchorPane.removeEventHandler(ChangeViewEvent.CHANGE_MAIN_VIEW, changeMainViewHandler);
|
||||||
|
anchorPane.addEventHandler(ChangeViewEvent.CHANGE_MAIN_VIEW, changeMainViewHandler);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.log(Level.SEVERE, "Could not load pane.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final EventHandler<ChangeViewEvent> changeMainViewHandler = (ChangeViewEvent event) -> showPaneAsMainView(event.view());
|
||||||
|
|
||||||
private void preloadPanes() throws IOException {
|
private void preloadPanes() throws IOException {
|
||||||
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
||||||
@@ -87,8 +95,9 @@ public class MainFXMLController implements Initializable {
|
|||||||
* loads the default FXML File
|
* loads the default FXML File
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@AfterInject
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
@SuppressWarnings("unused")
|
||||||
|
public void init() {
|
||||||
try {
|
try {
|
||||||
preloadPanes();
|
preloadPanes();
|
||||||
showPaneAsMainView("Home.fxml");
|
showPaneAsMainView("Home.fxml");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ch.zhaw.gartenverwaltung;
|
|||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.ChangeViewEvent;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||||
import ch.zhaw.gartenverwaltung.io.PlantList;
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
@@ -17,6 +18,7 @@ import javafx.scene.control.Button;
|
|||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
@@ -30,16 +32,15 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
public class MyGardenController {
|
public class MyGardenController {
|
||||||
private static final Logger LOG = Logger.getLogger(MyGardenController.class.getName());
|
private static final Logger LOG = Logger.getLogger(MyGardenController.class.getName());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AppLoader appLoader;
|
AppLoader appLoader;
|
||||||
@Inject
|
@Inject
|
||||||
MainFXMLController mainController;
|
|
||||||
@Inject
|
|
||||||
private Garden garden;
|
private Garden garden;
|
||||||
@Inject
|
@Inject
|
||||||
private PlantList plantList;
|
private PlantList plantList;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public AnchorPane myGardenRoot;
|
||||||
@FXML
|
@FXML
|
||||||
private VBox myPlants_vbox;
|
private VBox myPlants_vbox;
|
||||||
|
|
||||||
@@ -61,8 +62,8 @@ public class MyGardenController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void addPlant(ActionEvent event) throws IOException {
|
void addPlant() {
|
||||||
mainController.showPaneAsMainView("Plants.fxml");
|
myGardenRoot.fireEvent(new ChangeViewEvent(ChangeViewEvent.CHANGE_MAIN_VIEW, "Plants.fxml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPlantView(List<Crop> crops) throws HardinessZoneNotSetException, IOException {
|
private void createPlantView(List<Crop> crops) throws HardinessZoneNotSetException, IOException {
|
||||||
@@ -89,10 +90,12 @@ public class MyGardenController {
|
|||||||
Label label = new Label(plant.name());
|
Label label = new Label(plant.name());
|
||||||
label.setMaxWidth(2000);
|
label.setMaxWidth(2000);
|
||||||
HBox.setHgrow(label, Priority.ALWAYS);
|
HBox.setHgrow(label, Priority.ALWAYS);
|
||||||
|
|
||||||
Button details = new Button("Details");
|
Button details = new Button("Details");
|
||||||
Button delete = new Button("delete");
|
Button delete = new Button("delete");
|
||||||
details.setOnAction(getGoToCropDetailEvent(crop));
|
details.setOnAction(getGoToCropDetailEvent(crop));
|
||||||
delete.setOnAction(getDeleteCropEvent(crop));
|
delete.setOnAction(getDeleteCropEvent(crop));
|
||||||
|
|
||||||
hBox.getChildren().addAll(imageView, label, details, delete);
|
hBox.getChildren().addAll(imageView, label, details, delete);
|
||||||
return hBox;
|
return hBox;
|
||||||
}
|
}
|
||||||
@@ -107,7 +110,7 @@ public class MyGardenController {
|
|||||||
stage.initModality(Modality.APPLICATION_MODAL);
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
stage.setResizable(true);
|
stage.setResizable(true);
|
||||||
stage.showAndWait();
|
stage.showAndWait();
|
||||||
} catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) {
|
} catch (IOException | PlantNotFoundException e) {
|
||||||
// TODO: show error alert
|
// TODO: show error alert
|
||||||
LOG.log(Level.SEVERE, "Could not load plant details.", e);
|
LOG.log(Level.SEVERE, "Could not load plant details.", e);
|
||||||
}
|
}
|
||||||
@@ -128,7 +131,7 @@ public class MyGardenController {
|
|||||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
alert.setTitle("Delete Crop");
|
alert.setTitle("Delete Crop");
|
||||||
alert.setHeaderText("Are you sure want to delete this Crop?");
|
alert.setHeaderText("Are you sure want to delete this Crop?");
|
||||||
alert.setContentText("placeholder");
|
alert.setContentText("Deleting this crop will remove all associated tasks from your schedule.");
|
||||||
|
|
||||||
alert.showAndWait()
|
alert.showAndWait()
|
||||||
.ifPresent(buttonType -> {
|
.ifPresent(buttonType -> {
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|||||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Task;
|
import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import javafx.beans.property.ListProperty;
|
|
||||||
import javafx.beans.property.SimpleListProperty;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
@@ -37,8 +34,6 @@ public class MyScheduleController {
|
|||||||
@Inject
|
@Inject
|
||||||
private PlantList plantList;
|
private PlantList plantList;
|
||||||
|
|
||||||
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label day1_label;
|
private Label day1_label;
|
||||||
|
|
||||||
@@ -90,15 +85,8 @@ public class MyScheduleController {
|
|||||||
@AfterInject
|
@AfterInject
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void init() {
|
public void init() {
|
||||||
List<Crop> cropList;
|
|
||||||
try {
|
|
||||||
cropList = garden.getCrops();
|
|
||||||
cropListProperty.addAll(cropList);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
setCellFactoryListView();
|
setCellFactoryListView();
|
||||||
scheduledPlants_listview.itemsProperty().bind(cropListProperty);
|
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
|
||||||
lookForSelectedListEntries();
|
lookForSelectedListEntries();
|
||||||
setDayLabels();
|
setDayLabels();
|
||||||
information_label.setText("");
|
information_label.setText("");
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package ch.zhaw.gartenverwaltung;
|
|||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
||||||
|
import ch.zhaw.gartenverwaltung.bootstrap.ChangeViewEvent;
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||||
|
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Seasons;
|
import ch.zhaw.gartenverwaltung.types.Seasons;
|
||||||
@@ -16,11 +19,11 @@ import javafx.geometry.Insets;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Modality;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -32,6 +35,8 @@ public class PlantsController {
|
|||||||
private PlantListModel plantListModel;
|
private PlantListModel plantListModel;
|
||||||
@Inject
|
@Inject
|
||||||
private AppLoader appLoader;
|
private AppLoader appLoader;
|
||||||
|
@Inject
|
||||||
|
private Garden garden;
|
||||||
|
|
||||||
private Plant selectedPlant = null;
|
private Plant selectedPlant = null;
|
||||||
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
|
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
|
||||||
@@ -39,6 +44,9 @@ public class PlantsController {
|
|||||||
// TODO: move to model
|
// TODO: move to model
|
||||||
private final ListProperty<Plant> plantListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
private final ListProperty<Plant> plantListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public AnchorPane plantsRoot;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private VBox seasons;
|
private VBox seasons;
|
||||||
|
|
||||||
@@ -65,14 +73,31 @@ public class PlantsController {
|
|||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void selectSowDate() throws IOException {
|
void selectSowDate() throws IOException {
|
||||||
Stage stage = new Stage();
|
Dialog<LocalDate> dateSelection = new Dialog<>();
|
||||||
if (appLoader.loadSceneToStage("SelectSowDay.fxml", stage) instanceof SelectSowDayController controller) {
|
dateSelection.setTitle("Select Date");
|
||||||
controller.setSelectedPlant(selectedPlant);
|
dateSelection.setHeaderText(String.format("Select Harvest/Sow Date for %s:", selectedPlant.name()));
|
||||||
}
|
dateSelection.setResizable(false);
|
||||||
|
|
||||||
stage.initModality(Modality.APPLICATION_MODAL);
|
DialogPane dialogPane = dateSelection.getDialogPane();
|
||||||
stage.setResizable(false);
|
|
||||||
stage.showAndWait();
|
ButtonType sowButton = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE);
|
||||||
|
dialogPane.getButtonTypes().addAll(sowButton, ButtonType.CANCEL);
|
||||||
|
|
||||||
|
if (appLoader.loadPaneToDialog("SelectSowDay.fxml", dialogPane) instanceof SelectSowDayController controller) {
|
||||||
|
controller.initSaveButton((Button) dialogPane.lookupButton(sowButton));
|
||||||
|
controller.setSelectedPlant(selectedPlant);
|
||||||
|
dateSelection.setResultConverter(button -> button.equals(sowButton) ? controller.retrieveResult() : null);
|
||||||
|
|
||||||
|
dateSelection.showAndWait()
|
||||||
|
.ifPresent(date -> {
|
||||||
|
try {
|
||||||
|
garden.plantAsCrop(selectedPlant, date);
|
||||||
|
} catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) {
|
||||||
|
LOG.log(Level.SEVERE, "Couldn't save Crop", e);
|
||||||
|
}
|
||||||
|
plantsRoot.fireEvent(new ChangeViewEvent(ChangeViewEvent.CHANGE_MAIN_VIEW, "MyGarden.fxml"));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +151,7 @@ public class PlantsController {
|
|||||||
/**
|
/**
|
||||||
* get plant list according to param season and hardiness zone
|
* get plant list according to param season and hardiness zone
|
||||||
* fill list view with plant list
|
* fill list view with plant list
|
||||||
|
*
|
||||||
* @param season enum of seasons
|
* @param season enum of seasons
|
||||||
* @throws HardinessZoneNotSetException throws exception
|
* @throws HardinessZoneNotSetException throws exception
|
||||||
* @throws IOException throws exception
|
* @throws IOException throws exception
|
||||||
@@ -138,6 +164,7 @@ public class PlantsController {
|
|||||||
/**
|
/**
|
||||||
* get plant list filtered by search plant entry and hardiness zone
|
* get plant list filtered by search plant entry and hardiness zone
|
||||||
* fill list view with plant list
|
* fill list view with plant list
|
||||||
|
*
|
||||||
* @throws HardinessZoneNotSetException throws exception when no hardiness zone is defined
|
* @throws HardinessZoneNotSetException throws exception when no hardiness zone is defined
|
||||||
* @throws IOException throws exception
|
* @throws IOException throws exception
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,88 +1,60 @@
|
|||||||
package ch.zhaw.gartenverwaltung;
|
package ch.zhaw.gartenverwaltung;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
|
||||||
import ch.zhaw.gartenverwaltung.models.Garden;
|
|
||||||
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
|
||||||
import ch.zhaw.gartenverwaltung.models.PlantNotFoundException;
|
|
||||||
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.stage.Stage;
|
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
public class SelectSowDayController implements Initializable {
|
public class SelectSowDayController {
|
||||||
private Plant selectedPlant = null;
|
private Plant selectedPlant;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private Garden garden;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private DatePicker datepicker;
|
private DatePicker datepicker;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Label popup_label;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Button save_button;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private RadioButton harvest_radio;
|
private RadioButton harvest_radio;
|
||||||
|
|
||||||
/**
|
|
||||||
* close the date selector window
|
|
||||||
*/
|
|
||||||
@FXML
|
@FXML
|
||||||
void cancel() {
|
private RadioButton sow_radio;
|
||||||
closeWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get sow date from datePicker or calculate sow date from harvest date
|
|
||||||
* save selected plant and sow date
|
|
||||||
*/
|
|
||||||
@FXML
|
@FXML
|
||||||
void save() throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
public ToggleGroup phase_group;
|
||||||
|
|
||||||
|
public LocalDate retrieveResult() {
|
||||||
LocalDate sowDate = datepicker.getValue();
|
LocalDate sowDate = datepicker.getValue();
|
||||||
if (harvest_radio.isSelected()) {
|
if (harvest_radio.isSelected()) {
|
||||||
//ToDo method to get current lifecycle group in plant
|
sowDate = selectedPlant.sowDateFromHarvestDate(sowDate);
|
||||||
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
|
||||||
}
|
}
|
||||||
garden.plantAsCrop(selectedPlant, sowDate);
|
return sowDate;
|
||||||
closeWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save the plant which will be planted and update label
|
* Set the {@link Plant} for which a date should be selected.
|
||||||
|
*
|
||||||
* @param plant Plant
|
* @param plant Plant
|
||||||
*/
|
*/
|
||||||
public void setSelectedPlant(Plant plant) {
|
public void setSelectedPlant(Plant plant) {
|
||||||
selectedPlant = plant;
|
selectedPlant = plant;
|
||||||
popup_label.setText(String.format("Select Harvest/Sow Date for %s:", selectedPlant.name()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add listener and set default values
|
* add listener and set default values
|
||||||
* {@inheritDoc}
|
|
||||||
* @param location location
|
|
||||||
* @param resources resources
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@FXML
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize() {
|
||||||
clearDatePickerEntries();
|
clearDatePickerEntries();
|
||||||
|
|
||||||
Callback<DatePicker, DateCell> dayCellFactory = getDayCellFactory();
|
Callback<DatePicker, DateCell> dayCellFactory = getDayCellFactory();
|
||||||
datepicker.setDayCellFactory(dayCellFactory);
|
datepicker.setDayCellFactory(dayCellFactory);
|
||||||
datepicker.setEditable(false);
|
datepicker.setEditable(false);
|
||||||
|
|
||||||
save_button.disableProperty().bind(datepicker.valueProperty().isNull());
|
sow_radio.setUserData(GrowthPhaseType.SOW);
|
||||||
|
harvest_radio.setUserData(GrowthPhaseType.HARVEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initSaveButton(Button saveButton) {
|
||||||
|
saveButton.disableProperty().bind(datepicker.valueProperty().isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,44 +66,29 @@ public class SelectSowDayController implements Initializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* date picker disable/enable dates according to selected plant: sow or harvest day
|
* date picker disable/enable dates according to selected plant: sow or harvest day
|
||||||
|
*
|
||||||
* @return cellFactory of datePicker
|
* @return cellFactory of datePicker
|
||||||
*/
|
*/
|
||||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
||||||
|
|
||||||
return (datePicker) -> new DateCell() {
|
return (datePicker) -> new DateCell() {
|
||||||
|
private final LocalDate today = LocalDate.now();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateItem(LocalDate item, boolean empty) {
|
public void updateItem(LocalDate item, boolean empty) {
|
||||||
super.updateItem(item, empty);
|
super.updateItem(item, empty);
|
||||||
setDisable(true);
|
setDisable(true);
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
setStyle("-fx-background-color: #ffc0cb;");
|
||||||
List<LocalDate> dates;
|
|
||||||
LocalDate today = LocalDate.now();
|
if (item.compareTo(today) > 0 && (!harvest_radio.isSelected() || selectedPlant.sowDateFromHarvestDate(item).compareTo(today) >= 0)) {
|
||||||
if (harvest_radio.isSelected()) {
|
GrowthPhaseType selectedPhase = (GrowthPhaseType) phase_group.getSelectedToggle().getUserData();
|
||||||
dates = selectedPlant.getDateListOfGrowthPhase(GrowthPhaseType.HARVEST);
|
|
||||||
} else {
|
if (selectedPlant.isDateInPhase(item, selectedPhase)) {
|
||||||
dates = selectedPlant.getDateListOfGrowthPhase(GrowthPhaseType.SOW);
|
|
||||||
}
|
|
||||||
for (LocalDate date : dates) {
|
|
||||||
if (item.getMonth() == date.getMonth()
|
|
||||||
&& item.getDayOfMonth() == date.getDayOfMonth()
|
|
||||||
&& item.compareTo(today) > 0) {
|
|
||||||
setDisable(false);
|
setDisable(false);
|
||||||
setStyle("-fx-background-color: #32CD32;");
|
setStyle("-fx-background-color: #32CD32;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((harvest_radio.isSelected() && selectedPlant.sowDateFromHarvestDate(item, 0).compareTo(today) < 0)) {
|
|
||||||
setDisable(true);
|
|
||||||
setStyle("-fx-background-color: #ffc0cb;");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* close date picker window
|
|
||||||
*/
|
|
||||||
private void closeWindow() {
|
|
||||||
Stage stage = (Stage) save_button.getScene().getWindow();
|
|
||||||
stage.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotates a method to be executed after all dependencies annotates with {@link Inject}
|
||||||
|
* have been injected.
|
||||||
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
public @interface AfterInject { }
|
public @interface AfterInject { }
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ch.zhaw.gartenverwaltung.bootstrap;
|
package ch.zhaw.gartenverwaltung.bootstrap;
|
||||||
|
|
||||||
import ch.zhaw.gartenverwaltung.HelloApplication;
|
import ch.zhaw.gartenverwaltung.HelloApplication;
|
||||||
import ch.zhaw.gartenverwaltung.MainFXMLController;
|
|
||||||
import ch.zhaw.gartenverwaltung.io.CropList;
|
import ch.zhaw.gartenverwaltung.io.CropList;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonCropList;
|
import ch.zhaw.gartenverwaltung.io.JsonCropList;
|
||||||
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
import ch.zhaw.gartenverwaltung.io.JsonPlantList;
|
||||||
@@ -13,7 +12,7 @@ import ch.zhaw.gartenverwaltung.models.GardenSchedule;
|
|||||||
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
import ch.zhaw.gartenverwaltung.models.PlantListModel;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.control.DialogPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
@@ -39,14 +38,19 @@ public class AppLoader {
|
|||||||
|
|
||||||
private final GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
|
private final GardenSchedule gardenSchedule = new GardenSchedule(taskList, plantList);
|
||||||
private final Garden garden = new Garden(gardenSchedule, cropList);
|
private final Garden garden = new Garden(gardenSchedule, cropList);
|
||||||
private final MainFXMLController mainController;
|
|
||||||
|
|
||||||
|
|
||||||
public AppLoader(MainFXMLController mainController) throws IOException {
|
public AppLoader() throws IOException {
|
||||||
this.mainController = mainController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and returns a {@link Pane} (cached).
|
||||||
|
*
|
||||||
|
* @param fxmlFile The file name to be loaded
|
||||||
|
* @return The loaded Pane
|
||||||
|
* @throws IOException if the file could not be loaded
|
||||||
|
*/
|
||||||
public Pane loadPane(String fxmlFile) throws IOException {
|
public Pane loadPane(String fxmlFile) throws IOException {
|
||||||
Pane pane = panes.get(fxmlFile);
|
Pane pane = panes.get(fxmlFile);
|
||||||
if (pane == null) {
|
if (pane == null) {
|
||||||
@@ -56,6 +60,16 @@ public class AppLoader {
|
|||||||
return pane;
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given fxml-file from resources (no caching) and creates a new {@link Scene},
|
||||||
|
* which is then appended to the given {@link Stage}.
|
||||||
|
* Performs dependency-injection.
|
||||||
|
*
|
||||||
|
* @param fxmlFile The file name to be loaded
|
||||||
|
* @param appendee The {@link Stage} to which the new {@link Scene} is appended.
|
||||||
|
* @return The controller of the loaded scene.
|
||||||
|
* @throws IOException if the file could not be loaded
|
||||||
|
*/
|
||||||
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
|
||||||
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
Pane root = loader.load();
|
Pane root = loader.load();
|
||||||
@@ -65,13 +79,45 @@ public class AppLoader {
|
|||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given fxml-file from resources (no caching) and appendeds it's
|
||||||
|
* contents to the given {@link DialogPane}.
|
||||||
|
* Performs dependency-injection.
|
||||||
|
*
|
||||||
|
* @param fxmlFile The file name to be loaded
|
||||||
|
* @param appendee The {@link DialogPane} to which the FXML contents are to be appended.
|
||||||
|
* @return The controller of the loaded scene.
|
||||||
|
* @throws IOException if the file could not be loaded
|
||||||
|
*/
|
||||||
|
public Object loadPaneToDialog(String fxmlFile, DialogPane appendee) throws IOException {
|
||||||
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
|
appendee.setContent(loader.load());
|
||||||
|
Object controller = loader.getController();
|
||||||
|
annotationInject(controller);
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given fxml-file from resources and caches the pane.
|
||||||
|
* Performs dependency-injection.
|
||||||
|
*
|
||||||
|
* @param fxmlFile The file name to be loaded
|
||||||
|
* @throws IOException if the file could not be loaded
|
||||||
|
*/
|
||||||
public void loadAndCacheFxml(String fxmlFile) throws IOException {
|
public void loadAndCacheFxml(String fxmlFile) throws IOException {
|
||||||
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
AnchorPane anchorPane = loader.load();
|
Pane pane = loader.load();
|
||||||
panes.put(fxmlFile, anchorPane);
|
panes.put(fxmlFile, pane);
|
||||||
annotationInject(loader.getController());
|
annotationInject(loader.getController());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the applications dependencies into the given object's fields annotated with {@link Inject}.
|
||||||
|
* Afterwards, all methods on the objects annotated with {@link AfterInject} are executed.
|
||||||
|
* (Success of the injections is not guaranteed!)
|
||||||
|
*
|
||||||
|
* @param controller The class containing the injectable fields
|
||||||
|
*/
|
||||||
public void annotationInject(Object controller) {
|
public void annotationInject(Object controller) {
|
||||||
Arrays.stream(controller.getClass().getDeclaredFields())
|
Arrays.stream(controller.getClass().getDeclaredFields())
|
||||||
.filter(field -> field.isAnnotationPresent(Inject.class))
|
.filter(field -> field.isAnnotationPresent(Inject.class))
|
||||||
@@ -104,7 +150,6 @@ public class AppLoader {
|
|||||||
case "PlantList" -> plantList;
|
case "PlantList" -> plantList;
|
||||||
case "PlantListModel" -> new PlantListModel(plantList);
|
case "PlantListModel" -> new PlantListModel(plantList);
|
||||||
case "GardenSchedule" -> gardenSchedule;
|
case "GardenSchedule" -> gardenSchedule;
|
||||||
case "MainFXMLController" -> mainController;
|
|
||||||
case "AppLoader" -> this;
|
case "AppLoader" -> this;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package ch.zhaw.gartenverwaltung.bootstrap;
|
||||||
|
|
||||||
|
import javafx.event.Event;
|
||||||
|
import javafx.event.EventType;
|
||||||
|
|
||||||
|
public class ChangeViewEvent extends Event {
|
||||||
|
private final String view;
|
||||||
|
|
||||||
|
public static final EventType<ChangeViewEvent> CHANGE_MAIN_VIEW = new EventType<>("CHANGE_MAIN_VIEW");
|
||||||
|
|
||||||
|
public ChangeViewEvent(EventType<? extends Event> eventType, String view) {
|
||||||
|
super(eventType);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String view() {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotates a Field to be injected from the application-dependencies
|
||||||
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
public @interface Inject { }
|
public @interface Inject { }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package ch.zhaw.gartenverwaltung.types;
|
|||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.LinkedList;
|
import java.time.MonthDay;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -42,11 +42,10 @@ public record Plant(
|
|||||||
/**
|
/**
|
||||||
* get sow date from given harvest day from lifecycle group
|
* get sow date from given harvest day from lifecycle group
|
||||||
* @param harvestDate date of the harvest
|
* @param harvestDate date of the harvest
|
||||||
* @param group lifecycle group
|
|
||||||
* @return LocaleDate of sow date
|
* @return LocaleDate of sow date
|
||||||
*/
|
*/
|
||||||
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate, int group) {
|
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate) {
|
||||||
return harvestDate.minusDays(timeToHarvest(group));
|
return harvestDate.minusDays(timeToHarvest(lifecycleGroupFromHarvestDate(harvestDate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,37 +68,43 @@ public record Plant(
|
|||||||
return (int) DAYS.between(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
return (int) DAYS.between(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public int lifecycleGroupFromHarvestDate(LocalDate harvestDate) {
|
||||||
* filter out the given growthPhase out of the lifecycle
|
return lifecycle.stream()
|
||||||
* create list of dates for this growthPhase and return it
|
.filter(growthPhase -> growthPhase.type().equals(GrowthPhaseType.HARVEST) &&
|
||||||
* @param growthPhase the wanted growthPhase
|
dateInRange(harvestDate, growthPhase.startDate(), growthPhase.endDate()))
|
||||||
* @return a list of dates of the current year
|
.map(GrowthPhase::group)
|
||||||
*/
|
.findFirst()
|
||||||
public List<LocalDate> getDateListOfGrowthPhase(GrowthPhaseType growthPhase) {
|
.orElse(0);
|
||||||
List<LocalDate> dates = new LinkedList<>();
|
|
||||||
for (GrowthPhase growth : lifecycle) {
|
|
||||||
if (growth.type().equals(growthPhase)) {
|
|
||||||
dates = addDatesFromMonthDay(growth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* transform monthDay value of the given growthPhase to localDate
|
* Checks if the given {@link LocalDate} is within a {@link GrowthPhase} of the given {@link GrowthPhaseType}
|
||||||
* return a list of dates from start to end of growth phase
|
*
|
||||||
* @param growthPhase the current growthPhase
|
* @param date The date to check.
|
||||||
* @return a list of dates of the current year
|
* @param phase The {@link GrowthPhaseType} to match against
|
||||||
|
* @return Whether the date is within the given {@link GrowthPhaseType}
|
||||||
*/
|
*/
|
||||||
private List<LocalDate> addDatesFromMonthDay(GrowthPhase growthPhase) {
|
public boolean isDateInPhase(LocalDate date, GrowthPhaseType phase) {
|
||||||
List<LocalDate> dates = new LinkedList<>();
|
return lifecycle.stream()
|
||||||
LocalDate today = LocalDate.now();
|
.filter(growthPhase -> growthPhase.type().equals(phase))
|
||||||
LocalDate start = growthPhase.startDate().atYear(today.getYear());
|
.anyMatch(growthPhase -> dateInRange(date, growthPhase.startDate(), growthPhase.endDate()));
|
||||||
LocalDate end = growthPhase.endDate().atYear(today.getYear());
|
|
||||||
while (!start.isAfter(end)) {
|
|
||||||
dates.add(start);
|
|
||||||
start = start.plusDays(1);
|
|
||||||
}
|
}
|
||||||
return dates;
|
|
||||||
|
/**
|
||||||
|
* Checks if the given {@link LocalDate} is within the given {@link MonthDay} range.
|
||||||
|
* (regardless of year)
|
||||||
|
*
|
||||||
|
* @param subject The date to check
|
||||||
|
* @param min The start of the date-range
|
||||||
|
* @param max The end of the date-range
|
||||||
|
* @return Whether the subject is within the range.
|
||||||
|
*/
|
||||||
|
private boolean dateInRange(LocalDate subject, MonthDay min, MonthDay max) {
|
||||||
|
return subject.getMonth().compareTo(min.getMonth()) >= 0 &&
|
||||||
|
subject.getMonth().compareTo(max.getMonth()) <= 0 &&
|
||||||
|
// if the day is less than the minimum day, the minimum month must not be equal
|
||||||
|
(subject.getDayOfMonth() >= min.getDayOfMonth() || !subject.getMonth().equals(min.getMonth())) &&
|
||||||
|
// if the day is greater than the maximum day, the maximum month must not be equal
|
||||||
|
(subject.getDayOfMonth() <= max.getDayOfMonth() || !subject.getMonth().equals(max.getMonth()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?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.MyGardenController">
|
<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.MyGardenController" fx:id="myGardenRoot">
|
||||||
<children>
|
<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">
|
<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>
|
<children>
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="1000.0" prefHeight="853.0"
|
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="1000.0" prefHeight="853.0"
|
||||||
prefWidth="1219.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
|
prefWidth="1219.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="ch.zhaw.gartenverwaltung.PlantsController">
|
fx:controller="ch.zhaw.gartenverwaltung.PlantsController"
|
||||||
|
fx:id="plantsRoot">
|
||||||
<children>
|
<children>
|
||||||
<SplitPane dividerPositions="0.7377363661277062" layoutX="539.0" layoutY="266.0" prefHeight="853.0" prefWidth="1219.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<SplitPane dividerPositions="0.7377363661277062" layoutX="539.0" layoutY="266.0" prefHeight="853.0" prefWidth="1219.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.DatePicker?>
|
<?import javafx.scene.control.DatePicker?>
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.control.RadioButton?>
|
<?import javafx.scene.control.RadioButton?>
|
||||||
<?import javafx.scene.control.ToggleGroup?>
|
<?import javafx.scene.control.ToggleGroup?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
@@ -16,20 +14,19 @@
|
|||||||
<children>
|
<children>
|
||||||
<VBox maxWidth="1.7976931348623157E308" prefHeight="408.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<VBox maxWidth="1.7976931348623157E308" prefHeight="408.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="popup_label" text="Label" />
|
|
||||||
<HBox alignment="CENTER" prefHeight="293.0" prefWidth="631.0">
|
<HBox alignment="CENTER" prefHeight="293.0" prefWidth="631.0">
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="CENTER_LEFT" prefHeight="88.0" prefWidth="155.0">
|
<VBox alignment="CENTER_LEFT" prefHeight="88.0" prefWidth="155.0">
|
||||||
<children>
|
<children>
|
||||||
<RadioButton fx:id="sow_radio" mnemonicParsing="false" selected="true" text="Sow">
|
<RadioButton fx:id="sow_radio" mnemonicParsing="false" selected="true" text="Sow" toggleGroup="$phase_group">
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" />
|
<Insets bottom="10.0" />
|
||||||
</VBox.margin>
|
</VBox.margin>
|
||||||
<toggleGroup>
|
<toggleGroup>
|
||||||
<ToggleGroup fx:id="group" />
|
<ToggleGroup fx:id="phase_group" />
|
||||||
</toggleGroup>
|
</toggleGroup>
|
||||||
</RadioButton>
|
</RadioButton>
|
||||||
<RadioButton fx:id="harvest_radio" mnemonicParsing="false" text="Harvest" toggleGroup="$group" />
|
<RadioButton fx:id="harvest_radio" mnemonicParsing="false" text="Harvest" toggleGroup="$phase_group" />
|
||||||
</children>
|
</children>
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets top="10.0" />
|
<Insets top="10.0" />
|
||||||
@@ -38,16 +35,6 @@
|
|||||||
<DatePicker fx:id="datepicker" />
|
<DatePicker fx:id="datepicker" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox fillHeight="false" prefHeight="54.0" prefWidth="631.0" VBox.vgrow="NEVER">
|
|
||||||
<children>
|
|
||||||
<Button fx:id="save_button" mnemonicParsing="false" onAction="#save" prefHeight="25.0" prefWidth="53.0" text="Save">
|
|
||||||
<HBox.margin>
|
|
||||||
<Insets right="10.0" />
|
|
||||||
</HBox.margin>
|
|
||||||
</Button>
|
|
||||||
<Button fx:id="cancel_button" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
|
|
||||||
</children>
|
|
||||||
</HBox>
|
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
|||||||
@@ -6,17 +6,25 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.MonthDay;
|
import java.time.MonthDay;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class GardenPlanModelTest {
|
public class GardenPlanModelTest {
|
||||||
|
private final URL dbDataSource = JsonCropList.class.getResource("user-crops.json");
|
||||||
|
private final URL testFile = JsonCropList.class.getResource("test-user-crops.json");
|
||||||
|
|
||||||
CropList cropList;
|
CropList cropList;
|
||||||
List<Crop> exampleCrops;
|
List<Crop> exampleCrops;
|
||||||
Crop exampleCropOnion;
|
Crop exampleCropOnion;
|
||||||
@@ -29,7 +37,7 @@ public class GardenPlanModelTest {
|
|||||||
Garden model;
|
Garden model;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws IOException {
|
void setUp() throws IOException, URISyntaxException {
|
||||||
|
|
||||||
|
|
||||||
examplePlantOnion = new Plant(
|
examplePlantOnion = new Plant(
|
||||||
@@ -76,18 +84,24 @@ public class GardenPlanModelTest {
|
|||||||
exampleCrops.add(exampleCrop1);
|
exampleCrops.add(exampleCrop1);
|
||||||
exampleCrops.add(exampleCrop2);
|
exampleCrops.add(exampleCrop2);
|
||||||
exampleCrops.add(exampleCrop3);
|
exampleCrops.add(exampleCrop3);
|
||||||
cropList = mockGardenPlan(exampleCrops);
|
cropList = mockCropList(exampleCrops);
|
||||||
|
|
||||||
GardenSchedule gardenSchedule = new GardenSchedule(new JsonTaskList(), new JsonPlantList());
|
// Reset Crop "database" before test
|
||||||
model = new Garden(gardenSchedule, cropList);
|
assertNotNull(testFile);
|
||||||
|
assertNotNull(dbDataSource);
|
||||||
|
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
CropList testDatabase = new JsonCropList(dbDataSource);
|
||||||
|
|
||||||
|
GardenSchedule gardenSchedule = mock(GardenSchedule.class);
|
||||||
|
model = new Garden(gardenSchedule, testDatabase);
|
||||||
}
|
}
|
||||||
|
|
||||||
CropList mockGardenPlan(List<Crop> cropList) throws IOException {
|
CropList mockCropList(List<Crop> cropList) throws IOException {
|
||||||
CropList gardenPlan = mock(CropList.class);
|
CropList croplist = mock(CropList.class);
|
||||||
when(gardenPlan.getCrops()).thenReturn(cropList);
|
when(croplist.getCrops()).thenReturn(cropList);
|
||||||
when(gardenPlan.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
when(croplist.getCropById(5)).thenReturn(java.util.Optional.ofNullable(exampleCropCarrot));
|
||||||
when(gardenPlan.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
when(croplist.getCropById(3)).thenReturn(java.util.Optional.ofNullable(exampleCropOnion));
|
||||||
return gardenPlan;
|
return croplist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user