149 lines
4.0 KiB
Java
149 lines
4.0 KiB
Java
package ch.zhaw.gartenverwaltung;
|
|
|
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
|
import ch.zhaw.gartenverwaltung.io.PlantList;
|
|
import ch.zhaw.gartenverwaltung.models.Garden;
|
|
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
|
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;
|
|
import ch.zhaw.gartenverwaltung.types.Task;
|
|
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;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
public class CropDetailController {
|
|
private Crop crop;
|
|
|
|
@Inject
|
|
private PlantList plantList;
|
|
@Inject
|
|
private GardenSchedule gardenSchedule;
|
|
@Inject
|
|
private Garden garden;
|
|
|
|
private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName());
|
|
|
|
@FXML
|
|
private ImageView imageView;
|
|
|
|
@FXML
|
|
private Button area_button;
|
|
|
|
@FXML
|
|
private Label area_label;
|
|
|
|
@FXML
|
|
private Label cropName_label;
|
|
|
|
@FXML
|
|
private Label description_label;
|
|
|
|
@FXML
|
|
private VBox growthPhases_vbox;
|
|
|
|
@FXML
|
|
private Label location_label;
|
|
|
|
@FXML
|
|
private Label light_label;
|
|
|
|
@FXML
|
|
private Button location_button;
|
|
|
|
@FXML
|
|
private VBox pests_vbox;
|
|
|
|
@FXML
|
|
private Label soil_label;
|
|
|
|
@FXML
|
|
private Label spacing_label;
|
|
|
|
@FXML
|
|
void editTaskList() {
|
|
|
|
}
|
|
|
|
@FXML
|
|
void goBack() {
|
|
Stage stage = (Stage) imageView.getScene().getWindow();
|
|
stage.close();
|
|
}
|
|
|
|
@FXML
|
|
void setArea() {
|
|
|
|
}
|
|
|
|
@FXML
|
|
void setLocation() {
|
|
|
|
}
|
|
|
|
public void setPlantFromCrop(Crop crop) throws HardinessZoneNotSetException, IOException, PlantNotFoundException {
|
|
this.crop = crop;
|
|
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()));
|
|
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) {
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
}
|