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
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
22 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
25 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
26 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
27 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
28 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
37 public class DeleteTermBaseOperation
extends AbstractPostOperation
{
39 private TermEditorInput definedEditorInput
;
40 private TermBase termBase
;
41 private DefinedTermEditor definedTermEditor
;
45 * @param postOperationEnabled
47 public DeleteTermBaseOperation(String label
,
48 IUndoContext undoContext
,
50 TermEditorInput definedEditorInput
,
51 IPostOperationEnabled postOperationEnabled
) {
52 super(label
, undoContext
, postOperationEnabled
);
53 this.termBase
= termBase
;
54 this.definedEditorInput
= definedEditorInput
;
58 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
62 throws ExecutionException
{
66 if (termBase
instanceof TermVocabulary
) {
67 if (((TermVocabulary
)termBase
).getCreatedBy() == null) {
68 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system vocabulary");
69 StoreUtil
.warningDialog("Cannot delete vocabulary", termBase
, status
);
73 if (!((TermVocabulary
)termBase
).getTerms().isEmpty()) {
74 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");
75 StoreUtil
.warningDialog("Vocabulary not empty", termBase
, status
);
79 definedEditorInput
.getVocabularies().remove((TermVocabulary
)termBase
);
80 CdmStore
.getService(IVocabularyService
.class).delete((TermVocabulary
)termBase
);
83 } else if (termBase
instanceof DefinedTermBase
) {
86 DefinedTermBase definedTermBase
= (DefinedTermBase
) termBase
;
88 if (((DefinedTermBase
)termBase
).getCreatedBy() == null) {
89 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system defined term");
90 StoreUtil
.warningDialog("Cannot delete defined term", termBase
, status
);
93 if(!definedTermBase
.getIncludes().isEmpty()){
94 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");
95 StoreUtil
.warningDialog("Term has included terms", termBase
, status
);
100 DefinedTermBase partOf
= definedTermBase
.getPartOf();
102 partOf
.removeIncludes(definedTermBase
);
105 DefinedTermBase kindOf
= definedTermBase
.getKindOf();
107 definedTermBase
.removeGeneralization(kindOf
);
110 TermVocabulary vocabulary
= definedTermBase
.getVocabulary();
111 if(vocabulary
!= null){
112 vocabulary
.removeTerm(definedTermBase
);
114 CdmStore
.getService(ITermService
.class).delete((DefinedTermBase
)termBase
);
118 return postExecute(termBase
);
122 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
125 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
126 throws ExecutionException
{
127 // TODO Auto-generated method stub
132 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
135 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
136 throws ExecutionException
{
137 // TODO Auto-generated method stub