had to rename the packages to make them compliant with buckminster
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / operation / ChangeDescriptionElementType.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.description.operation;
11
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;
17
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;
30
31 /**
32 * <p>ChangeDescriptionElementType class.</p>
33 *
34 * @author e.-m.lee
35 * @date 25.05.2010
36 * @version $Id: $
37 */
38 public class ChangeDescriptionElementType extends AbstractPostOperation {
39
40 private DescriptionElementBase sourceElement;
41 private DestinationType destinationType;
42 private DescriptionElementBase destinationElement;
43
44 public enum DestinationType {
45 TextData,
46 Distribution
47 }
48
49 /**
50 * <p>Constructor for ChangeDescriptionElementType.</p>
51 *
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.
56 */
57 public ChangeDescriptionElementType(String label, DescriptionElementBase sourceType, IPostOperationEnabled postOperation,
58 IUndoContext undoContext) {
59 super(label, undoContext, postOperation);
60 this.sourceElement = sourceType;
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
65 */
66 /** {@inheritDoc} */
67 @Override
68 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
69 throws ExecutionException {
70 DescriptionBase inDescription = sourceElement.getInDescription();
71 Feature feature = sourceElement.getFeature();
72
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();
78 }
79 else if(feature.isSupportsCommonTaxonName()){
80 destinationElement = CommonTaxonName.NewInstance(null, null);
81 }
82 else if(feature.isSupportsTaxonInteraction()){
83 destinationElement = TaxonInteraction.NewInstance();
84 }
85 else if(feature.isSupportsIndividualAssociation()){
86 destinationElement = IndividualsAssociation.NewInstance();
87 }
88 else if(feature.isSupportsCategoricalData()){
89 destinationElement = CategoricalData.NewInstance();
90 }
91 else if(feature.isSupportsQuantitativeData()){
92 destinationElement = QuantitativeData.NewInstance();
93 }
94 }
95 else{
96 if(feature.isSupportsTextData()){
97 destinationElement = TextData.NewInstance();
98 }
99 }
100
101 destinationElement.setFeature(feature);
102 inDescription.addElement(destinationElement);
103 inDescription.removeElement(sourceElement);
104 return postExecute(destinationElement);
105 }
106
107 /* (non-Javadoc)
108 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109 */
110 /** {@inheritDoc} */
111 @Override
112 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
113 throws ExecutionException {
114 // TODO Auto-generated method stub
115 return null;
116 }
117
118 /* (non-Javadoc)
119 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
120 */
121 /** {@inheritDoc} */
122 @Override
123 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
124 throws ExecutionException {
125 // TODO Auto-generated method stub
126 return null;
127 }
128
129 }