Skip to content

Commit

Permalink
Fix sort by priority (#6222) (#6265)
Browse files Browse the repository at this point in the history
* Fix sort by priority (#6222)

* Change in CHANGELOG.
  • Loading branch information
dextep committed Apr 10, 2020
1 parent f26019a commit d4396ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where sort by priority was broken. [#6222](https://github.com/JabRef/jabref/issues/6222)
- We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939)
- We fixed an issue with inconsistent capitalization of file extensions when downloading files [#6115](https://github.com/JabRef/jabref/issues/6115)
- We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jabref.gui.specialfields.SpecialFieldsPreferences;
import org.jabref.gui.util.OptionalValueTableCellFactory;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.gui.util.comparator.PriorityFieldComparator;
import org.jabref.gui.util.comparator.RankingFieldComparator;
import org.jabref.gui.util.comparator.ReadStatusFieldComparator;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -316,6 +317,10 @@ private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>
column.setComparator(new ReadStatusFieldComparator());
}

if (specialField == SpecialField.PRIORITY) {
column.setComparator(new PriorityFieldComparator());
}

column.setSortable(true);

return column;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jabref.gui.util.comparator;

import java.util.Comparator;
import java.util.Optional;

import org.jabref.gui.specialfields.SpecialFieldValueViewModel;

public class PriorityFieldComparator implements Comparator<Optional<SpecialFieldValueViewModel>> {

@Override
public int compare(Optional<SpecialFieldValueViewModel> val1, Optional<SpecialFieldValueViewModel> val2) {
if (val1.isPresent()) {
if (val2.isPresent()) {
return val1.get().getValue().compareTo(val2.get().getValue());
} else {
return -1;
}
} else {
if (val2.isPresent()) {
return 1;
} else {
return 0;
}
}
}

}

0 comments on commit d4396ce

Please sign in to comment.