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.AbstractPostTaxonOperation;
|
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 AbstractPostTaxonOperation {
|
39
|
|
40
|
private DescriptionElementBase sourceElement;
|
41
|
private DescriptionElementBase destinationElement;
|
42
|
|
43
|
/**
|
44
|
* <p>Constructor for ChangeDescriptionElementType.</p>
|
45
|
*
|
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.
|
50
|
*/
|
51
|
public ChangeDescriptionElementType(String label, DescriptionElementBase sourceType, IPostOperationEnabled postOperation,
|
52
|
IUndoContext undoContext) {
|
53
|
super(label, undoContext, postOperation);
|
54
|
this.sourceElement = sourceType;
|
55
|
}
|
56
|
|
57
|
/* (non-Javadoc)
|
58
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
59
|
*/
|
60
|
/** {@inheritDoc} */
|
61
|
@Override
|
62
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
63
|
throws ExecutionException {
|
64
|
DescriptionBase inDescription = sourceElement.getInDescription();
|
65
|
Feature feature = sourceElement.getFeature();
|
66
|
|
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();
|
72
|
}
|
73
|
else if(feature.isSupportsCommonTaxonName()){
|
74
|
destinationElement = CommonTaxonName.NewInstance(null, null);
|
75
|
}
|
76
|
else if(feature.isSupportsTaxonInteraction()){
|
77
|
destinationElement = TaxonInteraction.NewInstance();
|
78
|
}
|
79
|
else if(feature.isSupportsIndividualAssociation()){
|
80
|
destinationElement = IndividualsAssociation.NewInstance();
|
81
|
}
|
82
|
else if(feature.isSupportsCategoricalData()){
|
83
|
destinationElement = CategoricalData.NewInstance();
|
84
|
}
|
85
|
else if(feature.isSupportsQuantitativeData()){
|
86
|
destinationElement = QuantitativeData.NewInstance();
|
87
|
}
|
88
|
}
|
89
|
else{
|
90
|
if(feature.isSupportsTextData()){
|
91
|
destinationElement = TextData.NewInstance();
|
92
|
}
|
93
|
}
|
94
|
|
95
|
destinationElement.setFeature(feature);
|
96
|
inDescription.addElement(destinationElement);
|
97
|
inDescription.removeElement(sourceElement);
|
98
|
return postExecute(destinationElement);
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
103
|
*/
|
104
|
/** {@inheritDoc} */
|
105
|
@Override
|
106
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
107
|
throws ExecutionException {
|
108
|
return null;
|
109
|
}
|
110
|
|
111
|
/* (non-Javadoc)
|
112
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
113
|
*/
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
117
|
throws ExecutionException {
|
118
|
return null;
|
119
|
}
|
120
|
|
121
|
}
|