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
.DescriptionBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
24 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
25 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
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
.AbstractPostTaxonOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 * <p>CreateDescriptionElementOperation class.</p>
40 public class CreateDescriptionElementOperation
extends AbstractPostTaxonOperation
{
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 final DescriptionBase
<?
> description
;
46 private final 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 DescriptionBase} 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 DescriptionBase
<?
> description
, Feature feature
, IPostOperationEnabled postOperationEnabled
) {
61 super(label
, undoContext
, (Taxon
)null, 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 DescriptionBase} 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
, DescriptionBase
<?
> description
, Feature feature
,
80 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
81 this(label
, undoContext
, description
, feature
, postOperationEnabled
);
83 this.element
= element
;
87 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
95 if (element
== null) {
96 if (feature
.isSupportsCommonTaxonName()) {
97 element
= CommonTaxonName
.NewInstance("", null);
99 else if (feature
.isSupportsDistribution()) {
100 element
= Distribution
.NewInstance();
102 else if(feature
.isSupportsTaxonInteraction()){
103 element
= TaxonInteraction
.NewInstance();
105 else if(feature
.isSupportsIndividualAssociation()){
106 element
= IndividualsAssociation
.NewInstance();
108 else if(feature
.isSupportsCategoricalData()){
109 element
= CategoricalData
.NewInstance();
111 else if(feature
.isSupportsQuantitativeData()){
112 element
= QuantitativeData
.NewInstance();
115 element
= TextData
.NewInstance();
119 element
.setFeature(feature
);
120 description
.addElement(element
);
123 return postExecute(element
);
127 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
131 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
132 throws ExecutionException
{
134 description
.addElement(element
);
136 return postExecute(element
);
140 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
144 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
145 throws ExecutionException
{
147 description
.removeElement(element
);
149 return postExecute(null);