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.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
20
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
22
|
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
|
23
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
24
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
28
|
|
29
|
/**
|
30
|
* @author l.morris
|
31
|
* @date 21 Dec 2011
|
32
|
*
|
33
|
*/
|
34
|
public class CreateDefinedTermOperation extends AbstractPostTaxonOperation {
|
35
|
|
36
|
|
37
|
|
38
|
private final TermDto parent;
|
39
|
private final TermEditorInput definedTermInput;
|
40
|
private boolean addTermAsKindOf;
|
41
|
|
42
|
|
43
|
/**
|
44
|
* @param label
|
45
|
* @param undoContext
|
46
|
* @param postOperationEnabled
|
47
|
* @param addTermAsKindOf
|
48
|
*/
|
49
|
public CreateDefinedTermOperation(String label,
|
50
|
IUndoContext undoContext,
|
51
|
TermDto parent,
|
52
|
TermEditorInput definedTermInput,
|
53
|
IPostOperationEnabled postOperationEnabled, boolean addTermAsKindOf) {
|
54
|
super(label, undoContext, postOperationEnabled);
|
55
|
this.parent = parent;
|
56
|
this.definedTermInput = definedTermInput;
|
57
|
this.addTermAsKindOf = addTermAsKindOf;
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
62
|
*/
|
63
|
@Override
|
64
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
65
|
throws ExecutionException {
|
66
|
|
67
|
DefinedTermBase newTerm = definedTermInput.getTermType().getEmptyDefinedTermBase();
|
68
|
if (newTerm == null) {
|
69
|
IStatus status =
|
70
|
new Status(IStatus.CANCEL,
|
71
|
StoreUtil.getPluginId(),
|
72
|
"Creation of term corresponding to type '" + definedTermInput.getTermType().getMessage() + "' is not yet supported");
|
73
|
MessagingUtils.warningDialog("Cannot create term", newTerm, status);
|
74
|
return status;
|
75
|
}
|
76
|
newTerm = CdmStore.getCurrentApplicationConfiguration().getTermService().save(newTerm);
|
77
|
|
78
|
//FIXME: Implement adding new terms to vocabularies
|
79
|
// if (parentTermBase instanceof TermVocabulary){
|
80
|
// TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
|
81
|
// vocabulary.addTerm(newTerm);
|
82
|
// } else
|
83
|
DefinedTermBase parentTerm = CdmStore.getService(ITermService.class).load(parent.getUuid());
|
84
|
TermVocabulary vocabulary = parentTerm.getVocabulary();
|
85
|
parentTerm.addIncludes(newTerm);
|
86
|
// parent.getIncludes().add(new TermDto(newTerm.getUuid(), null, parentTerm.getUuid(), vocabulary.getUuid(), null));
|
87
|
|
88
|
// DefinedTermBase parent = (DefinedTermBase) parentTermBase;
|
89
|
// if(addTermAsKindOf){
|
90
|
// parent.addGeneralizationOf(newTerm);
|
91
|
// }
|
92
|
// else{
|
93
|
// parent.addIncludes(newTerm);
|
94
|
// }
|
95
|
vocabulary.addTerm(newTerm);
|
96
|
// }
|
97
|
|
98
|
return postExecute(newTerm);
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
103
|
*/
|
104
|
@Override
|
105
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
106
|
throws ExecutionException {
|
107
|
// TODO Auto-generated method stub
|
108
|
return null;
|
109
|
}
|
110
|
|
111
|
/* (non-Javadoc)
|
112
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
113
|
*/
|
114
|
@Override
|
115
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
116
|
throws ExecutionException {
|
117
|
// TODO Auto-generated method stub
|
118
|
return null;
|
119
|
}
|
120
|
|
121
|
}
|