From 48be38a2d8d36876d1ceda55f3cd67da4be6598e Mon Sep 17 00:00:00 2001 From: Noah Lynch Date: Sat, 25 Jul 2020 06:08:39 -0500 Subject: [PATCH] Wrap setAliases() in Platform.runLater() (#885) Fixes issue #884 (see issue for more info). AliasItemEditor.save() modifies objects that are observed by the TableView's underlying SortedList. Thus, the TableView's selection can change by calling save(), which means the ListChangeListener can be fired. This is a problem for two reasons. 1. The alert dialogue that prompts the user to save a modified alias will show when the user presses the "save" button, because saving modifies the selected alias and causes the list to update. 2. setAliases() calls Alert.showAndWait(). From the JavaDoc: "It must not be called during animation or layout processing." This statement is likely there because it can cause issues like the one here: TableView's layout processing (and the list updating) is paused and the list is further modified (by calling save()). Thus, when the processing is resumed the list is in a different and unexpected state. Calling setAliases() from Platform.runLater() will allow the SortedList, TableView, and any other involved objects to finish processing changes before more modifications are made. Additionally, it allows save(), when called by pressing the save button, to complete and set the modifiedProperty to false, so setAliases() does not display an additional save prompt. --- .../dsheirer/gui/playlist/alias/AliasConfigurationEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasConfigurationEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasConfigurationEditor.java index a2c47fe4..05c314e0 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasConfigurationEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasConfigurationEditor.java @@ -422,7 +422,7 @@ public class AliasConfigurationEditor extends SplitPane mAliasTableView.setItems(getAliasSortedList()); mAliasTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); mAliasTableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener)c -> { - setAliases(mAliasTableView.getSelectionModel().getSelectedItems()); + Platform.runLater(() -> setAliases(mAliasTableView.getSelectionModel().getSelectedItems())); }); }