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.
This commit is contained in:
Noah Lynch
2020-10-25 06:54:04 -04:00
committed by GitHub
parent 57468ef932
commit 09893605eb
2 changed files with 19 additions and 12 deletions

View File

@@ -124,7 +124,7 @@ public class AliasEditor extends TabPane
{ {
if(mAliasViewByIdentifierEditor == null) if(mAliasViewByIdentifierEditor == null)
{ {
mAliasViewByIdentifierEditor = new AliasViewByIdentifierEditor(mPlaylistManager); mAliasViewByIdentifierEditor = new AliasViewByIdentifierEditor(mPlaylistManager, getAliasIdentifierTab().selectedProperty());
} }
return mAliasViewByIdentifierEditor; return mAliasViewByIdentifierEditor;

View File

@@ -25,11 +25,12 @@ import io.github.dsheirer.alias.id.AliasID;
import io.github.dsheirer.alias.id.AliasIDType; import io.github.dsheirer.alias.id.AliasIDType;
import io.github.dsheirer.eventbus.MyEventBus; import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.FilteredList;
import javafx.geometry.HPos; import javafx.geometry.HPos;
import javafx.geometry.Insets; import javafx.geometry.Insets;
@@ -63,15 +64,19 @@ public class AliasViewByIdentifierEditor extends VBox
private TableView<AliasAndIdentifier> mAliasAndIdentifierTableView; private TableView<AliasAndIdentifier> mAliasAndIdentifierTableView;
private TableColumn<AliasAndIdentifier,String> mIdentifierColumn; private TableColumn<AliasAndIdentifier,String> mIdentifierColumn;
private Button mViewAliasButton; private Button mViewAliasButton;
private boolean aliasListInvalidated;
public AliasViewByIdentifierEditor(PlaylistManager playlistManager) public AliasViewByIdentifierEditor(PlaylistManager playlistManager, ReadOnlyBooleanProperty tabSelectedProperty)
{ {
aliasListInvalidated = false;
mPlaylistManager = playlistManager; mPlaylistManager = playlistManager;
mPlaylistManager.getAliasModel().aliasList().addListener((ListChangeListener<Alias>)c -> { //Note if aliases change since we're using a static snapshot
//Refresh the list any time that the aliases change since we're using a static snapshot mPlaylistManager.getAliasModel().aliasList().addListener((InvalidationListener)observable -> aliasListInvalidated = true);
AliasIDType selected = getAliasIDTypeComboBox().getSelectionModel().getSelectedItem();
getAliasIDTypeComboBox().getSelectionModel().select(null); //Only update the list when this tab is selected to avoid many slow updates in the background
getAliasIDTypeComboBox().getSelectionModel().select(selected); tabSelectedProperty.addListener(observable -> {
if (aliasListInvalidated)
updateList();
}); });
GridPane gridPane = new GridPane(); GridPane gridPane = new GridPane();
@@ -131,6 +136,8 @@ public class AliasViewByIdentifierEditor extends VBox
} }
getAliasAndIdentifierTableView().getSortOrder().setAll(mIdentifierColumn); getAliasAndIdentifierTableView().getSortOrder().setAll(mIdentifierColumn);
aliasListInvalidated = false;
} }
/** /**
@@ -190,22 +197,22 @@ public class AliasViewByIdentifierEditor extends VBox
{ {
if(mAliasAndIdentifierTableView == null) 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")); mAliasAndIdentifierTableView.setPlaceholder(new Label("No aliases or identifiers available"));
mIdentifierColumn = new TableColumn<>("Identifier"); mIdentifierColumn = new TableColumn<>("Identifier");
mIdentifierColumn.setCellValueFactory(new PropertyValueFactory<>("identifier")); mIdentifierColumn.setCellValueFactory(new PropertyValueFactory<>("identifier"));
mIdentifierColumn.setPrefWidth(350); mIdentifierColumn.setPrefWidth(350);
TableColumn aliasColumn = new TableColumn(); TableColumn<AliasAndIdentifier, String> aliasColumn = new TableColumn<>();
aliasColumn.setText("Alias"); aliasColumn.setText("Alias");
aliasColumn.setCellValueFactory(new PropertyValueFactory<>("alias")); aliasColumn.setCellValueFactory(new PropertyValueFactory<>("alias"));
aliasColumn.setPrefWidth(200); aliasColumn.setPrefWidth(200);
TableColumn groupColumn = new TableColumn(); TableColumn<AliasAndIdentifier, String> groupColumn = new TableColumn<>();
groupColumn.setText("Group"); groupColumn.setText("Group");
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group")); groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
groupColumn.setPrefWidth(200); groupColumn.setPrefWidth(200);
mAliasAndIdentifierTableView.getColumns().addAll(mIdentifierColumn, aliasColumn, groupColumn); mAliasAndIdentifierTableView.getColumns().addAll(mIdentifierColumn, aliasColumn, groupColumn);
mAliasAndIdentifierTableView.setMaxHeight(Double.MAX_VALUE); mAliasAndIdentifierTableView.setMaxHeight(Double.MAX_VALUE);