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

Save sort order column of main table #4327

Merged
merged 13 commits into from
Sep 13, 2018
Merged

Save sort order column of main table #4327

merged 13 commits into from
Sep 13, 2018

Conversation

Siedlerchr
Copy link
Member

@Siedlerchr Siedlerchr commented Sep 9, 2018

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?


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef
  • Screenshots added in PR description (for bigger UI changes)
  • Ensured that the git commit message is a good one
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@tobiasdiez
Copy link
Member

Sorry no idea, would also need to debug this to see what's going on.

@Siedlerchr
Copy link
Member Author

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/
and I experience the same behaviour

@Siedlerchr Siedlerchr changed the title [WIP] Save sort order column of main table Save sort order column of main table Sep 10, 2018
@Siedlerchr
Copy link
Member Author

Apparently the SortOrder alone was not sufficient: https://stackoverflow.com/a/52255643/3450689
It works now

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 10, 2018
Copy link
Member

@tobiasdiez tobiasdiez left a 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))) {
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@tobiasdiez tobiasdiez Sep 11, 2018

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<>();
Copy link
Member

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) {
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

@Siedlerchr
Copy link
Member Author

I will try if I can store the sortOrder as well.

* upstream/master:
  Fix that web search pane steals input (#4335)
  Fix entry editor field display (#4333)
  Convert update worker to BackgroundTask (#4334)
  Fix that "Rename and move file" throws file not found exception (#4317)
@Siedlerchr
Copy link
Member Author

I now managed to save the whole sort oder for multiple columns.

Copy link
Member

@tobiasdiez tobiasdiez left a 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.

* upstream/master:
  Fix export of corporate author to MSOffice (#4337)
  Added new keyboard shortcut "ctrl+E" for closing the entry editor. (#4222) (#4338)
  Remove GlobalFocusListener and old TextField entry editor (#4336)
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();
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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.

restore table sort oder config
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@tobiasdiez tobiasdiez merged commit ed7ea50 into master Sep 13, 2018
@tobiasdiez tobiasdiez deleted the storeColumnSortOrder branch September 13, 2018 11:51
@calixtus calixtus mentioned this pull request Dec 10, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Save sort-criteria of maintable across sessions Default sorting of entry table is lost
2 participants