ref #7010 Allow multiple selection for derivative delete handler
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 28 May 2018 07:01:09 +0000 (09:01 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 28 May 2018 07:03:53 +0000 (09:03 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/l10n/messages.properties
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/l10n/messages_de.properties
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java

index 7c10909d8a1c16cdddf7b94a1aa98d2ec848ccde..617a3e81d97d790a93b3bd816519f08053b00937 100644 (file)
@@ -15,7 +15,7 @@ DerivateView_YOU_NEED_TO_SAVE=You need to save before performing this action
 DeleteDerivateOperation_AND_CHILDREN= and its children
 DeleteDerivateOperation_CONFIRM=Confirm Deletion
 DeleteDerivateOperation_DELETE_FAILED=Deletion failed
-DeleteDerivateOperation_REALLY_DELETE=Do you really want to delete the selected element
+DeleteDerivateOperation_REALLY_DELETE=Do you really want to delete the selected elements
 DerivateDropListener_MOVE_TO=Moving "%s" to "%s"
 DerivateViewEditorInput_FAIL_INIT=Failed initializing editor
 DerivateViewEditorInput_NO_ROOT=No root element found\!
index 09874b151895395522f5bc7acf25d94628b0a4f6..088604a11b483d529470cb3ef80820022c0ff207 100644 (file)
@@ -15,7 +15,7 @@ DerivateView_YOU_NEED_TO_SAVE=Sie m
 DeleteDerivateOperation_AND_CHILDREN= (mit Kind-Elementen)
 DeleteDerivateOperation_CONFIRM=Löschen bestätigen
 DeleteDerivateOperation_DELETE_FAILED=Löschen fehlgeschlagen
-DeleteDerivateOperation_REALLY_DELETE=Wollen Sie wirklich das ausgewählte Element löschen
+DeleteDerivateOperation_REALLY_DELETE=Wollen Sie wirklich die ausgewählten Elemente löschen
 DerivateDropListener_MOVE_TO=Verschiebe "%s" nach "%s"
 DerivateViewEditorInput_FAIL_INIT=Initialisierung des Editor fehlgeschlagen
 DerivateViewEditorInput_NO_ROOT=Kein Root-Element gefunden\!
index a4270289adcc80d6d5b847f72aeebdd7b1f6d1af..c012821cd7ccc3b3a05f4e7f7e87c800e682adf5 100644 (file)
@@ -53,13 +53,41 @@ public class DeleteDerivateHandler {
     private SpecimenDeleteConfigurator deleteConfigurator;
 
     @Execute
-    public Object execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode treeNode, ParameterizedCommand command) {
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection, ParameterizedCommand command) {
         deleteConfigurator = new SpecimenDeleteConfigurator();
         if(command.getId().equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DERIVATE_DEEPDELETE)){
             deleteConfigurator.setDeleteChildren(true);
         }
-
         DerivateView derivateView = (DerivateView) part.getObject();
+
+        String confirmationQuestion = Messages.DeleteDerivateOperation_REALLY_DELETE;
+        if(deleteConfigurator.isDeleteChildren()){
+            confirmationQuestion += Messages.DeleteDerivateOperation_AND_CHILDREN;
+        }
+
+        if(derivateView.isDirty()){
+            MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
+            return;
+        }
+        confirmationQuestion += "?"; //$NON-NLS-1$
+        if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, Messages.DeleteDerivateOperation_CONFIRM, confirmationQuestion)){
+            return;
+        }
+
+        if(selection instanceof Object[]){
+            for (Object o : (Object[])selection) {
+                if(o instanceof TreeNode){
+                    delete((TreeNode)o, derivateView);
+                }
+            }
+        }
+        if(selection instanceof TreeNode){
+            delete((TreeNode)selection, derivateView);
+        }
+
+    }
+
+    private void delete(TreeNode treeNode, DerivateView derivateView){
         Object value = treeNode.getValue();
         IStatus allowStatus = allowOperations(derivateView, treeNode);
         if(allowStatus.isOK()) {
@@ -77,8 +105,7 @@ public class DeleteDerivateHandler {
 
             if (!deleteResult.isOk()) {
                 MessagingUtils.warningDialog(Messages.DeleteDerivateOperation_DELETE_FAILED, this, deleteResult.toString());
-
-                return Status.CANCEL_STATUS;
+                return ;
             }
             //broadcast delete result
             EventUtility.postEvent(WorkbenchEventConstants.DELETE_DERIVATIVE, deleteResult);
@@ -87,25 +114,11 @@ public class DeleteDerivateHandler {
                 derivateView.remove(treeNode);
 
             }
-            return Status.OK_STATUS;
         }
-        return null;
+
     }
 
     public IStatus allowOperations(DerivateView derivateView, TreeNode treeNode) {
-        String confirmationQuestion = Messages.DeleteDerivateOperation_REALLY_DELETE;
-        if(deleteConfigurator.isDeleteChildren()){
-            confirmationQuestion += Messages.DeleteDerivateOperation_AND_CHILDREN;
-        }
-
-        if(derivateView.isDirty()){
-            MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
-            return Status.CANCEL_STATUS;
-        }
-        confirmationQuestion += "?"; //$NON-NLS-1$
-        if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, Messages.DeleteDerivateOperation_CONFIRM, confirmationQuestion)){
-            return Status.CANCEL_STATUS;
-        }
         DeleteResult deleteResult;
         Object value = treeNode.getValue();
         if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){
@@ -131,9 +144,10 @@ public class DeleteDerivateHandler {
     }
 
     @CanExecute
-    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node,
+    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
             MHandledMenuItem menuItem){
-        boolean canExecute = node !=null;
+        boolean canExecute = false;
+        canExecute = selection!=null;
         menuItem.setVisible(canExecute);
         return canExecute;
     }
index 2a3ac45471204b220f2d9d095393e2dc3a7e0f3b..919ea5f85cac53b45392b845f35a66379611c1ac 100644 (file)
@@ -650,10 +650,6 @@ public abstract class AbstractUtility {
         Object selectionToSet = selection;
         if(selection.size() == 1){
             selectionToSet = selection.getFirstElement();
-            if (selectionToSet instanceof Object[]){
-                Object[] selectionArray = (Object[])selectionToSet;
-                selectionToSet = selectionArray;
-            }
         }
         else if(!selection.isEmpty()){
             selectionToSet = selection.toArray();