3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
.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
.taxeditor
.operation
.AbstractPostTaxonOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 * <p>ChangeDescriptionElementType class.</p>
38 public class ChangeDescriptionElementType
extends AbstractPostTaxonOperation
{
40 private DescriptionElementBase sourceElement
;
41 private DescriptionElementBase destinationElement
;
44 * <p>Constructor for ChangeDescriptionElementType.</p>
46 * @param label a {@link java.lang.String} object.
47 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48 * @param sourceType a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
49 * @param postOperation a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51 public ChangeDescriptionElementType(String label
, DescriptionElementBase sourceType
, IPostOperationEnabled postOperation
,
52 IUndoContext undoContext
) {
53 super(label
, undoContext
, postOperation
);
54 this.sourceElement
= sourceType
;
58 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
63 throws ExecutionException
{
64 DescriptionBase inDescription
= sourceElement
.getInDescription();
65 Feature feature
= sourceElement
.getFeature();
67 if(sourceElement
instanceof TextData
){
68 // FIXME I guess there are features that support more that one of these
69 // and that case is not handled correctly at the moment
70 if(feature
.isSupportsDistribution()){
71 destinationElement
= Distribution
.NewInstance();
73 else if(feature
.isSupportsCommonTaxonName()){
74 destinationElement
= CommonTaxonName
.NewInstance(null, null);
76 else if(feature
.isSupportsTaxonInteraction()){
77 destinationElement
= TaxonInteraction
.NewInstance();
79 else if(feature
.isSupportsIndividualAssociation()){
80 destinationElement
= IndividualsAssociation
.NewInstance();
82 else if(feature
.isSupportsCategoricalData()){
83 destinationElement
= CategoricalData
.NewInstance();
85 else if(feature
.isSupportsQuantitativeData()){
86 destinationElement
= QuantitativeData
.NewInstance();
90 if(feature
.isSupportsTextData()){
91 destinationElement
= TextData
.NewInstance();
95 destinationElement
.setFeature(feature
);
96 inDescription
.addElement(destinationElement
);
97 inDescription
.removeElement(sourceElement
);
98 return postExecute(destinationElement
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
112 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
117 throws ExecutionException
{