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
.api
.service
.exception
.DataChangeNoRollbackException
;
24 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
25 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
28 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
29 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
40 public class DeleteTermBaseOperation
extends AbstractPostTaxonOperation
{
42 private TermEditorInput definedEditorInput
;
43 private TermBase termBase
;
44 private DefinedTermEditor definedTermEditor
;
48 * @param postOperationEnabled
50 public DeleteTermBaseOperation(String label
,
51 IUndoContext undoContext
,
53 TermEditorInput definedEditorInput
,
54 IPostOperationEnabled postOperationEnabled
) {
55 super(label
, undoContext
, postOperationEnabled
);
56 this.termBase
= termBase
;
57 this.definedEditorInput
= definedEditorInput
;
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
69 if (termBase
instanceof TermVocabulary
) {
70 if (((TermVocabulary
)termBase
).getCreatedBy() == null) {
71 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system vocabulary");
72 StoreUtil
.warningDialog("Cannot delete vocabulary", termBase
, status
);
76 if (!((TermVocabulary
)termBase
).getTerms().isEmpty()) {
77 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");
78 StoreUtil
.warningDialog("Vocabulary not empty", termBase
, status
);
82 definedEditorInput
.getVocabularies().remove((TermVocabulary
)termBase
);
84 DeleteResult result
= CdmStore
.getService(IVocabularyService
.class).delete((TermVocabulary
)termBase
);
85 if (result
.isError()){
86 //TODO: Error message!
89 } else if (termBase
instanceof DefinedTermBase
) {
92 DefinedTermBase definedTermBase
= (DefinedTermBase
) termBase
;
94 if (((DefinedTermBase
)termBase
).getCreatedBy() == null) {
95 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system defined term");
96 StoreUtil
.warningDialog("Cannot delete defined term", termBase
, status
);
99 if(!definedTermBase
.getIncludes().isEmpty()){
100 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");
101 StoreUtil
.warningDialog("Term has included terms", termBase
, status
);
106 DefinedTermBase partOf
= definedTermBase
.getPartOf();
108 partOf
.removeIncludes(definedTermBase
);
111 DefinedTermBase kindOf
= definedTermBase
.getKindOf();
113 definedTermBase
.removeGeneralization(kindOf
);
116 TermVocabulary vocabulary
= definedTermBase
.getVocabulary();
117 if(vocabulary
!= null){
118 vocabulary
.removeTerm(definedTermBase
);
121 DeleteResult result
= CdmStore
.getService(ITermService
.class).delete((DefinedTermBase
)termBase
);
123 if (result
.isError()){
124 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().get(0).getMessage());
128 return postExecute(termBase
);
132 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
135 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
136 throws ExecutionException
{
137 // TODO Auto-generated method stub
142 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
145 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
146 throws ExecutionException
{
147 // TODO Auto-generated method stub