add button to select default source in distribution editor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / operation / DeleteTermBaseOperation.java
index 043332141b11245bd21714525c6e8b070aa65639..88ad2da27aa7d06e9b871469782aa1fcf65e8bae 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$\r
 /**\r
 * Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
 * http://www.e-taxonomy.eu\r
-* \r
+*\r
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
@@ -20,18 +19,16 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import eu.etaxonomy.cdm.api.service.DeleteResult;\r
 import eu.etaxonomy.cdm.api.service.ITermService;\r
 import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
-import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;\r
-import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
 import eu.etaxonomy.cdm.model.common.TermBase;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;\r
 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;\r
 import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;\r
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
 import eu.etaxonomy.taxeditor.store.StoreUtil;\r
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;\r
 \r
 /**\r
  * @author l.morris\r
@@ -40,106 +37,92 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  */\r
 public class DeleteTermBaseOperation extends AbstractPostTaxonOperation {\r
 \r
-       private TermEditorInput definedEditorInput;\r
-       private TermBase termBase;\r
-       private DefinedTermEditor definedTermEditor;\r
-       /**\r
-        * @param label\r
-        * @param undoContext\r
-        * @param postOperationEnabled\r
-        */\r
-       public DeleteTermBaseOperation(String label, \r
-                       IUndoContext undoContext, \r
+       private final TermEditorInput definedEditorInput;\r
+       private final TermBase termBase;\r
+\r
+       public DeleteTermBaseOperation(String label,\r
+                       IUndoContext undoContext,\r
                        TermBase termBase,\r
                        TermEditorInput definedEditorInput,\r
                        IPostOperationEnabled postOperationEnabled) {\r
                super(label, undoContext, postOperationEnabled);\r
                this.termBase = termBase;\r
-               this.definedEditorInput = definedEditorInput;           \r
+               this.definedEditorInput = definedEditorInput;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
-               \r
-               \r
-               \r
                if (termBase instanceof TermVocabulary) {\r
                        if (((TermVocabulary)termBase).getCreatedBy() == null) {\r
                                IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This is a CDM system vocabulary");\r
                                MessagingUtils.warningDialog("Cannot delete vocabulary", termBase, status);\r
                                return status;\r
                        }\r
-                       \r
+\r
                        if (!((TermVocabulary)termBase).getTerms().isEmpty()) {\r
                                IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");\r
                                MessagingUtils.warningDialog("Vocabulary not empty", termBase, status);\r
                                return status;\r
-                       }                       \r
-\r
-                       definedEditorInput.getVocabularies().remove((TermVocabulary)termBase); \r
-                       \r
-                       DeleteResult result =   CdmStore.getService(IVocabularyService.class).delete((TermVocabulary)termBase);\r
-                       if (result.isError()){\r
-                               StringBuffer errorString = new StringBuffer();\r
-                               for (Exception e:result.getExceptions()){\r
-                                       errorString.append(e.getMessage() + "\\n");\r
-                               }\r
-                               MessageDialog.openError(null, "Delete failed", errorString.toString());\r
                        }\r
-                       \r
+\r
+                       definedEditorInput.getVocabularies().remove(termBase);\r
+\r
+                       DeleteResult result =   CdmStore.getService(IVocabularyService.class).delete(termBase.getUuid());\r
+                       if (!result.isOk()){\r
+                StringBuffer errorString = new StringBuffer();\r
+                for (Exception e:result.getExceptions()){\r
+                    errorString.append(e.getMessage() + System.lineSeparator());\r
+                }\r
+                if (result.isAbort()){\r
+                    MessageDialog.openWarning(null, "Delete failed", errorString.toString());\r
+                }else{\r
+                    if (result.getExceptions().iterator().hasNext()){\r
+                        MessagingUtils.errorDialog("Delete failed", this.getClass(),null, TaxeditorStorePlugin.PLUGIN_ID, result.getExceptions().iterator().next(), true);\r
+                    }else{\r
+                        MessageDialog.openWarning(null, "Delete failed", errorString.toString());\r
+                    }\r
+                }\r
+            }\r
+\r
                } else if (termBase instanceof DefinedTermBase) {\r
-                       \r
-                       \r
+\r
+\r
                        DefinedTermBase definedTermBase = (DefinedTermBase) termBase;\r
-                       \r
+\r
                        if (((DefinedTermBase)termBase).getCreatedBy() == null) {\r
                                IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This is a CDM system defined term");\r
                                MessagingUtils.warningDialog("Cannot delete defined term", termBase, status);\r
                                return status;\r
                        }\r
                        if(!definedTermBase.getIncludes().isEmpty()){\r
-                               IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");                            \r
+                               IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");\r
                                MessagingUtils.warningDialog("Term has included terms", termBase, status);\r
                                return status;\r
-                       } \r
-                                               \r
-\r
-                       DefinedTermBase partOf = definedTermBase.getPartOf();\r
-                       if(partOf != null){\r
-                               partOf.removeIncludes(definedTermBase);\r
-                       }\r
-                       \r
-                       DefinedTermBase kindOf = definedTermBase.getKindOf();\r
-                       if(kindOf != null){\r
-                               definedTermBase.removeGeneralization(kindOf);\r
-                       }\r
-                       \r
-                       TermVocabulary vocabulary = definedTermBase.getVocabulary();\r
-                       if(vocabulary != null){\r
-                               vocabulary.removeTerm(definedTermBase);\r
-                       }\r
-                       \r
-                       DeleteResult result =   CdmStore.getService(ITermService.class).delete((DefinedTermBase)termBase);\r
-                       \r
-                       if (result.isError()){\r
-                               StringBuffer errorString = new StringBuffer();\r
-                               for (Exception e:result.getExceptions()){\r
-                                       errorString.append(e.getMessage() + "\\n");\r
-                               }\r
-                               MessageDialog.openError(null, "Delete failed", errorString.toString());\r
                        }\r
+\r
+                       DeleteResult result =   CdmStore.getService(ITermService.class).delete(termBase.getUuid());\r
+\r
+                       if (!result.isOk()){\r
+                StringBuffer errorString = new StringBuffer();\r
+                for (Exception e:result.getExceptions()){\r
+                    errorString.append(e.getMessage() + System.lineSeparator());\r
+                }\r
+                if (result.isAbort()){\r
+                    MessageDialog.openWarning(null, "Delete failed", errorString.toString());\r
+                }else{\r
+                    if (result.getExceptions().iterator().hasNext()){\r
+                        MessagingUtils.errorDialog("Delete failed", this.getClass(),null, TaxeditorStorePlugin.PLUGIN_ID, result.getExceptions().iterator().next(), true);\r
+                    }else{\r
+                        MessageDialog.openWarning(null, "Delete failed", errorString.toString());\r
+                    }\r
+                }\r
+            }\r
                }\r
-               \r
+\r
                return postExecute(termBase);\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
@@ -147,9 +130,6 @@ public class DeleteTermBaseOperation extends AbstractPostTaxonOperation {
                return null;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r