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.operations;
|
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
|
|
29
|
/**
|
30
|
* <p>ChangeDescriptionElementType class.</p>
|
31
|
*
|
32
|
* @author e.-m.lee
|
33
|
* @date 25.05.2010
|
34
|
* @version $Id: $
|
35
|
*/
|
36
|
public class ChangeDescriptionElementType extends AbstractPostOperation {
|
37
|
|
38
|
private DescriptionElementBase sourceElement;
|
39
|
private DestinationType destinationType;
|
40
|
private DescriptionElementBase destinationElement;
|
41
|
|
42
|
public enum DestinationType {
|
43
|
TextData,
|
44
|
Distribution
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* <p>Constructor for ChangeDescriptionElementType.</p>
|
49
|
*
|
50
|
* @param label a {@link java.lang.String} object.
|
51
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
52
|
* @param sourceType a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
53
|
* @param postOperation a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
|
54
|
*/
|
55
|
public ChangeDescriptionElementType(String label, DescriptionElementBase sourceType, IPostOperationEnabled postOperation,
|
56
|
IUndoContext undoContext) {
|
57
|
super(label, undoContext, postOperation);
|
58
|
this.sourceElement = sourceType;
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
63
|
*/
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
67
|
throws ExecutionException {
|
68
|
DescriptionBase inDescription = sourceElement.getInDescription();
|
69
|
Feature feature = sourceElement.getFeature();
|
70
|
|
71
|
if(sourceElement instanceof TextData){
|
72
|
// FIXME I guess there are features that support more that one of these
|
73
|
// and that case is not handled correctly at the moment
|
74
|
if(feature.isSupportsDistribution()){
|
75
|
destinationElement = Distribution.NewInstance();
|
76
|
}
|
77
|
else if(feature.isSupportsCommonTaxonName()){
|
78
|
destinationElement = CommonTaxonName.NewInstance(null, null);
|
79
|
}
|
80
|
else if(feature.isSupportsTaxonInteraction()){
|
81
|
destinationElement = TaxonInteraction.NewInstance();
|
82
|
}
|
83
|
else if(feature.isSupportsIndividualAssociation()){
|
84
|
destinationElement = IndividualsAssociation.NewInstance();
|
85
|
}
|
86
|
else if(feature.isSupportsCategoricalData()){
|
87
|
destinationElement = CategoricalData.NewInstance();
|
88
|
}
|
89
|
else if(feature.isSupportsQuantitativeData()){
|
90
|
destinationElement = QuantitativeData.NewInstance();
|
91
|
}
|
92
|
}
|
93
|
else{
|
94
|
if(feature.isSupportsTextData()){
|
95
|
destinationElement = TextData.NewInstance();
|
96
|
}
|
97
|
}
|
98
|
|
99
|
destinationElement.setFeature(feature);
|
100
|
inDescription.addElement(destinationElement);
|
101
|
inDescription.removeElement(sourceElement);
|
102
|
return postExecute(destinationElement);
|
103
|
}
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
107
|
*/
|
108
|
/** {@inheritDoc} */
|
109
|
@Override
|
110
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
111
|
throws ExecutionException {
|
112
|
// TODO Auto-generated method stub
|
113
|
return null;
|
114
|
}
|
115
|
|
116
|
/* (non-Javadoc)
|
117
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
118
|
*/
|
119
|
/** {@inheritDoc} */
|
120
|
@Override
|
121
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
122
|
throws ExecutionException {
|
123
|
// TODO Auto-generated method stub
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
}
|