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