1
|
/**
|
2
|
* Copyright (C) 2011 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.editor.view.uses.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
|
|
17
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
18
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
22
|
import eu.etaxonomy.cdm.model.description.TextData;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
26
|
|
27
|
|
28
|
/**
|
29
|
* CreateUseRecordOperation Class
|
30
|
* @author a.theys
|
31
|
* @created mar 13, 2012
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class CreateUseRecordOperation extends AbstractPostOperation {
|
35
|
|
36
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.use."{trunked}</code> */
|
37
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.use.createUseRecord"; //$NON-NLS-1$
|
38
|
private final DescriptionBase<?> description;
|
39
|
private final Feature feature;
|
40
|
private DescriptionElementBase element;
|
41
|
|
42
|
/**
|
43
|
* <p>Constructor for CreateUseRecordOperation.</p>
|
44
|
*
|
45
|
* @param label a {@link java.lang.String} object.
|
46
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
47
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
48
|
* @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
|
49
|
* @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
|
50
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
51
|
*/
|
52
|
public CreateUseRecordOperation(String label, IUndoContext undoContext, DescriptionBase<?> description,
|
53
|
Feature feature, IPostOperationEnabled postOperationEnabled) {
|
54
|
super(label, undoContext, null, postOperationEnabled);
|
55
|
|
56
|
this.description = description;
|
57
|
this.feature = feature;
|
58
|
}
|
59
|
|
60
|
|
61
|
/**
|
62
|
* <p>Constructor for CreateUseRecordOperation.</p>
|
63
|
*
|
64
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
65
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
66
|
* @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
|
67
|
* @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
|
68
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
69
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
70
|
* @param label a {@link java.lang.String} object.
|
71
|
*/
|
72
|
public CreateUseRecordOperation(String label,
|
73
|
IUndoContext undoContext, Taxon taxon,
|
74
|
TaxonDescription description, Feature feature,
|
75
|
DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
|
76
|
this(label, undoContext, description, feature, postOperationEnabled);
|
77
|
|
78
|
this.element = element;
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
83
|
throws ExecutionException {
|
84
|
monitor.worked(20);
|
85
|
if (element == null) {
|
86
|
if(feature.isSupportsCategoricalData()){
|
87
|
element = CategoricalData.NewInstance();
|
88
|
}
|
89
|
else {
|
90
|
element = TextData.NewInstance();
|
91
|
}
|
92
|
}
|
93
|
|
94
|
|
95
|
element.setFeature(feature);
|
96
|
description.addElement(element);
|
97
|
monitor.worked(40);
|
98
|
|
99
|
return postExecute(element);
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
104
|
throws ExecutionException {
|
105
|
|
106
|
description.addElement(element);
|
107
|
|
108
|
return postExecute(element);
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
113
|
throws ExecutionException {
|
114
|
description.removeElement(element);
|
115
|
|
116
|
return postExecute(null);
|
117
|
}
|
118
|
}
|