1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.definedterm.operation;
|
10
|
|
11
|
import org.eclipse.core.commands.ExecutionException;
|
12
|
import org.eclipse.core.commands.operations.IUndoContext;
|
13
|
import org.eclipse.core.runtime.IAdaptable;
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.core.runtime.Status;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
19
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
20
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
21
|
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
|
22
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
23
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
24
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
27
|
|
28
|
/**
|
29
|
* @author l.morris
|
30
|
* @date 21 Dec 2011
|
31
|
*
|
32
|
*/
|
33
|
public class CreateDefinedTermOperation extends AbstractPostTaxonOperation {
|
34
|
|
35
|
|
36
|
|
37
|
private final TermBase parentTermBase;
|
38
|
private final TermEditorInput definedTermInput;
|
39
|
private boolean addTermAsKindOf;
|
40
|
|
41
|
|
42
|
/**
|
43
|
* @param label
|
44
|
* @param undoContext
|
45
|
* @param postOperationEnabled
|
46
|
* @param addTermAsKindOf
|
47
|
*/
|
48
|
public CreateDefinedTermOperation(String label,
|
49
|
IUndoContext undoContext,
|
50
|
TermBase termBase,
|
51
|
TermEditorInput definedTermInput,
|
52
|
IPostOperationEnabled postOperationEnabled, boolean addTermAsKindOf) {
|
53
|
super(label, undoContext, postOperationEnabled);
|
54
|
this.parentTermBase = termBase;
|
55
|
this.definedTermInput = definedTermInput;
|
56
|
this.addTermAsKindOf = addTermAsKindOf;
|
57
|
}
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
61
|
*/
|
62
|
@Override
|
63
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
64
|
throws ExecutionException {
|
65
|
|
66
|
DefinedTermBase newTerm = definedTermInput.getTermType().getEmptyDefinedTermBase();
|
67
|
if (newTerm == null) {
|
68
|
IStatus status =
|
69
|
new Status(IStatus.CANCEL,
|
70
|
StoreUtil.getPluginId(),
|
71
|
"Creation of term corresponding to type '" + definedTermInput.getTermType().getMessage() + "' is not yet supported");
|
72
|
MessagingUtils.warningDialog("Cannot create term", newTerm, status);
|
73
|
return status;
|
74
|
}
|
75
|
newTerm = CdmStore.getCurrentApplicationConfiguration().getTermService().save(newTerm);
|
76
|
|
77
|
if (parentTermBase instanceof TermVocabulary){
|
78
|
TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
|
79
|
vocabulary.addTerm(newTerm);
|
80
|
} else if (parentTermBase instanceof DefinedTermBase) {
|
81
|
DefinedTermBase parent = (DefinedTermBase) parentTermBase;
|
82
|
if(addTermAsKindOf){
|
83
|
parent.addGeneralizationOf(newTerm);
|
84
|
}
|
85
|
else{
|
86
|
parent.addIncludes(newTerm);
|
87
|
}
|
88
|
TermVocabulary vocabulary = parent.getVocabulary();
|
89
|
vocabulary.addTerm(newTerm);
|
90
|
}
|
91
|
|
92
|
return postExecute(newTerm);
|
93
|
}
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
97
|
*/
|
98
|
@Override
|
99
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
100
|
throws ExecutionException {
|
101
|
// TODO Auto-generated method stub
|
102
|
return null;
|
103
|
}
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
107
|
*/
|
108
|
@Override
|
109
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
110
|
throws ExecutionException {
|
111
|
// TODO Auto-generated method stub
|
112
|
return null;
|
113
|
}
|
114
|
|
115
|
}
|