fixing the deletion of polytomous keys
authorKatja Luther <k.luther@bgbm.org>
Tue, 17 May 2016 12:49:59 +0000 (14:49 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 17 May 2016 12:49:59 +0000 (14:49 +0200)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/RemotingDeletePolytomousKeyHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/PolytomousKeySelectionDialog.java

index 07e8caca4bf020d8a7c44996152382c4090030be..b9107f06bff15fdd98be691b945e1610f704f01e 100644 (file)
@@ -46,7 +46,7 @@ public class DeleteHandler extends AbstractHandler {
                        return null;
                }
 
-               boolean confirmation = MessagingUtils.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keys.size() == 1 ? "" : "s") + "?");
+               boolean confirmation = MessagingUtils.confirmDialog("Confirm deletion", "Do you want to delete the selected key" + (keys.size() == 1 ? "" : "s") + "?");
 
                if(confirmation){
 
index 691cccb16c6f4253ed33643a1500fbef90eb6238..f4eb7d18248d6ee7a34a31064cddc387abb765bd 100644 (file)
@@ -17,8 +17,13 @@ import org.eclipse.core.commands.operations.AbstractOperation;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
 import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RemotingDeletePolytomousKeyOperation;
@@ -58,6 +63,7 @@ public class RemotingDeletePolytomousKeyHandler extends RemotingCdmHandler {
         if(!confirmation) {
             return Status.CANCEL_STATUS;
         }
+        closeObsoleteEditor(event);
         return Status.OK_STATUS;
     }
 
@@ -79,5 +85,27 @@ public class RemotingDeletePolytomousKeyHandler extends RemotingCdmHandler {
         // TODO Auto-generated method stub
 
     }
+    protected boolean closeObsoleteEditor(ExecutionEvent event){
+        boolean result = true;
+        IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+
+        for (IEditorReference ref : activePage.getEditorReferences()) {
+            try {
+                IEditorInput input = ref.getEditorInput();
+                if (input instanceof PolytomousKeyEditorInput) {
+                    UUID uuidForKey = ((PolytomousKeyEditorInput) input).getKey().getUuid();
+                    for (UUID keyUuid :keysToDelete) {
+                        if( uuidForKey.equals(keyUuid)){
+                            result &= activePage.closeEditor(ref.getEditor(false), false);
+                        }
+                    }
+
+                }
+            } catch (PartInitException e) {
+                continue;
+            }
+        }
+        return result;
+    }
 
 }
index 37c0501d01094197d0358f201a20d45e11759291..8accc6c3db16764732fa59db81ddcdf45a788dda 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -33,7 +33,7 @@ public class PolytomousKeySelectionDialog extends
                                "Choose Polytomous Key", false, PolytomousKeySelectionDialog.class.getCanonicalName(), key);
                return getSelectionFromDialog(dialog);
        }
-       
+
        /**
         * @param shell
         * @param conversation
@@ -61,7 +61,7 @@ public class PolytomousKeySelectionDialog extends
         */
        @Override
        protected void initModel() {
-               model = CdmStore.getService(IPolytomousKeyService.class).getUuidAndTitleCache();
+               model = CdmStore.getService(IPolytomousKeyService.class).getUuidAndTitleCache(null, null);
        }
 
        /* (non-Javadoc)