Save sort order column of main table#4327
Conversation
|
Sorry no idea, would also need to debug this to see what's going on. |
|
Hm, this is odd. I created a simple test application based on the code here https://code.makery.ch/blog/javafx-8-tableview-sorting-filtering/ |
|
Apparently the SortOrder alone was not sufficient: https://stackoverflow.com/a/52255643/3450689 |
tobiasdiez
left a comment
There was a problem hiding this comment.
Nice! I've only a few remarks, mainly around code that apparently was added in previous tries and is now no longer needed.
|
|
||
| public Optional<SortType> getSortTypeForColumn(String columnName) { | ||
|
|
||
| if (columnName.equals(columnSortOrder.get(0))) { |
There was a problem hiding this comment.
This parsing should happen in the JabRefPreferences class so that the constructor here admits a map: column > sort order
|
|
||
| //Set sort order column from preferences, currently only single column suported | ||
| this.getColumns().forEach(col -> preferences.getColumnPreferences().getSortTypeForColumn(col.getText()).ifPresent(sortType -> { | ||
| this.getSortOrder().add(col); |
There was a problem hiding this comment.
Is this call this.getSortOrder().add(col); really necessary? I thought the TableView manages the sort order list on its own.
There was a problem hiding this comment.
Yes, I found it out while testing. The sort oder defines the column which are considered to be sorting.
The sortType property only has an influence if the column is the sortOrder
|
|
||
| this.pane.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); | ||
|
|
||
| //Set sort order column from preferences, currently only single column suported |
There was a problem hiding this comment.
why is only one column supported? You already transverse all columns here and set the right sort order, or do I miss something?
There was a problem hiding this comment.
As I learned from the SO answer, with shift it's possible to add multiple columns to the sort order.
However, currently only one column is stored, e.g. if you have both author DESCENDING and timestamp ASCENDING, it will only store the first one. Or do we have an elegant solution to store Key-Value Pairs in the preferences? e.g. a list of columns with sort type.
There was a problem hiding this comment.
The standard way is to have two lists, one for the keys and one for the values. In the progress, it would be nice if you would add the corresponding wrapper methods (get/putMap) in JabRefPreferences for reuse in the future.
| private void updateColumnPreferences() { | ||
| List<String> columnNames = new ArrayList<>(); | ||
| List<String> columnsWidths = new ArrayList<>(); | ||
| List<String> columnSortOrders = new ArrayList<>(); |
There was a problem hiding this comment.
This looks like it's not used...
| return get(ID_ENTRY_GENERATOR); | ||
| } | ||
|
|
||
| public void setMainTableColumnSortOrder(String column, String sortType) { |
There was a problem hiding this comment.
Accept SortOrder and not a string as second argument.
| putStringList(SORT_COLUMN, Arrays.asList(column, sortType)); | ||
| } | ||
|
|
||
| public List<String> getMainTableColumnSortOrder() { |
|
I will try if I can store the sortOrder as well. |
|
I now managed to save the whole sort oder for multiple columns. |
tobiasdiez
left a comment
There was a problem hiding this comment.
I just stumbled upon it, but it appears that Maintable.setupComparatorChooser contained the old logic for storing the sort order. This (and related code like preference keys) probably can now be deleted.
remove old table prefs sort order fields also from prefs
| if (this.getBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER)) { | ||
| saveOrder = this.loadExportSaveOrder(); | ||
| } else { | ||
| saveOrder = this.loadTableSaveOrder(); |
There was a problem hiding this comment.
I suspect this is still needed to allow the user to export entries in the current sort order.
There was a problem hiding this comment.
But the preferences are no longer set and therefore removed. So I think this is similar to default order?
There was a problem hiding this comment.
I still think the export sort order should be different from the table sort order and I will remove table sort order. But I currently see no easy way to convert the table column sort order to our schema
There was a problem hiding this comment.
I'm fine with removing the "export according to table sorting" feature since it may quickly lead to unexpected exports (although I'm pretty confident that some users rely on this feature). But then please add a changelog entry and check if the documentation needs to be adopted accordingly.
There was a problem hiding this comment.
I quickly had an idea on how to re implement this which works.
Fixes #4224
Fixes #3850
I tired to fix the above issue. But I have the problem that the column sort listener is never fired when the sort order is DESCENDING.
Edit// I also fixed an FX Threading error when opening a new library (the snackbar output was not onFX Thread)
@tobiasdiez Any idea if I did sth wrong oder have to set the value somewhere else?