diff --git a/CHANGELOG.md b/CHANGELOG.md index 09ee0dd7875..84895e45bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,7 +88,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the ArXiv Fetcher did not support HTTP URLs [koppor#328](https://github.com/koppor/jabref/issues/328) - We fixed an issue where only one PDF file could be imported [#4422](https://github.com/JabRef/jabref/issues/4422) - We fixed an issue where "Move to group" would always move the first entry in the library and not the selected [#4414](https://github.com/JabRef/jabref/issues/4414) - +- We fixed an issue to support sorting using Read Status(Sorting of read-status isn't working as expected #4521) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index ff343bc16c4..6133fc9c5e3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -35,6 +35,7 @@ import org.jabref.gui.util.OptionalValueTableCellFactory; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.gui.util.comparator.RankingFieldComparator; +import org.jabref.gui.util.comparator.ReadStatusFieldComparator; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -201,6 +202,11 @@ private TableColumn column.setComparator(new RankingFieldComparator()); } + // Added comparator for Read Status + if (specialField == SpecialField.READ_STATUS) { + column.setComparator(new ReadStatusFieldComparator()); + } + column.setSortable(true); return column; } diff --git a/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java b/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java new file mode 100644 index 00000000000..f0c3ddc5edc --- /dev/null +++ b/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java @@ -0,0 +1,32 @@ +package org.jabref.gui.util.comparator; + +import java.util.Comparator; +import java.util.Optional; + +import org.jabref.gui.specialfields.SpecialFieldValueViewModel; + +public class ReadStatusFieldComparator implements Comparator> { + + @Override + public int compare(Optional val1, Optional val2) { + if (val1.isPresent()) { + if (val2.isPresent()) { + int compareToRes = val1.get().getValue().compareTo(val2.get().getValue()); + if (compareToRes == 0) { + return 0; + } else { + return compareToRes * 1; + } + } else { + return -1; + } + } else { + if (val2.isPresent()) { + return 1; + } else { + return 0; + } + } + } + +}