Skip to content

Commit

Permalink
Add sorting of all groups and subgroups, recursively (#2666)
Browse files Browse the repository at this point in the history
* Add sorting of all groups and subgroups, recursively
For #2599

* Fix formattiong

* Change localization

* change localilaztion

* Add sort subgroups recursively
  • Loading branch information
Siedlerchr authored Apr 7, 2017
1 parent 8f3f526 commit c2fe388
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupTreeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
MenuItem removeEntries = new MenuItem(Localization.lang("Remove selected entries from this group"));
removeSubgroups.setOnAction(event -> viewModel.removeSelectedEntries(group));

MenuItem sortAlphabetically = new MenuItem(Localization.lang("Sort all subgroups (recursively)"));
sortAlphabetically.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group));

menu.getItems().add(editGroup);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().addAll(addSubgroup, removeSubgroups, removeGroupAndSubgroups, removeGroupKeepSubgroups);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().addAll(addEntries, removeEntries);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().add(sortAlphabetically);

return menu;
}

Expand Down
33 changes: 22 additions & 11 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.groups;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -33,18 +34,23 @@ public class GroupTreeViewModel extends AbstractViewModel {
private final ObjectProperty<Predicate<GroupNodeViewModel>> filterPredicate = new SimpleObjectProperty<>();
private final StringProperty filterText = new SimpleStringProperty();
private Optional<BibDatabaseContext> currentDatabase;
private final Comparator<GroupTreeNode> compAlphabetIgnoreCase = (GroupTreeNode v1, GroupTreeNode v2) -> v1
.getName()
.compareToIgnoreCase(v2.getName());

public GroupTreeViewModel(StateManager stateManager, DialogService dialogService, TaskExecutor taskExecutor) {
this.stateManager = Objects.requireNonNull(stateManager);
this.dialogService = Objects.requireNonNull(dialogService);
this.taskExecutor = Objects.requireNonNull(taskExecutor);

// Register listener
stateManager.activeDatabaseProperty().addListener((observable, oldValue, newValue) -> onActiveDatabaseChanged(newValue));
stateManager.activeDatabaseProperty()
.addListener((observable, oldValue, newValue) -> onActiveDatabaseChanged(newValue));
selectedGroup.addListener((observable, oldValue, newValue) -> onSelectedGroupChanged(newValue));

// Set-up bindings
filterPredicate.bind(Bindings.createObjectBinding(() -> group -> group.isMatchedBy(filterText.get()), filterText));
filterPredicate
.bind(Bindings.createObjectBinding(() -> group -> group.isMatchedBy(filterText.get()), filterText));

// Init
onActiveDatabaseChanged(stateManager.activeDatabaseProperty().getValue());
Expand Down Expand Up @@ -106,7 +112,8 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {

rootGroup.setValue(newRoot);
stateManager.getSelectedGroup(newDatabase.get()).ifPresent(
selectedGroup -> this.selectedGroup.setValue(new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup)));
selectedGroup -> this.selectedGroup.setValue(
new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup)));
}

currentDatabase = newDatabase;
Expand Down Expand Up @@ -135,19 +142,19 @@ public void addNewSubgroup(GroupNodeViewModel parent) {
* Opens "Edit Group Dialog" and changes the given group to the edited one.
*/
public void editGroup(GroupNodeViewModel oldGroup) {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup()));
Optional<AbstractGroup> newGroup = dialogService
.showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup()));
newGroup.ifPresent(group -> {

// TODO: Keep assignments
boolean keepPreviousAssignments = dialogService.showConfirmationDialogAndWait(
Localization.lang("Change of Grouping Method"),
Localization.lang("Assign the original group's entries to this group?"));
// WarnAssignmentSideEffects.warnAssignmentSideEffects(newGroup, panel.frame());
boolean removePreviousAssignents =
(oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup) && (group instanceof ExplicitGroup);
boolean removePreviousAssignents = (oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup)
&& (group instanceof ExplicitGroup);

List<FieldChange> addChange = oldGroup.
getGroupNode().setGroup(
List<FieldChange> addChange = oldGroup.getGroupNode().setGroup(
group,
keepPreviousAssignments,
removePreviousAssignents,
Expand Down Expand Up @@ -197,15 +204,14 @@ public void removeGroupKeepSubgroups(GroupNodeViewModel group) {
//final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_KEEP_CHILDREN);
//panel.getUndoManager().addEdit(undo);
GroupTreeNode groupNode = group.getGroupNode();
groupNode.getParent().ifPresent(parent ->
groupNode.moveAllChildrenTo(parent, parent.getIndexOfChild(groupNode).get()));
groupNode.getParent()
.ifPresent(parent -> groupNode.moveAllChildrenTo(parent, parent.getIndexOfChild(groupNode).get()));
groupNode.removeFromParent();

dialogService.notify(Localization.lang("Removed group \"%0\".", group.getDisplayName()));
}
}


/**
* Removes the specified group and its subgroups (after asking for confirmation).
*/
Expand Down Expand Up @@ -249,4 +255,9 @@ public void removeSelectedEntries(GroupNodeViewModel group) {
// if (!undo.isEmpty()) {
// mPanel.getUndoManager().addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(mNode, undo));
}

public void sortAlphabeticallyRecursive(GroupNodeViewModel group) {
group.getGroupNode().sortChildren(compAlphabetIgnoreCase, true);

}
}
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/groups/GroupsTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public GroupsTree(GroupSelector groupSelector) {
getSelectionModel().setSelectionMode(
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
this.setFocusable(true);

}

/** Highlights the specified cell or disables highlight if cell == null */
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/jabref/model/groups/AbstractGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ public String toString() {
'}';
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if ((other == null) || (getClass() != other.getClass())) {
return false;
}
AbstractGroup that = (AbstractGroup) other;
return Objects.equals(this.name, that.name) && Objects.equals(this.description, that.description)
&& Objects.equals(this.context, that.context);
}

@Override
public int hashCode() {
return Objects.hash(name, description, context);
}

public Optional<Color> getColor() {
return color;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=Unterstriche_maskieren
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=Escape_underscores
Color=Color
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.

Sort_all_subgroups_(recursively)=Sort_all_subgroups_(recursively)
Collect_and_share_telemetry_data_to_help_improve_JabRef.=Collect_and_share_telemetry_data_to_help_improve_JabRef.
Don't_share=Don't_share
Share_anonymous_statistics=Share_anonymous_statistics
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=Echapper_les_soulignements
Color=Couleur
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=S'il_vous_plaît,_Ajouter_si_possible_toutes_les_étapes_permettant_de_reproduire_cette_anomalie.

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=Maskera_understreck
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ Escape_underscores=
Color=
Please_also_add_all_steps_to_reproduce_this_issue,_if_possible.=

Sort_all_subgroups_(recursively)=
Collect_and_share_telemetry_data_to_help_improve_JabRef.=
Don't_share=
Share_anonymous_statistics=
Expand Down

0 comments on commit c2fe388

Please sign in to comment.