Skip to content

Commit

Permalink
Sorting of read-status isn't working as expected JabRef#4521
Browse files Browse the repository at this point in the history
*Created Comparator for Read Status by adding new class
*Added above comparator to read status column

Signed-off-by: Aman Jain <aman.jain01@sap.com>
  • Loading branch information
Aman Jain committed Dec 13, 2018
1 parent b52c972 commit cfe7bf7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -201,6 +202,11 @@ private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>
column.setComparator(new RankingFieldComparator());
}

// Added comparator for Read Status
if (specialField == SpecialField.READ_STATUS) {
column.setComparator(new ReadStatusFieldComparator());
}

column.setSortable(true);
return column;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Optional<SpecialFieldValueViewModel>> {

@Override
public int compare(Optional<SpecialFieldValueViewModel> val1, Optional<SpecialFieldValueViewModel> 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;
}
}
}

}

0 comments on commit cfe7bf7

Please sign in to comment.