From 09893605eb9c24578777ba34b981d8e98aba2f22 Mon Sep 17 00:00:00 2001 From: Noah Lynch Date: Sun, 25 Oct 2020 05:54:04 -0500 Subject: [PATCH] Only update ViewByIdentifierEditor's list when the editor is selected (#944) * Add type parameters to TableColumns to fix compiler warnings * Only update AliasViewByIdentifierEditor list when the editor is selected This prevents the editor's list from being rebuilt in the background as aliases are updated. This caused a massive slowdown when editing many aliases with the AliasBulkEditor. Bulk editing 1000 aliases apply time reduced from over a minute to under 5 seconds. --- .../gui/playlist/alias/AliasEditor.java | 2 +- .../alias/AliasViewByIdentifierEditor.java | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasEditor.java index 4666e497..fd71237c 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasEditor.java @@ -124,7 +124,7 @@ public class AliasEditor extends TabPane { if(mAliasViewByIdentifierEditor == null) { - mAliasViewByIdentifierEditor = new AliasViewByIdentifierEditor(mPlaylistManager); + mAliasViewByIdentifierEditor = new AliasViewByIdentifierEditor(mPlaylistManager, getAliasIdentifierTab().selectedProperty()); } return mAliasViewByIdentifierEditor; diff --git a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasViewByIdentifierEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasViewByIdentifierEditor.java index 6124aea7..981e695a 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasViewByIdentifierEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/alias/AliasViewByIdentifierEditor.java @@ -25,11 +25,12 @@ import io.github.dsheirer.alias.id.AliasID; import io.github.dsheirer.alias.id.AliasIDType; import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.playlist.PlaylistManager; +import javafx.beans.InvalidationListener; import javafx.beans.Observable; +import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; import javafx.collections.transformation.FilteredList; import javafx.geometry.HPos; import javafx.geometry.Insets; @@ -63,15 +64,19 @@ public class AliasViewByIdentifierEditor extends VBox private TableView mAliasAndIdentifierTableView; private TableColumn mIdentifierColumn; private Button mViewAliasButton; + private boolean aliasListInvalidated; - public AliasViewByIdentifierEditor(PlaylistManager playlistManager) + public AliasViewByIdentifierEditor(PlaylistManager playlistManager, ReadOnlyBooleanProperty tabSelectedProperty) { + aliasListInvalidated = false; mPlaylistManager = playlistManager; - mPlaylistManager.getAliasModel().aliasList().addListener((ListChangeListener)c -> { - //Refresh the list any time that the aliases change since we're using a static snapshot - AliasIDType selected = getAliasIDTypeComboBox().getSelectionModel().getSelectedItem(); - getAliasIDTypeComboBox().getSelectionModel().select(null); - getAliasIDTypeComboBox().getSelectionModel().select(selected); + //Note if aliases change since we're using a static snapshot + mPlaylistManager.getAliasModel().aliasList().addListener((InvalidationListener)observable -> aliasListInvalidated = true); + + //Only update the list when this tab is selected to avoid many slow updates in the background + tabSelectedProperty.addListener(observable -> { + if (aliasListInvalidated) + updateList(); }); GridPane gridPane = new GridPane(); @@ -131,6 +136,8 @@ public class AliasViewByIdentifierEditor extends VBox } getAliasAndIdentifierTableView().getSortOrder().setAll(mIdentifierColumn); + + aliasListInvalidated = false; } /** @@ -190,22 +197,22 @@ public class AliasViewByIdentifierEditor extends VBox { if(mAliasAndIdentifierTableView == null) { - mAliasAndIdentifierTableView = new TableView(FXCollections.observableArrayList(AliasAndIdentifier.extractor())); + mAliasAndIdentifierTableView = new TableView<>(FXCollections.observableArrayList(AliasAndIdentifier.extractor())); mAliasAndIdentifierTableView.setPlaceholder(new Label("No aliases or identifiers available")); mIdentifierColumn = new TableColumn<>("Identifier"); mIdentifierColumn.setCellValueFactory(new PropertyValueFactory<>("identifier")); mIdentifierColumn.setPrefWidth(350); - TableColumn aliasColumn = new TableColumn(); + TableColumn aliasColumn = new TableColumn<>(); aliasColumn.setText("Alias"); aliasColumn.setCellValueFactory(new PropertyValueFactory<>("alias")); aliasColumn.setPrefWidth(200); - TableColumn groupColumn = new TableColumn(); + TableColumn groupColumn = new TableColumn<>(); groupColumn.setText("Group"); groupColumn.setCellValueFactory(new PropertyValueFactory<>("group")); groupColumn.setPrefWidth(200); - + mAliasAndIdentifierTableView.getColumns().addAll(mIdentifierColumn, aliasColumn, groupColumn); mAliasAndIdentifierTableView.setMaxHeight(Double.MAX_VALUE);