Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent column sortorder #5730

Merged
merged 10 commits into from
Dec 16, 2019
Prev Previous commit
Next Next commit
Fixes storing of the correct value
  • Loading branch information
calixtus committed Dec 10, 2019
commit be0a58d2adb2ec03375a32fbc517a6d1d651a825
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import java.util.stream.Collectors;

import javafx.collections.ListChangeListener;
import javafx.scene.control.TableColumn;
import javafx.beans.InvalidationListener;

import org.jabref.preferences.JabRefPreferences;

/**
* Keep track of changes made to the columns, like reordering or resizing.
*
* Keep track of changes made to the columns (reordering, resorting, resizing).
*/
public class PersistenceVisualStateTable {

Expand All @@ -20,21 +18,15 @@ public PersistenceVisualStateTable(final MainTable mainTable, JabRefPreferences
this.mainTable = mainTable;
this.preferences = preferences;

mainTable.getColumns().addListener(this::onColumnsChanged);
mainTable.getSortOrder().addListener(this::onColumnsChanged);
mainTable.getColumns().forEach(col -> col.widthProperty().addListener(obs -> updateColumnPreferences()));
mainTable.getColumns().forEach(col -> col.sortTypeProperty().addListener(obs -> updateColumnPreferences()));
}

private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<BibEntryTableViewModel, ?>> change) {
boolean changed = false;
while (change.next()) {
changed = true;
}
mainTable.getColumns().addListener((InvalidationListener) obs -> updateColumnPreferences());
mainTable.getSortOrder().addListener((InvalidationListener) obs -> updateColumnPreferences());

if (changed) {
updateColumnPreferences();
}
// As we store the ColumnModels of the MainTable, we need to add the listener to the ColumnModel properties,
// since the value is bound to the model after the listener to the column itself is called.
mainTable.getColumns().forEach(col ->
((MainTableColumn<?>) col).getModel().widthProperty().addListener(obs -> updateColumnPreferences()));
mainTable.getColumns().forEach(col ->
((MainTableColumn<?>) col).getModel().sortTypeProperty().addListener(obs -> updateColumnPreferences()));
}

/**
Expand Down