Skip to content

Commit

Permalink
Add New Group Sorting Options (JabRef#10492)
Browse files Browse the repository at this point in the history
* Added new Group Sort options

* Added new Group Sort options

* Fixed Test Cases

* Fixed Test Cases

* Update GroupTreeViewModel.java

Indentation

* properly implemented sort by entries

* code style issue fix

* renamed Methods

---------

Co-authored-by: Carl Christian Snethlage <[email protected]>
  • Loading branch information
Preetish-T and calixtus authored Oct 20, 2023
1 parent cbf99ec commit d13b570
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added the ability to sort subgroups in Z-A order, as well as by ascending and descending number of subgroups. [#10249](https://github.com/JabRef/jabref/issues/10249)
- We added the possibility to find (and add) papers that cite or are cited by a given paper. [#6187](https://github.com/JabRef/jabref/issues/6187)
- We added an error-specific message for when a download from a URL fails. [#9826](https://github.com/JabRef/jabref/issues/9826)
- We added support for customizing the citation command (e.g., `[@key1,@key2]`) when [pushing to external applications](https://docs.jabref.org/cite/pushtoapplications). [#10133](https://github.com/JabRef/jabref/issues/10133)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public enum StandardActions implements Action {
GROUP_SUBGROUP_ADD(Localization.lang("Add subgroup")),
GROUP_SUBGROUP_REMOVE(Localization.lang("Remove subgroups")),
GROUP_SUBGROUP_SORT(Localization.lang("Sort subgroups A-Z")),
GROUP_SUBGROUP_SORT_REVERSE(Localization.lang("Sort subgroups Z-A")),
GROUP_SUBGROUP_SORT_ENTRIES(Localization.lang("Sort subgroups by # of entries (Descending)")),
GROUP_SUBGROUP_SORT_ENTRIES_REVERSE(Localization.lang("Sort subgroups by # of entries (Ascending)")),
GROUP_ENTRIES_ADD(Localization.lang("Add selected entries to this group")),
GROUP_ENTRIES_REMOVE(Localization.lang("Remove selected entries from this group"));

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_ADD, new ContextAction(StandardActions.GROUP_SUBGROUP_ADD, group)),
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_REMOVE, new ContextAction(StandardActions.GROUP_SUBGROUP_REMOVE, group)),
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT, group)),
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_REVERSE, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_REVERSE, group)),
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES, group)),
factory.createMenuItem(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES_REVERSE, new ContextAction(StandardActions.GROUP_SUBGROUP_SORT_ENTRIES_REVERSE, group)),
new SeparatorMenuItem(),
factory.createMenuItem(StandardActions.GROUP_ENTRIES_ADD, new ContextAction(StandardActions.GROUP_ENTRIES_ADD, group)),
factory.createMenuItem(StandardActions.GROUP_ENTRIES_REMOVE, new ContextAction(StandardActions.GROUP_ENTRIES_REMOVE, group))
Expand Down Expand Up @@ -620,6 +623,12 @@ public void execute() {
viewModel.removeSubgroups(group);
case GROUP_SUBGROUP_SORT ->
viewModel.sortAlphabeticallyRecursive(group.getGroupNode());
case GROUP_SUBGROUP_SORT_REVERSE ->
viewModel.sortReverseAlphabeticallyRecursive(group.getGroupNode());
case GROUP_SUBGROUP_SORT_ENTRIES ->
viewModel.sortEntriesRecursive(group.getGroupNode());
case GROUP_SUBGROUP_SORT_ENTRIES_REVERSE ->
viewModel.sortReverseEntriesRecursive(group.getGroupNode());
case GROUP_ENTRIES_ADD ->
viewModel.addSelectedEntries(group);
case GROUP_ENTRIES_REMOVE ->
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public class GroupTreeViewModel extends AbstractViewModel {
private final Comparator<GroupTreeNode> compAlphabetIgnoreCase = (GroupTreeNode v1, GroupTreeNode v2) -> v1
.getName()
.compareToIgnoreCase(v2.getName());
private final Comparator<GroupTreeNode> compAlphabetIgnoreCaseReverse = (GroupTreeNode v1, GroupTreeNode v2) -> v2
.getName()
.compareToIgnoreCase(v1.getName());
private final Comparator<GroupTreeNode> compEntries = (GroupTreeNode v1, GroupTreeNode v2) -> {
int numChildren1 = v1.getEntriesInGroup(this.currentDatabase.get().getEntries()).size();
int numChildren2 = v2.getEntriesInGroup(this.currentDatabase.get().getEntries()).size();
return Integer.compare(numChildren2, numChildren1);
};
private final Comparator<GroupTreeNode> compEntriesReverse = (GroupTreeNode v1, GroupTreeNode v2) -> {
int numChildren1 = v1.getEntriesInGroup(this.currentDatabase.get().getEntries()).size();
int numChildren2 = v2.getEntriesInGroup(this.currentDatabase.get().getEntries()).size();
return Integer.compare(numChildren1, numChildren2);
};
private Optional<BibDatabaseContext> currentDatabase = Optional.empty();

public GroupTreeViewModel(StateManager stateManager, DialogService dialogService, PreferencesService preferencesService, TaskExecutor taskExecutor, CustomLocalDragboard localDragboard) {
Expand Down Expand Up @@ -560,4 +573,16 @@ public void removeSelectedEntries(GroupNodeViewModel group) {
public void sortAlphabeticallyRecursive(GroupTreeNode group) {
group.sortChildren(compAlphabetIgnoreCase, true);
}

public void sortReverseAlphabeticallyRecursive(GroupTreeNode group) {
group.sortChildren(compAlphabetIgnoreCaseReverse, true);
}

public void sortEntriesRecursive(GroupTreeNode group) {
group.sortChildren(compEntries, true);
}

public void sortReverseEntriesRecursive(GroupTreeNode group) {
group.sortChildren(compEntriesReverse, true);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ SourceTab\ error=SourceTab error
User\ input\ via\ entry-editor\ in\ `{}bibtex\ source`\ tab\ led\ to\ failure.=User input via entry-editor in `{}bibtex source` tab led to failure.

Sort\ subgroups\ A-Z=Sort subgroups A-Z
Sort\ subgroups\ Z-A=Sort subgroups Z-A
Sort\ subgroups\ by\ #\ of\ entries\ (Descending)=Sort subgroups by # of entries (Descending)
Sort\ subgroups\ by\ #\ of\ entries\ (Ascending)=Sort subgroups by # of entries (Ascending)

source\ edit=source edit
Special\ name\ formatters=Special name formatters
Expand Down

0 comments on commit d13b570

Please sign in to comment.