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
.AbstractPostOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 * <p>ChangeDescriptionElementType class.</p>
38 public class ChangeDescriptionElementType
extends AbstractPostOperation
{
40 private DescriptionElementBase sourceElement
;
41 private DestinationType destinationType
;
42 private DescriptionElementBase destinationElement
;
44 public enum DestinationType
{
50 * <p>Constructor for ChangeDescriptionElementType.</p>
52 * @param label a {@link java.lang.String} object.
53 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54 * @param sourceType a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
55 * @param postOperation a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
57 public ChangeDescriptionElementType(String label
, DescriptionElementBase sourceType
, IPostOperationEnabled postOperation
,
58 IUndoContext undoContext
) {
59 super(label
, undoContext
, postOperation
);
60 this.sourceElement
= sourceType
;
64 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
69 throws ExecutionException
{
70 DescriptionBase inDescription
= sourceElement
.getInDescription();
71 Feature feature
= sourceElement
.getFeature();
73 if(sourceElement
instanceof TextData
){
74 // FIXME I guess there are features that support more that one of these
75 // and that case is not handled correctly at the moment
76 if(feature
.isSupportsDistribution()){
77 destinationElement
= Distribution
.NewInstance();
79 else if(feature
.isSupportsCommonTaxonName()){
80 destinationElement
= CommonTaxonName
.NewInstance(null, null);
82 else if(feature
.isSupportsTaxonInteraction()){
83 destinationElement
= TaxonInteraction
.NewInstance();
85 else if(feature
.isSupportsIndividualAssociation()){
86 destinationElement
= IndividualsAssociation
.NewInstance();
88 else if(feature
.isSupportsCategoricalData()){
89 destinationElement
= CategoricalData
.NewInstance();
91 else if(feature
.isSupportsQuantitativeData()){
92 destinationElement
= QuantitativeData
.NewInstance();
96 if(feature
.isSupportsTextData()){
97 destinationElement
= TextData
.NewInstance();
101 destinationElement
.setFeature(feature
);
102 inDescription
.addElement(destinationElement
);
103 inDescription
.removeElement(sourceElement
);
104 return postExecute(destinationElement
);
108 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
113 throws ExecutionException
{
114 // TODO Auto-generated method stub
119 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
123 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
124 throws ExecutionException
{
125 // TODO Auto-generated method stub