112 lines
3.3 KiB
Java
112 lines
3.3 KiB
Java
package ch.zhaw.gartenverwaltung;
|
|
|
|
import ch.zhaw.gartenverwaltung.types.Crop;
|
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.event.EventHandler;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.Initializable;
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.ButtonType;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.VBox;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.ResourceBundle;
|
|
|
|
public class MyPlantsController implements Initializable {
|
|
MainFXMLController mainController;
|
|
|
|
@FXML
|
|
private Button addPlant_button;
|
|
|
|
@FXML
|
|
private VBox myPlants_vbox;
|
|
|
|
@FXML
|
|
void addPlant(ActionEvent event) throws IOException {
|
|
mainController.loadPane("Plants.fxml");
|
|
}
|
|
|
|
@Override
|
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
|
//ToDo
|
|
List<Crop> cropList = getCropList();
|
|
createPlantView(cropList);
|
|
}
|
|
|
|
private void createPlantView(List<Crop> crops) {
|
|
for(Crop crop : crops) {
|
|
HBox hBox = createPlantView(crop);
|
|
myPlants_vbox.getChildren().add(hBox);
|
|
}
|
|
}
|
|
|
|
public void getMainController(MainFXMLController controller) {
|
|
mainController = controller;
|
|
}
|
|
|
|
private List<Crop> getCropList() {
|
|
//ToDo method to get cropList
|
|
//Method to get Crop List
|
|
List<Crop> cropList = new LinkedList<>();
|
|
return cropList;
|
|
}
|
|
|
|
private HBox createPlantView(Crop crop) {
|
|
//ToDo add dynamic design
|
|
HBox hBox = new HBox();
|
|
Label label = new Label("Placeholder");
|
|
Button details = new Button("Details");
|
|
Button delete = new Button("delete");
|
|
details.setOnAction(getGoToCropDetailEvent(crop));
|
|
delete.setOnAction(getDeleteCropEvent(crop));
|
|
hBox.getChildren().addAll(label, details, delete);
|
|
return hBox;
|
|
}
|
|
|
|
private EventHandler<ActionEvent> getGoToCropDetailEvent(Crop crop) {
|
|
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent event) {
|
|
//ToDo uncomment when new FXML exists
|
|
/*try {
|
|
mainController.loadPane("");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}*/
|
|
}
|
|
};
|
|
return event;
|
|
}
|
|
|
|
private EventHandler<ActionEvent> getDeleteCropEvent(Crop crop) {
|
|
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent event) {
|
|
showConfirmation(crop);
|
|
}
|
|
};
|
|
return event;
|
|
}
|
|
|
|
private void showConfirmation(Crop crop) {
|
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
|
alert.setTitle("Delete Crop");
|
|
alert.setHeaderText("Are you sure want to delete this Crop?");
|
|
alert.setContentText("placeholder");
|
|
|
|
Optional<ButtonType> option = alert.showAndWait();
|
|
|
|
if (option.get() == ButtonType.OK) {
|
|
//ToDo Method to remove crop
|
|
}
|
|
}
|
|
}
|