Revision cc26e350
Added by Cherian Mathew over 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateDefinedTermOperation.java | ||
---|---|---|
14 | 14 |
import org.eclipse.core.runtime.IAdaptable; |
15 | 15 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 | 16 |
import org.eclipse.core.runtime.IStatus; |
17 |
import org.eclipse.ui.IEditorInput;
|
|
17 |
import org.eclipse.core.runtime.Status;
|
|
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
20 | 20 |
import eu.etaxonomy.cdm.model.common.TermBase; |
21 | 21 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
22 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
23 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
|
24 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput; |
|
25 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.NamedAreaEditorInput; |
|
22 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; |
|
26 | 23 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
27 | 24 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
25 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
28 | 26 |
|
29 | 27 |
/** |
30 | 28 |
* @author l.morris |
... | ... | |
36 | 34 |
|
37 | 35 |
|
38 | 36 |
private TermBase parentTermBase; |
39 |
private AbstractDefinedTermEditorInput editorInput;
|
|
37 |
private TermEditorInput definedTermInput;
|
|
40 | 38 |
|
41 | 39 |
/** |
42 | 40 |
* @param label |
... | ... | |
44 | 42 |
* @param postOperationEnabled |
45 | 43 |
*/ |
46 | 44 |
public CreateDefinedTermOperation(String label, |
47 |
IUndoContext undoContext, TermBase termBase, IPostOperationEnabled postOperationEnabled) { |
|
45 |
IUndoContext undoContext, |
|
46 |
TermBase termBase, |
|
47 |
TermEditorInput definedTermInput, |
|
48 |
IPostOperationEnabled postOperationEnabled) { |
|
48 | 49 |
super(label, undoContext, postOperationEnabled); |
49 | 50 |
this.parentTermBase = termBase; |
50 |
editorInput = ((DefinedTermEditor)postOperationEnabled).getDefinedTermEditorInput();
|
|
51 |
this.definedTermInput = definedTermInput;
|
|
51 | 52 |
} |
52 | 53 |
|
53 | 54 |
/* (non-Javadoc) |
... | ... | |
57 | 58 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
58 | 59 |
throws ExecutionException { |
59 | 60 |
|
60 |
DefinedTermBase newTerm = editorInput.createTermInstance(); |
|
61 |
|
|
62 |
newTerm.setLabel("Untitled"); |
|
61 |
DefinedTermBase newTerm = definedTermInput.getTermType().getEmptyDefinedTermBase(); |
|
62 |
if (newTerm == null) { |
|
63 |
IStatus status = |
|
64 |
new Status(IStatus.CANCEL, |
|
65 |
StoreUtil.getPluginId(), |
|
66 |
"Creation of term corresponding to type '" + definedTermInput.getTermType().getMessage() + "' is not yet supported"); |
|
67 |
StoreUtil.warningDialog("Cannot create term", newTerm, status); |
|
68 |
return status; |
|
69 |
} |
|
63 | 70 |
|
64 | 71 |
if (parentTermBase instanceof TermVocabulary){ |
65 | 72 |
TermVocabulary vocabulary = (TermVocabulary) parentTermBase; |
66 | 73 |
vocabulary.addTerm(newTerm); |
67 | 74 |
} else if (parentTermBase instanceof DefinedTermBase) { |
68 |
DefinedTermBase parent = (DefinedTermBase) parentTermBase; |
|
69 |
parent.addIncludes(newTerm); |
|
75 |
DefinedTermBase parent = (DefinedTermBase) parentTermBase;
|
|
76 |
parent.addIncludes(newTerm);
|
|
70 | 77 |
TermVocabulary vocabulary = parent.getVocabulary(); |
71 | 78 |
vocabulary.addTerm(newTerm); |
72 | 79 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateTermVocabularyOperation.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.definedterm.operation; |
11 | 11 |
|
12 |
import java.net.URI; |
|
13 |
|
|
12 | 14 |
import org.eclipse.core.commands.ExecutionException; |
13 | 15 |
import org.eclipse.core.commands.operations.IUndoContext; |
14 | 16 |
import org.eclipse.core.runtime.IAdaptable; |
... | ... | |
16 | 18 |
import org.eclipse.core.runtime.IStatus; |
17 | 19 |
|
18 | 20 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
21 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
19 | 22 |
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; |
23 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
20 | 24 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
21 | 25 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
26 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; |
|
22 | 27 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
28 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
23 | 29 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
24 | 30 |
|
25 | 31 |
/** |
... | ... | |
29 | 35 |
*/ |
30 | 36 |
public class CreateTermVocabularyOperation extends AbstractPostOperation { |
31 | 37 |
|
32 |
private DefinedTermEditor definedTermEditor;
|
|
33 |
|
|
38 |
private TermEditorInput definedEditorInput;
|
|
39 |
|
|
34 | 40 |
/** |
35 | 41 |
* @param label |
36 | 42 |
* @param undoContext |
37 | 43 |
* @param postOperationEnabled |
38 | 44 |
*/ |
39 | 45 |
public CreateTermVocabularyOperation(String label, |
40 |
IUndoContext undoContext, DefinedTermEditor definedTermEditor) { |
|
41 |
super(label, undoContext, definedTermEditor); |
|
42 |
this.definedTermEditor = definedTermEditor; |
|
46 |
IUndoContext undoContext, |
|
47 |
TermEditorInput definedEditorInput, |
|
48 |
IPostOperationEnabled postOperationEnabled) { |
|
49 |
super(label, undoContext, postOperationEnabled); |
|
50 |
this.definedEditorInput = definedEditorInput; |
|
43 | 51 |
} |
44 | 52 |
|
45 | 53 |
/* (non-Javadoc) |
... | ... | |
48 | 56 |
@Override |
49 | 57 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
50 | 58 |
throws ExecutionException { |
51 |
|
|
52 |
TermVocabulary termVocabulary = OrderedTermVocabulary.NewInstance(null, "Untitled", null, null); |
|
59 |
|
|
60 |
TermVocabulary termVocabulary = |
|
61 |
TermVocabulary.NewInstance(definedEditorInput.getTermType(), |
|
62 |
null, |
|
63 |
"Untitled", |
|
64 |
null, |
|
65 |
null); |
|
66 |
|
|
53 | 67 |
CdmStore.getService(IVocabularyService.class).save(termVocabulary); |
54 |
definedTermEditor.getInMemoryVocabularies().add(termVocabulary);
|
|
68 |
definedEditorInput.getVocabularies().add(termVocabulary);
|
|
55 | 69 |
|
56 | 70 |
return postExecute(termVocabulary); |
57 | 71 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/DeleteTermBaseOperation.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.api.service.ITermService; |
20 | 20 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
21 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
21 | 22 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
22 | 23 |
import eu.etaxonomy.cdm.model.common.TermBase; |
23 | 24 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
24 | 25 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
26 |
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput; |
|
25 | 27 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
28 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
26 | 29 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
27 | 30 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
28 | 31 |
|
... | ... | |
33 | 36 |
*/ |
34 | 37 |
public class DeleteTermBaseOperation extends AbstractPostOperation { |
35 | 38 |
|
39 |
private TermEditorInput definedEditorInput; |
|
36 | 40 |
private TermBase termBase; |
37 | 41 |
private DefinedTermEditor definedTermEditor; |
38 | 42 |
/** |
... | ... | |
40 | 44 |
* @param undoContext |
41 | 45 |
* @param postOperationEnabled |
42 | 46 |
*/ |
43 |
public DeleteTermBaseOperation(String label, IUndoContext undoContext, TermBase termBase, |
|
44 |
DefinedTermEditor definedTermEditor) { |
|
45 |
super(label, undoContext, definedTermEditor); |
|
47 |
public DeleteTermBaseOperation(String label, |
|
48 |
IUndoContext undoContext, |
|
49 |
TermBase termBase, |
|
50 |
TermEditorInput definedEditorInput, |
|
51 |
IPostOperationEnabled postOperationEnabled) { |
|
52 |
super(label, undoContext, postOperationEnabled); |
|
46 | 53 |
this.termBase = termBase; |
47 |
this.definedTermEditor = definedTermEditor;
|
|
54 |
this.definedEditorInput = definedEditorInput;
|
|
48 | 55 |
} |
49 | 56 |
|
50 | 57 |
/* (non-Javadoc) |
... | ... | |
57 | 64 |
|
58 | 65 |
|
59 | 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 |
} |
|
60 | 72 |
|
61 | 73 |
if (!((TermVocabulary)termBase).getTerms().isEmpty()) { |
62 | 74 |
IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary."); |
63 | 75 |
StoreUtil.warningDialog("Vocabulary not empty", termBase, status); |
64 | 76 |
return status; |
65 |
} |
|
66 |
definedTermEditor.getInMemoryVocabularies().remove(termBase); |
|
77 |
} |
|
78 |
|
|
79 |
definedEditorInput.getVocabularies().remove((TermVocabulary)termBase); |
|
67 | 80 |
CdmStore.getService(IVocabularyService.class).delete((TermVocabulary)termBase); |
68 | 81 |
|
82 |
|
|
69 | 83 |
} else if (termBase instanceof DefinedTermBase) { |
70 | 84 |
|
71 | 85 |
|
72 | 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 |
} |
|
73 | 93 |
if(!definedTermBase.getIncludes().isEmpty()){ |
74 | 94 |
IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term."); |
75 | 95 |
StoreUtil.warningDialog("Term has included terms", termBase, status); |
76 | 96 |
return status; |
77 | 97 |
} |
78 | 98 |
|
99 |
|
|
79 | 100 |
DefinedTermBase partOf = definedTermBase.getPartOf(); |
80 | 101 |
if(partOf != null){ |
81 | 102 |
partOf.removeIncludes(definedTermBase); |
Also available in: Unified diff
updated operations to use the new TermEditorInput and also added pop-up warnings when,