From c6b4bc1cd1594ff5f17724779f76244abf873499 Mon Sep 17 00:00:00 2001 From: pbs2h22aal Date: Tue, 23 Jan 2024 14:58:19 +0100 Subject: [PATCH] Inhaltsstoffe in Filter Maske anzeigen --- src/main/java/Logik/Zutat.java | 6 ++++ .../InhaltsstoffeFilternController.java | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/Logik/Zutat.java b/src/main/java/Logik/Zutat.java index 4c5fe96..d303676 100644 --- a/src/main/java/Logik/Zutat.java +++ b/src/main/java/Logik/Zutat.java @@ -9,4 +9,10 @@ public class Zutat { public String getName(){ return this.name; } + + @Override + public String toString() { + return name; + } + } diff --git a/src/main/java/de/subway_surfers/vpr_app/InhaltsstoffeFilternController.java b/src/main/java/de/subway_surfers/vpr_app/InhaltsstoffeFilternController.java index 2716160..1779c8a 100644 --- a/src/main/java/de/subway_surfers/vpr_app/InhaltsstoffeFilternController.java +++ b/src/main/java/de/subway_surfers/vpr_app/InhaltsstoffeFilternController.java @@ -7,14 +7,21 @@ package de.subway_surfers.vpr_app; import Logik.Kind; +import Logik.Zutat; +import RestAPISchnittstelle.RestApiClient; +import com.google.gson.*; +import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ListView; +import javafx.scene.control.SelectionMode; + +import java.util.ArrayList; public class InhaltsstoffeFilternController { - private @FXML ListView zutatListView; + private @FXML ListView zutatListView; private @FXML CheckBox speichernCheckBox; @@ -22,11 +29,28 @@ public class InhaltsstoffeFilternController { private @FXML Button fortfahrenButton; + private ArrayList zutaten; + public void initialize(){ - // hier ListView füllen + zutatListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + RestApiClient api = new RestApiClient(); + String json = api.get("Inhaltsstoff"); + zutaten = new ArrayList<>(); + + Gson gson = new Gson(); + + JsonElement je = JsonParser.parseString(json); + JsonArray ja = je.getAsJsonArray(); + + for (JsonElement e : ja) { + JsonObject jo = e.getAsJsonObject(); + zutaten.add(gson.fromJson(jo, Zutat.class)); + } + + zutatListView.setItems(FXCollections.observableArrayList(zutaten)); } }