// $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
import org.eclipse.core.runtime.IProgressMonitor;\r
import org.eclipse.core.runtime.IStatus;\r
import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
\r
+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.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.operation.AbstractPostOperation;\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
\r
* @date 22 Dec 2011\r
*\r
*/\r
-public class DeleteTermBaseOperation extends AbstractPostOperation {\r
+public class DeleteTermBaseOperation extends AbstractPostTaxonOperation {\r
\r
- private TermBase termBase;\r
+ private final TermEditorInput definedEditorInput;\r
+ private final TermBase termBase;\r
private DefinedTermEditor definedTermEditor;\r
/**\r
* @param label\r
* @param undoContext\r
* @param postOperationEnabled\r
*/\r
- public DeleteTermBaseOperation(String label, IUndoContext undoContext, TermBase termBase,\r
- DefinedTermEditor definedTermEditor) {\r
- super(label, undoContext, definedTermEditor);\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.definedTermEditor = definedTermEditor;\r
+ this.definedEditorInput = definedEditorInput;\r
}\r
\r
/* (non-Javadoc)\r
@Override\r
public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
throws ExecutionException {\r
- \r
- \r
- \r
+\r
+\r
+\r
if (termBase instanceof TermVocabulary) {\r
- \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
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
- StoreUtil.warningDialog("Vocabulary not empty", termBase, status);\r
+ MessagingUtils.warningDialog("Vocabulary not empty", termBase, status);\r
return status;\r
}\r
- definedTermEditor.getInMemoryVocabularies().remove(termBase); \r
- CdmStore.getService(IVocabularyService.class).delete((TermVocabulary)termBase);\r
- \r
+\r
+ definedEditorInput.getVocabularies().remove(termBase);\r
+\r
+ DeleteResult result = CdmStore.getService(IVocabularyService.class).delete(termBase.getUuid());\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
} else if (termBase instanceof DefinedTermBase) {\r
- \r
- \r
+\r
+\r
DefinedTermBase definedTermBase = (DefinedTermBase) termBase;\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
- StoreUtil.warningDialog("Term has included terms", termBase, status);\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
+\r
+\r
DefinedTermBase partOf = definedTermBase.getPartOf();\r
if(partOf != null){\r
partOf.removeIncludes(definedTermBase);\r
}\r
- \r
+\r
DefinedTermBase kindOf = definedTermBase.getKindOf();\r
if(kindOf != null){\r
definedTermBase.removeGeneralization(kindOf);\r
}\r
- \r
+\r
TermVocabulary vocabulary = definedTermBase.getVocabulary();\r
if(vocabulary != null){\r
vocabulary.removeTerm(definedTermBase);\r
}\r
- CdmStore.getService(ITermService.class).delete((DefinedTermBase)termBase);\r
- \r
+\r
+ DeleteResult result = CdmStore.getService(ITermService.class).delete(termBase.getUuid());\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
- \r
+\r
return postExecute(termBase);\r
}\r
\r