From 18d74480d0c9bae1d845f58900dd675155f251a6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 24 Feb 2017 13:34:35 +0100 Subject: [PATCH] Add "Remove group and subgroups" option Issue #1407 is fixed in the process --- CHANGELOG.md | 2 +- .../java/org/jabref/gui/DialogService.java | 14 ++++++++++++-- .../java/org/jabref/gui/FXDialogService.java | 13 +++++++++++-- .../gui/groups/GroupTreeController.java | 4 ++++ .../jabref/gui/groups/GroupTreeViewModel.java | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed83bb94f8d..4e11dae738d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - ArXiV fetcher now checks similarity of entry when using DOI retrieval to avoid false positives [#2575](https://github.com/JabRef/jabref/issues/2575) - Sciencedirect/Elsevier fetcher is now able to scrape new HTML structure [#2576](https://github.com/JabRef/jabref/issues/2576) - Fixed the synchronization logic of keywords and special fields and vice versa [#2580](https://github.com/JabRef/jabref/issues/2580) - + - Fixed a display issue when removing a group with a long name [#1407](https://github.com/JabRef/jabref/issues/1407) ### Removed diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index f9bbf9c5578..117767217e7 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -66,9 +66,19 @@ default void showErrorDialogAndWait(Exception exception) { * a OK and Cancel Button. To create a confirmation dialog with custom * buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)} * - * @return Optional with the pressed Button as ButtonType + * @return true if the use clicked "OK" otherwise false + */ + boolean showConfirmationDialogAndWait(String title, String content); + + /** + * Create and display a new confirmation dialog. + * It will include a blue question icon on the left and + * a OK (with given label) and Cancel Button. To create a confirmation dialog with custom + * buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)} + * + * @return true if the use clicked "OK" otherwise false */ - Optional showConfirmationDialogAndWait(String title, String content); + boolean showConfirmationDialogAndWait(String title, String content, String okButtonLabel); /** * This will create and display a new dialog of the specified diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index 6cd1863fc77..972fb7b2429 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -5,6 +5,7 @@ import java.util.Optional; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; import javafx.scene.control.DialogPane; import javafx.stage.FileChooser; @@ -65,9 +66,17 @@ public void showErrorDialogAndWait(String message) { } @Override - public Optional showConfirmationDialogAndWait(String title, String content) { + public boolean showConfirmationDialogAndWait(String title, String content) { FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content); - return alert.showAndWait(); + return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.OK).isPresent(); + } + + @Override + public boolean showConfirmationDialogAndWait(String title, String content, String okButtonLabel) { + FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content); + ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE); + alert.getButtonTypes().setAll(ButtonType.CANCEL, okButtonType); + return alert.showAndWait().filter(buttonType -> buttonType == okButtonType).isPresent(); } @Override diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeController.java b/src/main/java/org/jabref/gui/groups/GroupTreeController.java index 590a8b76820..6813c4d4cbf 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeController.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeController.java @@ -130,7 +130,11 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { MenuItem addSubgroup = new MenuItem(Localization.lang("Add subgroup")); addSubgroup.setOnAction(event -> viewModel.addNewSubgroup(group)); + MenuItem removeGroupAndSubgroups = new MenuItem(Localization.lang("Remove group and subgroups")); + removeGroupAndSubgroups.setOnAction(event -> viewModel.removeGroupAndSubgroups(group)); + menu.getItems().add(addSubgroup); + menu.getItems().add(removeGroupAndSubgroups); return menu; } diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 6e7ed7e35b1..1f1c4308b26 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -94,4 +94,23 @@ public void addNewSubgroup(GroupNodeViewModel parent) { dialogService.notify(Localization.lang("Added group \"%0\".", group.getName())); }); } + + /** + * Removes the specified group and its subgroups (after asking for confirmation). + */ + public void removeGroupAndSubgroups(GroupNodeViewModel group) { + boolean confirmed = dialogService.showConfirmationDialogAndWait( + Localization.lang("Remove group and subgroups"), + Localization.lang("Remove group \"%0\" and its subgroups?", group.getDisplayName()), + Localization.lang("Remove")); + if (confirmed) { + // TODO: Add undo + //final UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(groupsRoot, node, UndoableAddOrRemoveGroup.REMOVE_NODE_AND_CHILDREN); + //panel.getUndoManager().addEdit(undo); + + group.getGroupNode().removeFromParent(); + + dialogService.notify(Localization.lang("Removed group \"%0\" and its subgroups.", group.getDisplayName())); + } + } }