diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java index 089ffdc..d0cdef4 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java @@ -1,5 +1,7 @@ package com.bib.essensbestellungsverwaltung; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -7,6 +9,7 @@ import javafx.scene.control.RadioButton; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.text.Text; +import org.controlsfx.control.CheckComboBox; import java.util.ArrayList; import java.util.List; @@ -27,9 +30,18 @@ public class CreateFoodController { @FXML public RadioButton isFleischRadio; @FXML - public TextArea allergienTextBox; - @FXML public Text responseText; + public CheckComboBox allergienComboBox; + + @FXML + public void initialize() { + List a = Database.getTable("allergy"); + ObservableList allergies = FXCollections.observableArrayList(); + for (String allergie : a) { + allergies.add(allergie.split(":")[0] + ": " + allergie.split(":")[1]); + } + allergienComboBox.getItems().addAll(allergies); + } @FXML public void onAbbrechen(ActionEvent actionEvent) { @@ -78,7 +90,12 @@ public class CreateFoodController { int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3; FoodType foodType = new FoodType(ft, "Vegan"); List allergies = new ArrayList<>(); - // TODO: allergien hinzufügen + allergienComboBox.getCheckModel().getCheckedItems().stream().forEach(a -> { + long id = Integer.parseInt(a.toString().split(":")[0]); + String name = a.toString().split(":")[1].trim(); + allergies.add((new Allergy(id, name, ""))); + }); + System.out.println(allergies.get(0).getName()); long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies)); if(id <= 0){ @@ -102,6 +119,6 @@ public class CreateFoodController { isVeganRadio.setSelected(false); isVegetarischRadio.setSelected(false); isFleischRadio.setSelected(false); - allergienTextBox.setText(""); + allergienComboBox.getCheckModel().clearChecks(); } } diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/createFood-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/createFood-view.fxml index 0c897cd..bc398d7 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/createFood-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/createFood-view.fxml @@ -4,6 +4,7 @@ + @@ -90,8 +91,8 @@ -