2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.operations
;
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
;
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
;
31 * <p>CreateDescriptionElementOperation class.</p>
38 public class CreateDescriptionElementOperation
extends AbstractPostOperation
{
40 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
41 public static final String ID
= "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
43 private TaxonDescription description
;
44 private Feature feature
;
45 private DescriptionElementBase element
;
48 * <p>Constructor for CreateDescriptionElementOperation.</p>
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.
57 public CreateDescriptionElementOperation(String label
, IUndoContext undoContext
,
58 Taxon taxon
, TaxonDescription description
, Feature feature
, IPostOperationEnabled postOperationEnabled
) {
59 super(label
, undoContext
, taxon
, postOperationEnabled
);
61 this.description
= description
;
62 this.feature
= feature
;
66 * <p>Constructor for CreateDescriptionElementOperation.</p>
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.
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
);
82 this.element
= element
;
86 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
91 throws ExecutionException
{
94 if (element
== null) {
95 if (feature
.isSupportsCommonTaxonName()) {
96 element
= CommonTaxonName
.NewInstance("", null);
98 else if (feature
.isSupportsDistribution()) {
99 element
= Distribution
.NewInstance();
101 else if(feature
.isSupportsTaxonInteraction()){
102 element
= TaxonInteraction
.NewInstance();
104 else if(feature
.isSupportsIndividualAssociation()){
105 element
= IndividualsAssociation
.NewInstance();
107 else if(feature
.isSupportsCategoricalData()){
108 element
= CategoricalData
.NewInstance();
110 else if(feature
.isSupportsQuantitativeData()){
111 element
= QuantitativeData
.NewInstance();
114 element
= TextData
.NewInstance();
118 element
.setFeature(feature
);
119 description
.addElement(element
);
122 return postExecute(element
);
126 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
130 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
131 throws ExecutionException
{
133 description
.addElement(element
);
135 return postExecute(element
);
139 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
143 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
144 throws ExecutionException
{
146 description
.removeElement(element
);
148 return postExecute(null);