fix for #3998
authorKatja Luther <k.luther@bgbm.org>
Tue, 2 Jun 2015 09:43:50 +0000 (09:43 +0000)
committerKatja Luther <k.luther@bgbm.org>
Tue, 2 Jun 2015 09:43:50 +0000 (09:43 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/handler/DeleteNodeHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java

index f65f3fdc455c9b7e83959049037b0a5af03154e5..4fc42da010535d14387ff4b3c0c0812b3b5c9ac7 100644 (file)
@@ -20,6 +20,9 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
@@ -27,6 +30,7 @@ import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
 import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.DeleteNodeOperation;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * @author n.hoffmann
@@ -46,6 +50,15 @@ public class DeleteNodeHandler extends AbstractHandler {
        public Object execute(ExecutionEvent event) throws ExecutionException {
                IEditorPart editor = HandlerUtil.getActiveEditor(event);
 
+               if (editor.isDirty()){
+                       boolean proceed = MessageDialog.openQuestion(null,
+                                       "Save changes", "You have made changes that must be saved before you can delete the node. Would you like to proceed?");
+                       if (!proceed) {
+                               return null;
+                       }else{
+                               editor.doSave(EditorUtil.getMonitor());
+                       }
+               }
                if (editor instanceof KeyEditor) {
                        IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
                                        .getActiveEditor();
@@ -59,8 +72,8 @@ public class DeleteNodeHandler extends AbstractHandler {
                                        IUndoContext undoContext = EditorUtil.getUndoContext();
 
                                        for (Object element : selection.toArray()) {
-                                               PolytomousKeyNode keyNode = (PolytomousKeyNode) element;
-
+                                               PolytomousKeyNode keyNode = HibernateProxyHelper.deproxy(element, PolytomousKeyNode.class);
+                                               
                                                AbstractPostOperation operation = new DeleteNodeOperation(
                                                                label, undoContext, keyNode, editorPage);
                                                EditorUtil.executeOperation(operation);
index c55cff77a96035aaf81e50f9bc0ece33eb28f7a1..3b4ae0d7ab1d1bcad784e2b7d041f4eabee34ad3 100644 (file)
@@ -52,14 +52,15 @@ public class DeleteNodeOperation extends AbstractPostTaxonOperation {
                controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
                
                IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
+               
                if (node.getChildren().size()>0){
                        if(! MessageDialog.openQuestion(null, "Confirm deletion of children", "The selected node has children, do you want to delete them, too?")) {
-                               service.delete(node, false);
+                               service.delete(node.getUuid(), false);
                        } else{
-                               service.delete(node, true);
+                               service.delete(node.getUuid(), true);
                        }
                } else{
-                       service.delete(node, true);
+                       service.delete(node.getUuid(), true);
                }
                return postExecute(null);
        }