AT: committing changes to the TaxEditor Post second round of code review
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / operation / CreateUseSummaryOperation.java
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.DescriptionElementBase;
10 import eu.etaxonomy.cdm.model.description.Feature;
11 import eu.etaxonomy.cdm.model.description.TaxonDescription;
12 import eu.etaxonomy.cdm.model.description.TextData;
13 import eu.etaxonomy.cdm.model.taxon.Taxon;
14 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
15 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
16
17
18 /**
19 * CreateUseSummaryOperation Class
20 * @author a.theys
21 * @created mar 13, 2012
22 * @version 1.0
23 */
24 public class CreateUseSummaryOperation extends AbstractPostOperation {
25
26 public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord";
27
28 private TaxonDescription description;
29 private Feature feature;
30 private DescriptionElementBase element;
31
32
33 /**
34 * <p>Constructor for CreateUseSummaryOperation.</p>
35 *
36 * @param label a {@link java.lang.String} object.
37 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
38 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
39 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
40 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
41 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
42 */
43 public CreateUseSummaryOperation(String label, IUndoContext undoContext,
44 Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
45 super(label, undoContext, taxon, postOperationEnabled);
46
47 this.description = description;
48 this.feature = feature;
49 }
50
51 /**
52 * <p>Constructor for CreateUseSummaryOperation.</p>
53 *
54 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
55 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
56 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
57 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
58 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
59 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60 * @param label a {@link java.lang.String} object.
61 */
62 public CreateUseSummaryOperation(String label,
63 IUndoContext undoContext, Taxon taxon,
64 TaxonDescription description, Feature feature,
65 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
66 this(label, undoContext, taxon, description, feature, postOperationEnabled);
67
68 this.element = element;
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
74 throws ExecutionException {
75 monitor.worked(20);
76 if (element == null) {
77
78 element = TextData.NewInstance();
79 }
80
81
82 element.setFeature(feature);
83 description.addElement(element);
84 monitor.worked(40);
85
86 return postExecute(element);
87 }
88
89 @Override
90 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92
93 description.addElement(element);
94
95 return postExecute(element);
96 }
97
98 @Override
99 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
100 throws ExecutionException {
101 description.removeElement(element);
102
103 return postExecute(null);
104 }
105 }