1 |
3be6ef3e
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
7a0547ca
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
3be6ef3e
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
7a0547ca
|
Patric Plitzner
|
*
|
6 |
3be6ef3e
|
n.hoffmann
|
* 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 |
35861667
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
|
11 |
3be6ef3e
|
n.hoffmann
|
|
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 |
7a0547ca
|
Patric Plitzner
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
21 |
3be6ef3e
|
n.hoffmann
|
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 |
343457b6
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
30 |
35861667
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
31 |
3be6ef3e
|
n.hoffmann
|
|
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 |
343457b6
|
Patric Plitzner
|
public class CreateDescriptionElementOperation extends AbstractPostTaxonOperation {
|
41 |
7a0547ca
|
Patric Plitzner
|
|
42 |
3be6ef3e
|
n.hoffmann
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
|
43 |
150b624d
|
Patrick Plitzner
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.descriptive.command.createDescriptionElement"; //$NON-NLS-1$
|
44 |
7a0547ca
|
Patric Plitzner
|
|
45 |
|
|
private final DescriptionBase<?> description;
|
46 |
|
|
private final Feature feature;
|
47 |
3be6ef3e
|
n.hoffmann
|
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 |
7a0547ca
|
Patric Plitzner
|
* @param description a {@link DescriptionBase} object.
|
56 |
3be6ef3e
|
n.hoffmann
|
* @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
|
57 |
35861667
|
n.hoffmann
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
58 |
3be6ef3e
|
n.hoffmann
|
*/
|
59 |
|
|
public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
|
60 |
7a0547ca
|
Patric Plitzner
|
DescriptionBase<?> description, Feature feature, IPostOperationEnabled postOperationEnabled) {
|
61 |
|
|
super(label, undoContext, (Taxon)null, postOperationEnabled);
|
62 |
|
|
|
63 |
3be6ef3e
|
n.hoffmann
|
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 |
7a0547ca
|
Patric Plitzner
|
* @param description a {@link DescriptionBase} object.
|
73 |
3be6ef3e
|
n.hoffmann
|
* @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
|
74 |
|
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
75 |
35861667
|
n.hoffmann
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
76 |
3be6ef3e
|
n.hoffmann
|
* @param label a {@link java.lang.String} object.
|
77 |
|
|
*/
|
78 |
|
|
public CreateDescriptionElementOperation(String label,
|
79 |
7a0547ca
|
Patric Plitzner
|
IUndoContext undoContext, DescriptionBase<?> description, Feature feature,
|
80 |
3be6ef3e
|
n.hoffmann
|
DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
|
81 |
7a0547ca
|
Patric Plitzner
|
this(label, undoContext, description, feature, postOperationEnabled);
|
82 |
|
|
|
83 |
3be6ef3e
|
n.hoffmann
|
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 |
150b624d
|
Patrick Plitzner
|
element = CommonTaxonName.NewInstance("", null); //$NON-NLS-1$
|
98 |
7a0547ca
|
Patric Plitzner
|
}
|
99 |
3be6ef3e
|
n.hoffmann
|
else if (feature.isSupportsDistribution()) {
|
100 |
|
|
element = Distribution.NewInstance();
|
101 |
7a0547ca
|
Patric Plitzner
|
}
|
102 |
3be6ef3e
|
n.hoffmann
|
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 |
7a0547ca
|
Patric Plitzner
|
|
134 |
3be6ef3e
|
n.hoffmann
|
description.addElement(element);
|
135 |
7a0547ca
|
Patric Plitzner
|
|
136 |
3be6ef3e
|
n.hoffmann
|
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 |
7a0547ca
|
Patric Plitzner
|
|
147 |
3be6ef3e
|
n.hoffmann
|
description.removeElement(element);
|
148 |
7a0547ca
|
Patric Plitzner
|
|
149 |
3be6ef3e
|
n.hoffmann
|
return postExecute(null);
|
150 |
|
|
}
|
151 |
|
|
}
|