1
|
package eu.etaxonomy.taxeditor.editor.view.uses.operation;
|
2
|
|
3
|
import org.eclipse.core.commands.ExecutionException;
|
4
|
import org.eclipse.core.commands.operations.IUndoContext;
|
5
|
import org.eclipse.core.runtime.IAdaptable;
|
6
|
import org.eclipse.core.runtime.IProgressMonitor;
|
7
|
import org.eclipse.core.runtime.IStatus;
|
8
|
|
9
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
10
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
11
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
12
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
13
|
import eu.etaxonomy.cdm.model.description.Feature;
|
14
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
15
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
16
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
17
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
18
|
import eu.etaxonomy.cdm.model.description.TextData;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
20
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
21
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
22
|
|
23
|
|
24
|
/**
|
25
|
* The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
|
26
|
*
|
27
|
* @author a.theys
|
28
|
* @created mar 13, 2012
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class CreateUseSummaryOperation extends AbstractPostOperation {
|
32
|
|
33
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord";
|
34
|
|
35
|
private TaxonDescription description;
|
36
|
private Feature feature;
|
37
|
private DescriptionElementBase element;
|
38
|
|
39
|
|
40
|
public CreateUseSummaryOperation(String label, IUndoContext undoContext,
|
41
|
Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
|
42
|
super(label, undoContext, taxon, postOperationEnabled);
|
43
|
|
44
|
this.description = description;
|
45
|
this.feature = feature;
|
46
|
}
|
47
|
|
48
|
public CreateUseSummaryOperation(String label,
|
49
|
IUndoContext undoContext, Taxon taxon,
|
50
|
TaxonDescription description, Feature feature,
|
51
|
DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
|
52
|
this(label, undoContext, taxon, description, feature, postOperationEnabled);
|
53
|
|
54
|
this.element = element;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
59
|
throws ExecutionException {
|
60
|
monitor.worked(20);
|
61
|
if (element == null) {
|
62
|
|
63
|
element = TextData.NewInstance();
|
64
|
}
|
65
|
|
66
|
|
67
|
element.setFeature(feature);
|
68
|
description.addElement(element);
|
69
|
monitor.worked(40);
|
70
|
|
71
|
return postExecute(element);
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
76
|
throws ExecutionException {
|
77
|
|
78
|
description.addElement(element);
|
79
|
|
80
|
return postExecute(element);
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
85
|
throws ExecutionException {
|
86
|
description.removeElement(element);
|
87
|
|
88
|
return postExecute(null);
|
89
|
}
|
90
|
}
|