- enabled DescriptiveView (Factual Data) to show descriptions of SpecimenOrObservati...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / operation / CreateUseRecordOperation.java
1 /**
2 * Copyright (C) 2011 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.view.uses.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
17 import eu.etaxonomy.cdm.model.description.CategoricalData;
18 import eu.etaxonomy.cdm.model.description.DescriptionBase;
19 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20 import eu.etaxonomy.cdm.model.description.Feature;
21 import eu.etaxonomy.cdm.model.description.TaxonDescription;
22 import eu.etaxonomy.cdm.model.description.TextData;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
27
28 /**
29 * CreateUseRecordOperation Class
30 * @author a.theys
31 * @created mar 13, 2012
32 * @version 1.0
33 */
34 public class CreateUseRecordOperation extends AbstractPostOperation {
35
36 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.use."{trunked}</code> */
37 public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord";
38 private final DescriptionBase<?> description;
39 private final Feature feature;
40 private DescriptionElementBase element;
41
42 /**
43 * <p>Constructor for CreateUseRecordOperation.</p>
44 *
45 * @param label a {@link java.lang.String} object.
46 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
48 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
49 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51 */
52 public CreateUseRecordOperation(String label, IUndoContext undoContext, DescriptionBase<?> description, Feature feature, IPostOperationEnabled postOperationEnabled) {
53 super(label, undoContext, (Taxon)null, postOperationEnabled);
54
55 this.description = description;
56 this.feature = feature;
57 }
58
59
60 /**
61 * <p>Constructor for CreateUseRecordOperation.</p>
62 *
63 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
64 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
65 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
66 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
67 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
68 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
69 * @param label a {@link java.lang.String} object.
70 */
71 public CreateUseRecordOperation(String label,
72 IUndoContext undoContext, Taxon taxon,
73 TaxonDescription description, Feature feature,
74 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
75 this(label, undoContext, description, feature, postOperationEnabled);
76
77 this.element = element;
78 }
79
80 @Override
81 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
82 throws ExecutionException {
83 monitor.worked(20);
84 if (element == null) {
85 if(feature.isSupportsCategoricalData()){
86 element = CategoricalData.NewInstance();
87 }
88 else {
89 element = TextData.NewInstance();
90 }
91 }
92
93
94 element.setFeature(feature);
95 description.addElement(element);
96 monitor.worked(40);
97
98 return postExecute(element);
99 }
100
101 @Override
102 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
103 throws ExecutionException {
104
105 description.addElement(element);
106
107 return postExecute(element);
108 }
109
110 @Override
111 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
112 throws ExecutionException {
113 description.removeElement(element);
114
115 return postExecute(null);
116 }
117 }