-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parsing should happen in the JabRefPreferences
class so that the constructor here admits a map: column > sort order
@@ -114,6 +114,12 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, | |||
|
|||
this.pane.getStylesheets().add(MainTable.class.getResource("MainTable.css").toExternalForm()); | |||
|
|||
//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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -114,6 +114,12 @@ public MainTable(MainTableDataModel model, JabRefFrame frame, | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -41,13 +43,16 @@ private void onColumnsChanged(ListChangeListener.Change<? extends TableColumn<Bi | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's not used...
@@ -1955,4 +1961,13 @@ public void setIdBasedFetcherForEntryGenerator(String fetcherName) { | |||
public String getIdBasedFetcherForEntryGenerator() { | |||
return get(ID_ENTRY_GENERATOR); | |||
} | |||
|
|||
public void setMainTableColumnSortOrder(String column, String sortType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accept SortOrder
and not a string as second argument.
putStringList(SORT_COLUMN, Arrays.asList(column, sortType)); | ||
} | ||
|
||
public List<String> getMainTableColumnSortOrder() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used?
I will try if I can store the sortOrder as well. |
I now managed to save the whole sort oder for multiple columns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -1442,8 +1429,6 @@ public SavePreferences loadForExportFromPreferences() { | |||
if (!saveInOriginalOrder) { | |||
if (this.getBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER)) { | |||
saveOrder = this.loadExportSaveOrder(); | |||
} else { | |||
saveOrder = this.loadTableSaveOrder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quickly had an idea on how to re implement this which works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
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?