Fixes #2436; PolytomousKeyListView now allows deletion of multiple elements
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / handler / DeleteHandler.java
index a916177ffff382ed476272aa6f752fa7b08619ce..ede0de647847c1f9670a21bb166d2ba9e1951577 100644 (file)
@@ -10,6 +10,8 @@
 
 package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
 
+import java.util.List;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -37,19 +39,27 @@ public class DeleteHandler extends AbstractHandler {
        public Object execute(ExecutionEvent event) throws ExecutionException {
                IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
                
-               PolytomousKey key = (PolytomousKey) selection.getFirstElement();
+               List<PolytomousKey> keys = selection.toList();
+               
+               if(keys.isEmpty()){
+                       return null;
+               }
+               
+               boolean confirmation = NavigationUtil.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keys.size() == 1 ? "" : "s") + "?");
                
-               if(NavigationUtil.confirmDialog("Confirm deletaion", "Do you really want to delete the key: " + key.getTitleCache())){
+               if(confirmation){
                
-                       try {
-                               AbstractPostOperation operation = new DeleteOperation(
-                                               event.getCommand().getName(),
-                                               NavigationUtil.getUndoContext(), key, 
-                                               (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false),
-                                               (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false));
-                               NavigationUtil.executeOperation(operation);
-                       } catch (NotDefinedException e) {
-                               NavigationUtil.error(getClass(), e);
+                       for(PolytomousKey key : keys){
+                               try {
+                                       AbstractPostOperation operation = new DeleteOperation(
+                                                       event.getCommand().getName(),
+                                                       NavigationUtil.getUndoContext(), key, 
+                                                       (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false),
+                                                       (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false));
+                                       NavigationUtil.executeOperation(operation);
+                               } catch (NotDefinedException e) {
+                                       NavigationUtil.error(getClass(), e);
+                               }
                        }
                }