fix: rectify a NPE caused by wrong ListView model
Apparently a thing can be selected but not focused. Oops.
This commit is contained in:
parent
73324022b0
commit
30cbfbc454
1 changed files with 11 additions and 11 deletions
|
|
@ -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!");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue