latest changes from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / derivate / operation / DeleteDerivateOperation.java
index 5032dde4168c692c542897a6675c5be41ed89a75..b480a0f83cd27dd8cd55c462180f8746a03391f6 100644 (file)
@@ -14,11 +14,14 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.ISaveablePart;
 
 import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -56,17 +59,34 @@ public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
     /** {@inheritDoc} */
     @Override
     public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        if(getPostOperationEnabled() instanceof ISaveablePart){
+            if(!MessagingUtils.confirmDialog("Confirm deletion", "Do you really want to delete the selected element?")){
+                return Status.CANCEL_STATUS;
+            }
+            if(((ISaveablePart) getPostOperationEnabled()).isDirty()){
+                MessagingUtils.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
+                return Status.CANCEL_STATUS;
+            }
+        }
         DeleteResult deleteResult = CdmStore.getService(IOccurrenceService.class).deleteDerivateHierarchy(element, deleteConfigurator);
-        if(!deleteResult.isOk()){
+        if(deleteResult.isOk()){
+            if(getPostOperationEnabled() instanceof DerivateView){
+                DerivateView derivateView = (DerivateView) getPostOperationEnabled();
+                //update DerivateView
+                derivateView.getConversationHolder().commit();
+                return postExecute(null);
+            }
+        }
+        else{
             String exceptionMessage = "";
             for(Exception exception:deleteResult.getExceptions()){
                 exceptionMessage += exception.getLocalizedMessage();
             }
             //TODO: add method to DeleteResult to sum up exceptions
             MessagingUtils.warningDialog("Deletion failed", this, exceptionMessage);
-            return postExecute(null);
+            return Status.CANCEL_STATUS;
         }
-        return postExecute(element);
+        return Status.OK_STATUS;
     }
 
     /*
@@ -79,7 +99,8 @@ public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
     /** {@inheritDoc} */
     @Override
     public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-        return execute(monitor, info);
+        //no redo possible
+        return Status.CANCEL_STATUS ;
     }
 
     /*
@@ -92,6 +113,7 @@ public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
     /** {@inheritDoc} */
     @Override
     public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-        return postExecute(element);
+        //no undo possible
+        return Status.CANCEL_STATUS;
     }
 }