diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index e50a983..0e80969 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -92,37 +92,36 @@ public class FoodpalApplicationCtrl implements LocaleAware { this.ingredientListCtrl = ingredientListCtrl; this.stepListCtrl = stepListCtrl; } - @Override public void initializeComponents() { // TODO Reduce code duplication?? // Initialize callback for ingredient list updates this.ingredientListCtrl.setUpdateCallback(newList -> { - Recipe focusedRecipe = recipeList.getFocusModel().getFocusedItem(); - if (focusedRecipe == null) { + Recipe selectedRecipe = recipeList.getSelectionModel().getSelectedItem(); + if (selectedRecipe == null) { // edge case error for NPE. throw new NullPointerException("Null recipe whereas ingredients are edited"); } - focusedRecipe.setIngredients(newList); + selectedRecipe.setIngredients(newList); try { // propagate changes to server - server.updateRecipe(focusedRecipe); + server.updateRecipe(selectedRecipe); } catch (IOException | InterruptedException e) { - throw new UpdateException("Unable to update recipe to server for " + focusedRecipe); + throw new UpdateException("Unable to update recipe to server for " + selectedRecipe); } }); this.stepListCtrl.setUpdateCallback(newList -> { - Recipe focusedRecipe = recipeList.getFocusModel().getFocusedItem(); - if (focusedRecipe == null) { + Recipe selectedRecipe = recipeList.getSelectionModel().getSelectedItem(); + if (selectedRecipe == null) { // edge case error for NPE. throw new NullPointerException("Null recipe whereas ingredients are edited"); } - focusedRecipe.setPreparationSteps(newList); + selectedRecipe.setPreparationSteps(newList); try { // propagate changes to server - server.updateRecipe(focusedRecipe); + server.updateRecipe(selectedRecipe); } catch (IOException | InterruptedException e) { - throw new UpdateException("Unable to update recipe to server for " + focusedRecipe); + throw new UpdateException("Unable to update recipe to server for " + selectedRecipe); } }); // Show recipe name in the list @@ -284,6 +283,7 @@ public class FoodpalApplicationCtrl implements LocaleAware { try { server.updateRecipe(selected); refresh(); + recipeList.getSelectionModel().select(selected); } catch (IOException | InterruptedException e) { // throw a nice blanket UpdateException throw new UpdateException("Error occurred when updating recipe name!");