refactor: annotation-based dependency-injection

This commit is contained in:
David Guler
2022-11-14 21:15:27 +01:00
parent 15279838b7
commit 5ef3f6c587
9 changed files with 188 additions and 139 deletions
@@ -1,5 +1,8 @@
package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.models.PlantListModel;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
@@ -8,7 +11,6 @@ import ch.zhaw.gartenverwaltung.types.Seasons;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.*;
@@ -25,21 +27,18 @@ import java.util.logging.Logger;
public class PlantsController {
private static final Logger LOG = Logger.getLogger(PlantsController.class.getName());
@Inject
private PlantListModel plantListModel;
private MainFXMLController mainController;
@Inject
private AppLoader appLoader;
private Plant selectedPlant = null;
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
// TODO: move to model
private final ListProperty<Plant> plantListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
@SuppressWarnings("unused")
public void injectDependencies(PlantListModel plantListModel, MainFXMLController mainController) {
this.plantListModel = plantListModel;
this.mainController = mainController;
init();
}
@FXML
private VBox seasons;
@@ -63,12 +62,11 @@ public class PlantsController {
/**
* open new window to select sow or harvest day to save the crop
* @param event event
*/
@FXML
void selectSowDate(ActionEvent event) throws IOException {
void selectSowDate() throws IOException {
Stage stage = new Stage();
if (mainController.loadSceneToStage("SelectSowDay.fxml", stage) instanceof SelectSowDayController controller) {
if (appLoader.loadSceneToStage("SelectSowDay.fxml", stage) instanceof SelectSowDayController controller) {
controller.setSelectedPlant(selectedPlant);
}
@@ -84,6 +82,8 @@ public class PlantsController {
* create event listener for selected list entry and search by query
* {@inheritDoc}
*/
@AfterInject
@SuppressWarnings("unused")
public void init() {
setListCellFactory();
fillPlantListWithHardinessZone();
@@ -95,6 +95,7 @@ public class PlantsController {
createFilterSeasons();
createFilterHardinessZone();
lookForSelectedListEntry();
try {
viewFilteredListBySearch();
} catch (HardinessZoneNotSetException e) {