From a03a29426016cc4b2af579892eb8a20cebfed2e4 Mon Sep 17 00:00:00 2001 From: Malte Schulze Hobeling Date: Mon, 6 Feb 2023 09:30:13 +0100 Subject: [PATCH] fixed childview --- .../essensbestellungsverwaltung/Allergy.java | 5 +++ .../AllergySeverity.java | 5 +++ .../ChildViewController.java | 36 +++++++++++++------ .../child-view.fxml | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/Allergy.java b/src/main/java/com/bib/essensbestellungsverwaltung/Allergy.java index 39e1581..553622e 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/Allergy.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/Allergy.java @@ -26,4 +26,9 @@ public class Allergy { public String getHandle() { return handle; } + + @Override + public String toString() { + return getName(); + } } diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/AllergySeverity.java b/src/main/java/com/bib/essensbestellungsverwaltung/AllergySeverity.java index 77bb02a..2875d32 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/AllergySeverity.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/AllergySeverity.java @@ -26,4 +26,9 @@ public class AllergySeverity { public String getSeverity() { return severity; } + + @Override + public String toString() { + return getAllergy().getName() + " (" + getSeverity() + ")"; + } } diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java b/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java index 3c998ad..194dd3b 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java @@ -2,6 +2,8 @@ package com.bib.essensbestellungsverwaltung; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -35,6 +37,7 @@ public class ChildViewController implements Initializable { //public TextField allergies; @FXML public ListView allergiesList; + ObservableList olAllergiesList; @FXML public ComboBox selectAllergy; @FXML @@ -71,17 +74,21 @@ public class ChildViewController implements Initializable { if(childData) { - Address adress = new Address(streetString, numberString, plzString, cityString); + Address adress = AccountMgr.currentUser.getAddress(); - List childAllergyList = allergiesList.getItems(); + var olChildAllergyList = allergiesList.getItems(); + List childAllergyList = new ArrayList<>(); + for (var o : olChildAllergyList) { + childAllergyList.add((AllergySeverity) o); + } ArrayList allergySeverityArrayList = new ArrayList<>(); - /*for (Allergy a : childAllergyList) { + /*for (AllergySeverity a : childAllergyList) { AllergySeverity aS = new AllergySeverity(a, ) - }*/ //Allergy Severity doesn't work in my case so the List will be left empty for now + } */ //Allergy Severity doesn't work in my case so the List will be left empty for now - Child child = new Child(childLastname, childName, adress, allergySeverityArrayList); + Child child = new Child(childLastname, childName, adress, childAllergyList); System.out.println(AccountMgr.createChild(child)); @@ -121,9 +128,11 @@ public class ChildViewController implements Initializable { - String addedAllergy = selectAllergy.getValue().toString(); - String addedSeverity = selectAllergySeverity.getValue().toString().split(":")[0]; - allergiesList.getItems().add(addedAllergy + ":" + addedSeverity); + Allergy addedAllergy = (Allergy)selectAllergy.getValue(); + long addedSeverityId = Long.parseLong(selectAllergySeverity.getValue().toString().split(":")[0]); + String addedSeverity = selectAllergySeverity.getValue().toString().split(":")[1]; + olAllergiesList.add(new AllergySeverity(addedAllergy,addedSeverityId,addedSeverity)); + allergiesList.setItems(olAllergiesList); selectAllergy.setValue("Allergie Wählen"); @@ -133,8 +142,15 @@ public class ChildViewController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - selectAllergy.getItems().addAll(allergyComboBox()); + ObservableList olAll = FXCollections.observableArrayList(allergyComboBox()); + selectAllergy.setItems(olAll); + //selectAllergy.getItems().addAll(allergyComboBox()); + olAllergiesList = FXCollections.observableArrayList(); - selectAllergySeverity.getItems().addAll("1:Harmlos","2:Warnung","3:Kritisch"); + ObservableList olSev = FXCollections.observableArrayList(); + olSev.add("1:Harmlos"); + olSev.add("2:Warnung"); + olSev.add("3:Kritisch"); + selectAllergySeverity.setItems(olSev); } } diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml index b022ce4..4b2318e 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml @@ -101,7 +101,7 @@ - +