Revision b405585f
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateDefinedTermOperation.java | ||
---|---|---|
13 | 13 |
import org.eclipse.core.runtime.IAdaptable; |
14 | 14 |
import org.eclipse.core.runtime.IProgressMonitor; |
15 | 15 |
import org.eclipse.core.runtime.IStatus; |
16 |
import org.eclipse.core.runtime.Status; |
|
17 | 16 |
|
18 | 17 |
import eu.etaxonomy.cdm.api.service.ITermService; |
19 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
20 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
21 | 18 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
22 | 19 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; |
23 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
24 |
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; |
|
20 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
25 | 21 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
26 | 22 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
27 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
28 | 23 |
|
29 | 24 |
/** |
30 | 25 |
* @author l.morris |
31 | 26 |
* @date 21 Dec 2011 |
32 | 27 |
* |
33 | 28 |
*/ |
34 |
public class CreateDefinedTermOperation extends AbstractPostTaxonOperation {
|
|
29 |
public class CreateDefinedTermOperation extends AbstractPostOperation { |
|
35 | 30 |
|
36 | 31 |
private final TermDto parent; |
37 | 32 |
private final TermEditorInput definedTermInput; |
... | ... | |
43 | 38 |
TermDto parent, |
44 | 39 |
TermEditorInput definedTermInput, |
45 | 40 |
IPostOperationEnabled postOperationEnabled, boolean addTermAsKindOf) { |
46 |
super(label, undoContext, postOperationEnabled); |
|
41 |
super(label, undoContext, null, postOperationEnabled);
|
|
47 | 42 |
this.parent = parent; |
48 | 43 |
this.definedTermInput = definedTermInput; |
49 | 44 |
this.addTermAsKindOf = addTermAsKindOf; |
... | ... | |
52 | 47 |
@Override |
53 | 48 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
54 | 49 |
throws ExecutionException { |
55 |
|
|
56 |
DefinedTermBase newTerm = definedTermInput.getTermType().getEmptyDefinedTermBase(); |
|
57 |
if (newTerm == null) { |
|
58 |
IStatus status = |
|
59 |
new Status(IStatus.CANCEL, |
|
60 |
StoreUtil.getPluginId(), |
|
61 |
"Creation of term corresponding to type '" + definedTermInput.getTermType().getMessage() + "' is not yet supported"); |
|
62 |
MessagingUtils.warningDialog("Cannot create term", newTerm, status); |
|
63 |
return status; |
|
64 |
} |
|
65 |
newTerm = CdmStore.getCurrentApplicationConfiguration().getTermService().save(newTerm); |
|
66 |
|
|
67 |
//FIXME: Implement adding new terms to vocabularies |
|
68 |
// if (parentTermBase instanceof TermVocabulary){ |
|
69 |
// TermVocabulary vocabulary = (TermVocabulary) parentTermBase; |
|
50 |
CdmStore.getService(ITermService.class).addNewTerm(definedTermInput.getTermType(), parent.getUuid(), addTermAsKindOf); |
|
51 |
// |
|
52 |
// //FIXME: Implement adding new terms to vocabularies |
|
53 |
//// if (parentTermBase instanceof TermVocabulary){ |
|
54 |
//// TermVocabulary vocabulary = (TermVocabulary) parentTermBase; |
|
55 |
//// vocabulary.addTerm(newTerm); |
|
56 |
//// } else |
|
57 |
// DefinedTermBase parentTerm = CdmStore.getService(ITermService.class).load(parent.getUuid()); |
|
58 |
// TermVocabulary vocabulary = parentTerm.getVocabulary(); |
|
59 |
// parentTerm.addIncludes(newTerm); |
|
60 |
//// parent.getIncludes().add(new TermDto(newTerm.getUuid(), null, parentTerm.getUuid(), vocabulary.getUuid(), null)); |
|
61 |
// |
|
62 |
//// DefinedTermBase parent = (DefinedTermBase) parentTermBase; |
|
63 |
//// if(addTermAsKindOf){ |
|
64 |
//// parent.addGeneralizationOf(newTerm); |
|
65 |
//// } |
|
66 |
//// else{ |
|
67 |
//// parent.addIncludes(newTerm); |
|
68 |
//// } |
|
70 | 69 |
// vocabulary.addTerm(newTerm); |
71 |
// } else |
|
72 |
DefinedTermBase parentTerm = CdmStore.getService(ITermService.class).load(parent.getUuid()); |
|
73 |
TermVocabulary vocabulary = parentTerm.getVocabulary(); |
|
74 |
parentTerm.addIncludes(newTerm); |
|
75 |
// parent.getIncludes().add(new TermDto(newTerm.getUuid(), null, parentTerm.getUuid(), vocabulary.getUuid(), null)); |
|
76 |
|
|
77 |
// DefinedTermBase parent = (DefinedTermBase) parentTermBase; |
|
78 |
// if(addTermAsKindOf){ |
|
79 |
// parent.addGeneralizationOf(newTerm); |
|
80 |
// } |
|
81 |
// else{ |
|
82 |
// parent.addIncludes(newTerm); |
|
83 |
// } |
|
84 |
vocabulary.addTerm(newTerm); |
|
85 |
// } |
|
70 |
//// } |
|
86 | 71 |
|
87 |
return postExecute(newTerm);
|
|
72 |
return postExecute(null);
|
|
88 | 73 |
} |
89 | 74 |
|
90 | 75 |
@Override |
Also available in: Unified diff
ref #7887 Use service for term creation directly