From 0dca957e434e3c5f3c225458e9813a6315727950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Rasie=C5=84ski?= Date: Wed, 17 Dec 2025 13:32:14 +0100 Subject: [PATCH] Fixed bug and improved debug print --- .../java/client/scenes/FoodpalApplicationCtrl.java | 13 ++++++------- commons/src/main/java/commons/Recipe.java | 6 ++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index ed97139..0b3aeba 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -223,14 +223,13 @@ public class FoodpalApplicationCtrl implements LocaleAware { */ @FXML private void addRecipe() { - // a default factory provides the value - Recipe newRecipe = DefaultRecipeFactory.getDefaultRecipe(); + Recipe newRecipe = DefaultRecipeFactory.getDefaultRecipe(); // Create default recipe try { - server.addRecipe(newRecipe); - refresh(); - // the list focuses on the new recipe - // otherwise strange issues occur when the autofocus on edit box is called - recipeList.getFocusModel().focus(recipeList.getItems().indexOf(newRecipe)); + newRecipe = server.addRecipe(newRecipe); // get the new recipe id + refresh(); // refresh view with server recipes + + // Select newly created recipe + recipeList.getSelectionModel().select(recipeList.getItems().indexOf(newRecipe)); } catch (IOException | InterruptedException e) { printError("Error occurred when adding recipe!"); } diff --git a/commons/src/main/java/commons/Recipe.java b/commons/src/main/java/commons/Recipe.java index 6ee2497..ffe87cb 100644 --- a/commons/src/main/java/commons/Recipe.java +++ b/commons/src/main/java/commons/Recipe.java @@ -157,7 +157,8 @@ public class Recipe { @Override public String toString() { return "Recipe{" + - "name='" + name + '\'' + + "id=" + id + + ", name='" + name + '\'' + ", ingredientsCount=" + ingredients.size() + ", preparationStepsCount=" + preparationSteps.size() + "}"; @@ -167,7 +168,8 @@ public class Recipe { public String toDetailedString() { // More detailed toString for debugging. return "Recipe{" + - "name='" + name + '\'' + + "id=" + id + + ", name='" + name + '\'' + ", ingredients=" + ingredients + ", preparationSteps=" + preparationSteps + '}';