From a4fdd5a47730afab5467f8221237b27f4a7b04bf Mon Sep 17 00:00:00 2001 From: Tobias Boceck Date: Tue, 11 Apr 2017 22:25:05 +0200 Subject: [PATCH] Fixed freeze on Mac OS X when creating/editing groups (#2727) * Fixed freeze on Mac OS X when creating/editing groups - also fixed wrong actions on groups menu items * hopefully fix import order --- .../gui/groups/GroupTreeController.java | 4 +- .../jabref/gui/groups/GroupTreeViewModel.java | 99 ++++++++++--------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeController.java b/src/main/java/org/jabref/gui/groups/GroupTreeController.java index fe431a5e7d6..471f2c1a2f2 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeController.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeController.java @@ -238,9 +238,9 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { removeSubgroups.setOnAction(event -> viewModel.removeSubgroups(group)); MenuItem addEntries = new MenuItem(Localization.lang("Add selected entries to this group")); - removeSubgroups.setOnAction(event -> viewModel.addSelectedEntries(group)); + addEntries.setOnAction(event -> viewModel.addSelectedEntries(group)); MenuItem removeEntries = new MenuItem(Localization.lang("Remove selected entries from this group")); - removeSubgroups.setOnAction(event -> viewModel.removeSelectedEntries(group)); + removeEntries.setOnAction(event -> viewModel.removeSelectedEntries(group)); MenuItem sortAlphabetically = new MenuItem(Localization.lang("Sort all subgroups (recursively)")); sortAlphabetically.setOnAction(event -> viewModel.sortAlphabeticallyRecursive(group)); diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index a1e60939d1e..adab6abb7dd 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -6,6 +6,9 @@ import java.util.Optional; import java.util.function.Predicate; +import javax.swing.SwingUtilities; + +import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; @@ -123,18 +126,20 @@ private void onActiveDatabaseChanged(Optional newDatabase) { * Opens "New Group Dialog" and add the resulting group to the specified group */ public void addNewSubgroup(GroupNodeViewModel parent) { - Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialog()); - newGroup.ifPresent(group -> { - GroupTreeNode newGroupNode = parent.addSubgroup(group); + SwingUtilities.invokeLater(() -> { + Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialog()); + newGroup.ifPresent(group -> { + GroupTreeNode newGroupNode = parent.addSubgroup(group); - // TODO: Add undo - //UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(parent, new GroupTreeNodeViewModel(newGroupNode), UndoableAddOrRemoveGroup.ADD_NODE); - //panel.getUndoManager().addEdit(undo); + // TODO: Add undo + //UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(parent, new GroupTreeNodeViewModel(newGroupNode), UndoableAddOrRemoveGroup.ADD_NODE); + //panel.getUndoManager().addEdit(undo); - // TODO: Expand parent to make new group visible - //parent.expand(); + // TODO: Expand parent to make new group visible + //parent.expand(); - dialogService.notify(Localization.lang("Added group \"%0\".", group.getName())); + dialogService.notify(Localization.lang("Added group \"%0\".", group.getName())); + }); }); } @@ -142,42 +147,46 @@ public void addNewSubgroup(GroupNodeViewModel parent) { * Opens "Edit Group Dialog" and changes the given group to the edited one. */ public void editGroup(GroupNodeViewModel oldGroup) { - Optional 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); - - List addChange = oldGroup.getGroupNode().setGroup( - group, - keepPreviousAssignments, - removePreviousAssignents, - stateManager.getEntriesInCurrentDatabase()); - - // TODO: Add undo - // Store undo information. - // AbstractUndoableEdit undoAddPreviousEntries = null; - // UndoableModifyGroup undo = new UndoableModifyGroup(GroupSelector.this, groupsRoot, node, newGroup); - // if (undoAddPreviousEntries == null) { - // panel.getUndoManager().addEdit(undo); - //} else { - // NamedCompound nc = new NamedCompound("Modify Group"); - // nc.addEdit(undo); - // nc.addEdit(undoAddPreviousEntries); - // nc.end();/ - // panel.getUndoManager().addEdit(nc); - //} - //if (!addChange.isEmpty()) { - // undoAddPreviousEntries = UndoableChangeEntriesOfGroup.getUndoableEdit(null, addChange); - //} - - dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName())); + SwingUtilities.invokeLater(() -> { + Optional newGroup = dialogService + .showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup())); + newGroup.ifPresent(group -> { + + Platform.runLater(() -> { + // 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); + + List addChange = oldGroup.getGroupNode().setGroup( + group, + keepPreviousAssignments, + removePreviousAssignents, + stateManager.getEntriesInCurrentDatabase()); + + // TODO: Add undo + // Store undo information. + // AbstractUndoableEdit undoAddPreviousEntries = null; + // UndoableModifyGroup undo = new UndoableModifyGroup(GroupSelector.this, groupsRoot, node, newGroup); + // if (undoAddPreviousEntries == null) { + // panel.getUndoManager().addEdit(undo); + //} else { + // NamedCompound nc = new NamedCompound("Modify Group"); + // nc.addEdit(undo); + // nc.addEdit(undoAddPreviousEntries); + // nc.end();/ + // panel.getUndoManager().addEdit(nc); + //} + //if (!addChange.isEmpty()) { + // undoAddPreviousEntries = UndoableChangeEntriesOfGroup.getUndoableEdit(null, addChange); + //} + + dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName())); + }); + }); }); }