1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.definedterm.operation;
|
11
|
|
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
|
|
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;
|
31
|
|
32
|
/**
|
33
|
* @author l.morris
|
34
|
* @date 22 Dec 2011
|
35
|
*
|
36
|
*/
|
37
|
public class DeleteTermBaseOperation extends AbstractPostOperation {
|
38
|
|
39
|
private TermEditorInput definedEditorInput;
|
40
|
private TermBase termBase;
|
41
|
private DefinedTermEditor definedTermEditor;
|
42
|
/**
|
43
|
* @param label
|
44
|
* @param undoContext
|
45
|
* @param postOperationEnabled
|
46
|
*/
|
47
|
public DeleteTermBaseOperation(String label,
|
48
|
IUndoContext undoContext,
|
49
|
TermBase termBase,
|
50
|
TermEditorInput definedEditorInput,
|
51
|
IPostOperationEnabled postOperationEnabled) {
|
52
|
super(label, undoContext, postOperationEnabled);
|
53
|
this.termBase = termBase;
|
54
|
this.definedEditorInput = definedEditorInput;
|
55
|
}
|
56
|
|
57
|
/* (non-Javadoc)
|
58
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
59
|
*/
|
60
|
@Override
|
61
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
62
|
throws ExecutionException {
|
63
|
|
64
|
|
65
|
|
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);
|
70
|
return status;
|
71
|
}
|
72
|
|
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);
|
76
|
return status;
|
77
|
}
|
78
|
|
79
|
definedEditorInput.getVocabularies().remove((TermVocabulary)termBase);
|
80
|
CdmStore.getService(IVocabularyService.class).delete((TermVocabulary)termBase);
|
81
|
|
82
|
|
83
|
} else if (termBase instanceof DefinedTermBase) {
|
84
|
|
85
|
|
86
|
DefinedTermBase definedTermBase = (DefinedTermBase) termBase;
|
87
|
|
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);
|
91
|
return status;
|
92
|
}
|
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);
|
96
|
return status;
|
97
|
}
|
98
|
|
99
|
|
100
|
DefinedTermBase partOf = definedTermBase.getPartOf();
|
101
|
if(partOf != null){
|
102
|
partOf.removeIncludes(definedTermBase);
|
103
|
}
|
104
|
|
105
|
DefinedTermBase kindOf = definedTermBase.getKindOf();
|
106
|
if(kindOf != null){
|
107
|
definedTermBase.removeGeneralization(kindOf);
|
108
|
}
|
109
|
|
110
|
TermVocabulary vocabulary = definedTermBase.getVocabulary();
|
111
|
if(vocabulary != null){
|
112
|
vocabulary.removeTerm(definedTermBase);
|
113
|
}
|
114
|
CdmStore.getService(ITermService.class).delete((DefinedTermBase)termBase);
|
115
|
|
116
|
}
|
117
|
|
118
|
return postExecute(termBase);
|
119
|
}
|
120
|
|
121
|
/* (non-Javadoc)
|
122
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
123
|
*/
|
124
|
@Override
|
125
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
126
|
throws ExecutionException {
|
127
|
// TODO Auto-generated method stub
|
128
|
return null;
|
129
|
}
|
130
|
|
131
|
/* (non-Javadoc)
|
132
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
133
|
*/
|
134
|
@Override
|
135
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
136
|
throws ExecutionException {
|
137
|
// TODO Auto-generated method stub
|
138
|
return null;
|
139
|
}
|
140
|
|
141
|
}
|