2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
.operation
;
11 import org
.eclipse
.core
.commands
.ExecutionException
;
12 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
13 import org
.eclipse
.core
.runtime
.IAdaptable
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.swt
.widgets
.Display
;
20 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
21 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
25 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
26 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
27 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
29 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 * <p>ChangeDescriptionElementType class.</p>
40 public class ChangeDescriptionElementType
extends AbstractPostTaxonOperation
{
42 private DescriptionElementBase sourceElement
;
43 private DescriptionElementBase destinationElement
;
46 * <p>Constructor for ChangeDescriptionElementType.</p>
48 * @param label a {@link java.lang.String} object.
49 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
50 * @param sourceType a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
51 * @param postOperation a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53 public ChangeDescriptionElementType(String label
, DescriptionElementBase sourceType
, IPostOperationEnabled postOperation
,
54 IUndoContext undoContext
) {
55 super(label
, undoContext
, postOperation
);
56 this.sourceElement
= sourceType
;
60 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
66 DescriptionBase inDescription
= sourceElement
.getInDescription();
67 Feature feature
= sourceElement
.getFeature();
69 if(sourceElement
instanceof TextData
){
70 // FIXME I guess there are features that support more that one of these
71 // and that case is not handled correctly at the moment
72 if(feature
.isSupportsDistribution()){
73 destinationElement
= Distribution
.NewInstance();
75 else if(feature
.isSupportsCommonTaxonName()){
76 destinationElement
= CommonTaxonName
.NewInstance(null, null);
78 else if(feature
.isSupportsTaxonInteraction()){
79 destinationElement
= TaxonInteraction
.NewInstance();
81 else if(feature
.isSupportsIndividualAssociation()){
82 destinationElement
= IndividualsAssociation
.NewInstance();
84 else if(feature
.isSupportsCategoricalData()){
85 destinationElement
= CategoricalData
.NewInstance();
87 else if(feature
.isSupportsQuantitativeData()){
88 destinationElement
= QuantitativeData
.NewInstance();
92 if(feature
.isSupportsTextData()){
93 destinationElement
= TextData
.NewInstance();
96 if(destinationElement
==null){
97 MessageDialog
.openInformation(Display
.getCurrent().getActiveShell(), "Change not possible", "Feature does not have another type");
98 return Status
.CANCEL_STATUS
;
100 destinationElement
.setFeature(feature
);
101 inDescription
.addElement(destinationElement
);
102 inDescription
.removeElement(sourceElement
);
103 return postExecute(destinationElement
);
107 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
111 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
112 throws ExecutionException
{
117 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
121 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
122 throws ExecutionException
{