Skip to content

Commit

Permalink
Fix sort by priority (JabRef#6222)
Browse files Browse the repository at this point in the history
  • Loading branch information
dextep committed Apr 9, 2020
1 parent a44305b commit 3c0e365
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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 3c0e365

Please sign in to comment.