Project

General

Profile

Download (5.43 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.editor.view.descriptive.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.cdm.model.taxon.Taxon;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31

    
32
/**
33
 * <p>CreateDescriptionElementOperation class.</p>
34
 *
35
 * @author p.ciardelli
36
 * @author n.hoffmann
37
 * @created 05.02.2009
38
 * @version 1.0
39
 */
40
public class CreateDescriptionElementOperation extends AbstractPostTaxonOperation {
41

    
42
	/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
43
	public static final String ID = "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
44

    
45
	private final DescriptionBase<?> description;
46
	private final Feature feature;
47
	private DescriptionElementBase element;
48

    
49
	/**
50
	 * <p>Constructor for CreateDescriptionElementOperation.</p>
51
	 *
52
	 * @param label a {@link java.lang.String} object.
53
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55
	 * @param description a {@link DescriptionBase} object.
56
	 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
57
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58
	 */
59
	public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
60
	        DescriptionBase<?> description, Feature feature, IPostOperationEnabled postOperationEnabled) {
61
		super(label, undoContext, (Taxon)null, postOperationEnabled);
62

    
63
		this.description = description;
64
		this.feature = feature;
65
	}
66

    
67
	/**
68
	 * <p>Constructor for CreateDescriptionElementOperation.</p>
69
	 *
70
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
71
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
72
	 * @param description a {@link DescriptionBase} object.
73
	 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
74
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
75
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
76
	 * @param label a {@link java.lang.String} object.
77
	 */
78
	public CreateDescriptionElementOperation(String label,
79
			IUndoContext undoContext, DescriptionBase<?> description, Feature feature,
80
			DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
81
		this(label, undoContext, description, feature, postOperationEnabled);
82

    
83
		this.element = element;
84
	}
85

    
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88
	 */
89
	/** {@inheritDoc} */
90
	@Override
91
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
92
			throws ExecutionException {
93

    
94
		monitor.worked(20);
95
		if (element == null) {
96
			if (feature.isSupportsCommonTaxonName()) {
97
				element = CommonTaxonName.NewInstance("", null);
98
			}
99
			else if (feature.isSupportsDistribution()) {
100
				element = Distribution.NewInstance();
101
			}
102
			else if(feature.isSupportsTaxonInteraction()){
103
				element = TaxonInteraction.NewInstance();
104
			}
105
			else if(feature.isSupportsIndividualAssociation()){
106
				element = IndividualsAssociation.NewInstance();
107
			}
108
			else if(feature.isSupportsCategoricalData()){
109
				element = CategoricalData.NewInstance();
110
			}
111
			else if(feature.isSupportsQuantitativeData()){
112
				element = QuantitativeData.NewInstance();
113
			}
114
			else {
115
				element = TextData.NewInstance();
116
			}
117
		}
118

    
119
		element.setFeature(feature);
120
		description.addElement(element);
121
		monitor.worked(40);
122

    
123
		return postExecute(element);
124
	}
125

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

    
134
		description.addElement(element);
135

    
136
		return postExecute(element);
137
	}
138

    
139
	/* (non-Javadoc)
140
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
141
	 */
142
	/** {@inheritDoc} */
143
	@Override
144
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
145
			throws ExecutionException {
146

    
147
		description.removeElement(element);
148

    
149
		return postExecute(null);
150
	}
151
}
(1-1/7)