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

Fix column sort order gets overwritten #7573

Merged
merged 12 commits into from
Mar 29, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where the table column sort order was not properly stored and resulted in unsorted eports [#7524](https://github.com/JabRef/jabref/issues/7524)
- We fixed an issue where the value of the field `school` or `institution` would be printed twice in the HTML Export [forum#2634](https://discourse.jabref.org/t/problem-with-exporting-techreport-phdthesis-mastersthesis-to-html/2634)
- We fixed an issue preventing to connect to a shared database. [#7570](https://github.com/JabRef/jabref/pull/7570)
- We fixed an issue preventing files from being dragged & dropped into an empty library. [#6851](https://github.com/JabRef/jabref/issues/6851)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public enum Type {

public static final EnumSet<Type> ICON_COLUMNS = EnumSet.of(EXTRAFILE, FILES, GROUPS, LINKED_IDENTIFIER);

private String name;
private String displayName;
private final String name;
private final String displayName;

Type(String name) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,37 @@ public PersistenceVisualStateTable(final MainTable mainTable, PreferencesService
this.mainTable = mainTable;
this.preferences = preferences;

mainTable.getColumns().addListener((InvalidationListener) obs -> updateColumnPreferences());
mainTable.getSortOrder().addListener((InvalidationListener) obs -> updateColumnPreferences());
mainTable.getColumns().addListener((InvalidationListener) obs -> updateColumns());
mainTable.getSortOrder().addListener((InvalidationListener) obs -> updateSortOrder());

// 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()));
((MainTableColumn<?>) col).getModel().widthProperty().addListener(obs -> updateColumns()));
mainTable.getColumns().forEach(col ->
((MainTableColumn<?>) col).getModel().sortTypeProperty().addListener(obs -> updateColumnPreferences()));
((MainTableColumn<?>) col).getModel().sortTypeProperty().addListener(obs -> updateColumns()));
}

/**
* Store shown columns, their width and their sortType in preferences.
* Stores shown columns, their width and their sortType in preferences.
*/
private void updateColumnPreferences() {
private void updateColumns() {
preferences.storeColumnPreferences(new ColumnPreferences(
mainTable.getColumns().stream()
.map(column -> ((MainTableColumn<?>) column).getModel())
.collect(Collectors.toList()),
preferences.getColumnPreferences().getColumnSortOrder()));
}

/**
* Stores the SortOrder of the the Table in the preferences. Cannot be combined with updateColumns, because JavaFX
* would provide just an empty list for the sort order on other changes.
*/
private void updateSortOrder() {
preferences.storeColumnPreferences(new ColumnPreferences(
preferences.getColumnPreferences().getColumns(),
mainTable.getSortOrder().stream()
.map(column -> ((MainTableColumn<?>) column).getModel())
.collect(Collectors.toList())
));
.collect(Collectors.toList())));
}
}