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