2 * Copyright (C) 2011 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
.operation
;
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
;
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
;
28 * CreateUseRecordOperation Class
30 * @created mar 13, 2012
32 public class CreateUseRecordOperation
extends AbstractPostOperation
<Taxon
> {
34 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.use."{trunked}</code> */
35 public static final String ID
= "eu.etaxonomy.taxeditor.editor.use.createUseRecord"; //$NON-NLS-1$
36 private final DescriptionBase
<?
> description
;
37 private final Feature feature
;
38 private DescriptionElementBase element
;
41 * <p>Constructor for CreateUseRecordOperation.</p>
43 * @param label a {@link java.lang.String} object.
44 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
45 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
46 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
47 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
48 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
50 public CreateUseRecordOperation(String label
, IUndoContext undoContext
, DescriptionBase
<?
> description
,
51 Feature feature
, IPostOperationEnabled postOperationEnabled
) {
52 super(label
, undoContext
, null, postOperationEnabled
);
54 this.description
= description
;
55 this.feature
= feature
;
59 * <p>Constructor for CreateUseRecordOperation.</p>
61 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
62 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
63 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
64 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
65 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
66 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
67 * @param label a {@link java.lang.String} object.
69 public CreateUseRecordOperation(String label
,
70 IUndoContext undoContext
, Taxon taxon
,
71 TaxonDescription description
, Feature feature
,
72 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
73 this(label
, undoContext
, description
, feature
, postOperationEnabled
);
75 this.element
= element
;
79 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
80 throws ExecutionException
{
82 if (element
== null) {
83 if(feature
.isSupportsCategoricalData()){
84 element
= CategoricalData
.NewInstance();
87 element
= TextData
.NewInstance();
92 element
.setFeature(feature
);
93 description
.addElement(element
);
96 return postExecute(element
);
100 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
101 throws ExecutionException
{
103 description
.addElement(element
);
105 return postExecute(element
);
109 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
110 throws ExecutionException
{
111 description
.removeElement(element
);
113 return postExecute(null);