3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.operation
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
18 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
23 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
26 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
27 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
39 public class DeleteTermBaseOperation
extends AbstractPostTaxonOperation
{
41 private final TermEditorInput definedEditorInput
;
42 private final TermBase termBase
;
43 private DefinedTermEditor definedTermEditor
;
47 * @param postOperationEnabled
49 public DeleteTermBaseOperation(String label
,
50 IUndoContext undoContext
,
52 TermEditorInput definedEditorInput
,
53 IPostOperationEnabled postOperationEnabled
) {
54 super(label
, undoContext
, postOperationEnabled
);
55 this.termBase
= termBase
;
56 this.definedEditorInput
= definedEditorInput
;
60 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
63 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
64 throws ExecutionException
{
68 if (termBase
instanceof TermVocabulary
) {
69 if (((TermVocabulary
)termBase
).getCreatedBy() == null) {
70 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system vocabulary");
71 MessagingUtils
.warningDialog("Cannot delete vocabulary", termBase
, status
);
75 if (!((TermVocabulary
)termBase
).getTerms().isEmpty()) {
76 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");
77 MessagingUtils
.warningDialog("Vocabulary not empty", termBase
, status
);
81 definedEditorInput
.getVocabularies().remove(termBase
);
83 DeleteResult result
= CdmStore
.getService(IVocabularyService
.class).delete(termBase
.getUuid());
84 if (result
.isError()){
85 StringBuffer errorString
= new StringBuffer();
86 for (Exception e
:result
.getExceptions()){
87 errorString
.append(e
.getMessage() + "\\n");
89 MessageDialog
.openError(null, "Delete failed", errorString
.toString());
92 } else if (termBase
instanceof DefinedTermBase
) {
95 DefinedTermBase definedTermBase
= (DefinedTermBase
) termBase
;
97 if (((DefinedTermBase
)termBase
).getCreatedBy() == null) {
98 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system defined term");
99 MessagingUtils
.warningDialog("Cannot delete defined term", termBase
, status
);
102 if(!definedTermBase
.getIncludes().isEmpty()){
103 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");
104 MessagingUtils
.warningDialog("Term has included terms", termBase
, status
);
109 DefinedTermBase partOf
= definedTermBase
.getPartOf();
111 partOf
.removeIncludes(definedTermBase
);
114 DefinedTermBase kindOf
= definedTermBase
.getKindOf();
116 definedTermBase
.removeGeneralization(kindOf
);
119 TermVocabulary vocabulary
= definedTermBase
.getVocabulary();
120 if(vocabulary
!= null){
121 vocabulary
.removeTerm(definedTermBase
);
124 DeleteResult result
= CdmStore
.getService(ITermService
.class).delete(termBase
.getUuid());
126 if (result
.isError()){
127 StringBuffer errorString
= new StringBuffer();
128 for (Exception e
:result
.getExceptions()){
129 errorString
.append(e
.getMessage() + "\\n");
131 MessageDialog
.openError(null, "Delete failed", errorString
.toString());
135 return postExecute(termBase
);
139 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
142 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
143 throws ExecutionException
{
144 // TODO Auto-generated method stub
149 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
152 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
153 throws ExecutionException
{
154 // TODO Auto-generated method stub