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)); } }