From cfe7bf76981f2108d196c86564e74dbd54e71c5d Mon Sep 17 00:00:00 2001 From: Aman Jain Date: Thu, 13 Dec 2018 22:26:41 +0530 Subject: [PATCH 1/3] Sorting of read-status isn't working as expected #4521 *Created Comparator for Read Status by adding new class *Added above comparator to read status column Signed-off-by: Aman Jain --- CHANGELOG.md | 2 +- .../gui/maintable/MainTableColumnFactory.java | 6 ++++ .../comparator/ReadStatusFieldComparator.java | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java 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; + } + } + } + +} From 1a4b73f1991a16395b70288c537687fed8b2f598 Mon Sep 17 00:00:00 2001 From: Aman Jain Date: Fri, 14 Dec 2018 08:45:47 +0530 Subject: [PATCH 2/3] Update CHANGELOG.md Remove redundant code in ReadStatusFieldComparator.java as suggested Signed-off-by: Aman Jain --- CHANGELOG.md | 1 - .../gui/util/comparator/ReadStatusFieldComparator.java | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84895e45bc8..054ae472b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,7 +88,6 @@ 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/util/comparator/ReadStatusFieldComparator.java b/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java index f0c3ddc5edc..d4317cd7464 100644 --- a/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java +++ b/src/main/java/org/jabref/gui/util/comparator/ReadStatusFieldComparator.java @@ -11,12 +11,7 @@ public class ReadStatusFieldComparator implements Comparator 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; - } + return val1.get().getValue().compareTo(val2.get().getValue()); } else { return -1; } From 9d932bc8d2ed280147c7a8076e091d01f3228848 Mon Sep 17 00:00:00 2001 From: aman-coolinc1 Date: Fri, 14 Dec 2018 08:52:12 +0530 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 054ae472b92..09ee0dd7875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# + ### Removed - The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group. - The number column was removed.