From d4396ce4de0c796a6b40b1b63351a011c715594d Mon Sep 17 00:00:00 2001 From: Grzegorz Popiel Date: Fri, 10 Apr 2020 21:26:45 +0200 Subject: [PATCH] Fix sort by priority (#6222) (#6265) * Fix sort by priority (#6222) * Change in CHANGELOG. --- CHANGELOG.md | 1 + .../gui/maintable/MainTableColumnFactory.java | 5 ++++ .../comparator/PriorityFieldComparator.java | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/main/java/org/jabref/gui/util/comparator/PriorityFieldComparator.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c49eaed2b1..7b63f3508ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index bde67b260aa..a821e343d01 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -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; @@ -316,6 +317,10 @@ private TableColumn column.setComparator(new ReadStatusFieldComparator()); } + if (specialField == SpecialField.PRIORITY) { + column.setComparator(new PriorityFieldComparator()); + } + column.setSortable(true); return column; diff --git a/src/main/java/org/jabref/gui/util/comparator/PriorityFieldComparator.java b/src/main/java/org/jabref/gui/util/comparator/PriorityFieldComparator.java new file mode 100644 index 00000000000..d9ab62e1cc3 --- /dev/null +++ b/src/main/java/org/jabref/gui/util/comparator/PriorityFieldComparator.java @@ -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> { + + @Override + public int compare(Optional val1, Optional 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; + } + } + } + +}