performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / CreateDescriptionElementOperation.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.operations;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17
18 import eu.etaxonomy.cdm.model.description.CategoricalData;
19 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
20 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21 import eu.etaxonomy.cdm.model.description.Distribution;
22 import eu.etaxonomy.cdm.model.description.Feature;
23 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
24 import eu.etaxonomy.cdm.model.description.QuantitativeData;
25 import eu.etaxonomy.cdm.model.description.TaxonDescription;
26 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
27 import eu.etaxonomy.cdm.model.description.TextData;
28 import eu.etaxonomy.cdm.model.taxon.Taxon;
29
30 /**
31 * <p>CreateDescriptionElementOperation class.</p>
32 *
33 * @author p.ciardelli
34 * @author n.hoffmann
35 * @created 05.02.2009
36 * @version 1.0
37 */
38 public class CreateDescriptionElementOperation extends AbstractPostOperation {
39
40 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
41 public static final String ID = "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
42
43 private TaxonDescription description;
44 private Feature feature;
45 private DescriptionElementBase element;
46
47 /**
48 * <p>Constructor for CreateDescriptionElementOperation.</p>
49 *
50 * @param label a {@link java.lang.String} object.
51 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
54 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
55 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
56 */
57 public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
58 Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
59 super(label, undoContext, taxon, postOperationEnabled);
60
61 this.description = description;
62 this.feature = feature;
63 }
64
65 /**
66 * <p>Constructor for CreateDescriptionElementOperation.</p>
67 *
68 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
69 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
70 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
71 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
72 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
73 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
74 * @param label a {@link java.lang.String} object.
75 */
76 public CreateDescriptionElementOperation(String label,
77 IUndoContext undoContext, Taxon taxon,
78 TaxonDescription description, Feature feature,
79 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
80 this(label, undoContext, taxon, description, feature, postOperationEnabled);
81
82 this.element = element;
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
87 */
88 /** {@inheritDoc} */
89 @Override
90 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92
93 monitor.worked(20);
94 if (element == null) {
95 if (feature.isSupportsCommonTaxonName()) {
96 element = CommonTaxonName.NewInstance("", null);
97 }
98 else if (feature.isSupportsDistribution()) {
99 element = Distribution.NewInstance();
100 }
101 else if(feature.isSupportsTaxonInteraction()){
102 element = TaxonInteraction.NewInstance();
103 }
104 else if(feature.isSupportsIndividualAssociation()){
105 element = IndividualsAssociation.NewInstance();
106 }
107 else if(feature.isSupportsCategoricalData()){
108 element = CategoricalData.NewInstance();
109 }
110 else if(feature.isSupportsQuantitativeData()){
111 element = QuantitativeData.NewInstance();
112 }
113 else {
114 element = TextData.NewInstance();
115 }
116 }
117
118 element.setFeature(feature);
119 description.addElement(element);
120 monitor.worked(40);
121
122 return postExecute(element);
123 }
124
125 /* (non-Javadoc)
126 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
127 */
128 /** {@inheritDoc} */
129 @Override
130 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
131 throws ExecutionException {
132
133 description.addElement(element);
134
135 return postExecute(element);
136 }
137
138 /* (non-Javadoc)
139 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
140 */
141 /** {@inheritDoc} */
142 @Override
143 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
144 throws ExecutionException {
145
146 description.removeElement(element);
147
148 return postExecute(null);
149 }
150 }