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
.editor
.view
.descriptive
.operation
;
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
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 * <p>CreateDescriptionElementOperation class.</p>
40 public class CreateDescriptionElementOperation
extends AbstractPostOperation
{
42 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
43 public static final String ID
= "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
45 private TaxonDescription description
;
46 private Feature feature
;
47 private DescriptionElementBase element
;
50 * <p>Constructor for CreateDescriptionElementOperation.</p>
52 * @param label a {@link java.lang.String} object.
53 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
56 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
57 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59 public CreateDescriptionElementOperation(String label
, IUndoContext undoContext
,
60 Taxon taxon
, TaxonDescription description
, Feature feature
, IPostOperationEnabled postOperationEnabled
) {
61 super(label
, undoContext
, taxon
, postOperationEnabled
);
63 this.description
= description
;
64 this.feature
= feature
;
68 * <p>Constructor for CreateDescriptionElementOperation.</p>
70 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
71 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
72 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
73 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
74 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
75 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
76 * @param label a {@link java.lang.String} object.
78 public CreateDescriptionElementOperation(String label
,
79 IUndoContext undoContext
, Taxon taxon
,
80 TaxonDescription description
, Feature feature
,
81 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
82 this(label
, undoContext
, taxon
, description
, feature
, postOperationEnabled
);
84 this.element
= element
;
88 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
92 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
93 throws ExecutionException
{
96 if (element
== null) {
97 if (feature
.isSupportsCommonTaxonName()) {
98 element
= CommonTaxonName
.NewInstance("", null);
100 else if (feature
.isSupportsDistribution()) {
101 element
= Distribution
.NewInstance();
103 else if(feature
.isSupportsTaxonInteraction()){
104 element
= TaxonInteraction
.NewInstance();
106 else if(feature
.isSupportsIndividualAssociation()){
107 element
= IndividualsAssociation
.NewInstance();
109 else if(feature
.isSupportsCategoricalData()){
110 element
= CategoricalData
.NewInstance();
112 else if(feature
.isSupportsQuantitativeData()){
113 element
= QuantitativeData
.NewInstance();
116 element
= TextData
.NewInstance();
120 element
.setFeature(feature
);
121 description
.addElement(element
);
124 return postExecute(element
);
128 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
132 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
133 throws ExecutionException
{
135 description
.addElement(element
);
137 return postExecute(element
);
141 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
145 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
146 throws ExecutionException
{
148 description
.removeElement(element
);
150 return postExecute(null);