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
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
41 public class DeleteTermBaseOperation
extends AbstractPostTaxonOperation
{
43 private TermEditorInput definedEditorInput
;
44 private TermBase termBase
;
45 private DefinedTermEditor definedTermEditor
;
49 * @param postOperationEnabled
51 public DeleteTermBaseOperation(String label
,
52 IUndoContext undoContext
,
54 TermEditorInput definedEditorInput
,
55 IPostOperationEnabled postOperationEnabled
) {
56 super(label
, undoContext
, postOperationEnabled
);
57 this.termBase
= termBase
;
58 this.definedEditorInput
= definedEditorInput
;
62 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
65 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
66 throws ExecutionException
{
70 if (termBase
instanceof TermVocabulary
) {
71 if (((TermVocabulary
)termBase
).getCreatedBy() == null) {
72 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system vocabulary");
73 MessagingUtils
.warningDialog("Cannot delete vocabulary", termBase
, status
);
77 if (!((TermVocabulary
)termBase
).getTerms().isEmpty()) {
78 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");
79 MessagingUtils
.warningDialog("Vocabulary not empty", termBase
, status
);
83 definedEditorInput
.getVocabularies().remove((TermVocabulary
)termBase
);
85 DeleteResult result
= CdmStore
.getService(IVocabularyService
.class).delete((TermVocabulary
)termBase
);
86 if (result
.isError()){
87 //TODO: Error message!
90 } else if (termBase
instanceof DefinedTermBase
) {
93 DefinedTermBase definedTermBase
= (DefinedTermBase
) termBase
;
95 if (((DefinedTermBase
)termBase
).getCreatedBy() == null) {
96 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This is a CDM system defined term");
97 MessagingUtils
.warningDialog("Cannot delete defined term", termBase
, status
);
100 if(!definedTermBase
.getIncludes().isEmpty()){
101 IStatus status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");
102 MessagingUtils
.warningDialog("Term has included terms", termBase
, status
);
107 DefinedTermBase partOf
= definedTermBase
.getPartOf();
109 partOf
.removeIncludes(definedTermBase
);
112 DefinedTermBase kindOf
= definedTermBase
.getKindOf();
114 definedTermBase
.removeGeneralization(kindOf
);
117 TermVocabulary vocabulary
= definedTermBase
.getVocabulary();
118 if(vocabulary
!= null){
119 vocabulary
.removeTerm(definedTermBase
);
122 DeleteResult result
= CdmStore
.getService(ITermService
.class).delete((DefinedTermBase
)termBase
);
124 if (result
.isError()){
125 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().get(0).getMessage());
129 return postExecute(termBase
);
133 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
136 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
137 throws ExecutionException
{
138 // TODO Auto-generated method stub
143 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
146 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
147 throws ExecutionException
{
148 // TODO Auto-generated method stub