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 + '}';