Project

General

Profile

Download (4.94 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.ui.section.description.operation;
10

    
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.jface.viewers.Viewer;
19
import org.eclipse.swt.widgets.Display;
20

    
21
import eu.etaxonomy.cdm.model.description.CategoricalData;
22
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
23
import eu.etaxonomy.cdm.model.description.DescriptionBase;
24
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
25
import eu.etaxonomy.cdm.model.description.Distribution;
26
import eu.etaxonomy.cdm.model.description.Feature;
27
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
28
import eu.etaxonomy.cdm.model.description.QuantitativeData;
29
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
30
import eu.etaxonomy.cdm.model.description.TextData;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
32
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
33
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
34

    
35
/**
36
 * <p>ChangeDescriptionElementType class.</p>
37
 *
38
 * @author e.-m.lee
39
 * @date 25.05.2010
40
 * @version $Id: $
41
 */
42
public class ChangeDescriptionElementType extends AbstractPostTaxonOperation {
43

    
44
	private DescriptionElementBase sourceElement;
45
	private DescriptionElementBase destinationElement;
46
	private Viewer viewer;
47

    
48
	/**
49
	 * <p>Constructor for ChangeDescriptionElementType.</p>
50
	 *
51
	 * @param label a {@link java.lang.String} object.
52
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
53
	 * @param sourceType a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
54
	 * @param postOperation a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
55
	 */
56
	public ChangeDescriptionElementType(String label, DescriptionElementBase sourceType, IPostOperationEnabled postOperation,
57
			IUndoContext undoContext) {
58
		super(label, undoContext, postOperation);
59
		this.sourceElement = sourceType;
60
		if(postOperation instanceof DetailsPartE4){
61
		    this.viewer = ((DetailsPartE4) postOperation).getViewer();
62
		}
63
	}
64

    
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
67
	 */
68
	/** {@inheritDoc} */
69
	@Override
70
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
71
			throws ExecutionException {
72
		DescriptionBase inDescription = sourceElement.getInDescription();
73
		Feature feature = sourceElement.getFeature();
74

    
75
		if(sourceElement instanceof TextData){
76
			// FIXME I guess there are features that support more that one of these
77
			// and that case is not handled correctly at the moment
78
			if(feature.isSupportsDistribution()){
79
				destinationElement = Distribution.NewInstance();
80
			}
81
			else if(feature.isSupportsCommonTaxonName()){
82
				destinationElement = CommonTaxonName.NewInstance(null, null);
83
			}
84
			else if(feature.isSupportsTaxonInteraction()){
85
				destinationElement = TaxonInteraction.NewInstance();
86
			}
87
			else if(feature.isSupportsIndividualAssociation()){
88
				destinationElement = IndividualsAssociation.NewInstance();
89
			}
90
			else if(feature.isSupportsCategoricalData()){
91
				destinationElement = CategoricalData.NewInstance();
92
			}
93
			else if(feature.isSupportsQuantitativeData()){
94
				destinationElement = QuantitativeData.NewInstance();
95
			}
96
		}
97
		else{
98
			if(feature.isSupportsTextData()){
99
				destinationElement = TextData.NewInstance();
100
			}
101
		}
102
		if(destinationElement==null){
103
			MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Change not possible", "Feature does not have another type");
104
			return Status.CANCEL_STATUS;
105
		}
106
		destinationElement.setFeature(feature);
107
		inDescription.addElement(destinationElement);
108
		inDescription.removeElement(sourceElement);
109

    
110
        viewer.setInput(destinationElement);
111
		return postExecute(destinationElement);
112
	}
113

    
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116
	 */
117
	/** {@inheritDoc} */
118
	@Override
119
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
120
			throws ExecutionException {
121
		return null;
122
	}
123

    
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
126
	 */
127
	/** {@inheritDoc} */
128
	@Override
129
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
130
			throws ExecutionException {
131
		return null;
132
	}
133

    
134
}
    (1-1/1)