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
.DescriptionElementBase
;
19 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 * CreateUseRecordOperation Class
30 * @created mar 13, 2012
33 public class CreateUseRecordOperation
extends AbstractPostOperation
{
35 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.use."{trunked}</code> */
36 public static final String ID
= "eu.etaxonomy.taxeditor.editor.use.createUseRecord";
37 private TaxonDescription description
;
38 private Feature feature
;
39 private DescriptionElementBase element
;
42 * <p>Constructor for CreateUseRecordOperation.</p>
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.
51 public CreateUseRecordOperation(String label
, IUndoContext undoContext
,
52 Taxon taxon
, TaxonDescription description
, Feature feature
, IPostOperationEnabled postOperationEnabled
) {
53 super(label
, undoContext
, taxon
, postOperationEnabled
);
55 this.description
= description
;
56 this.feature
= feature
;
61 * <p>Constructor for CreateUseRecordOperation.</p>
63 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
64 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
65 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
66 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
67 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
68 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
69 * @param label a {@link java.lang.String} object.
71 public CreateUseRecordOperation(String label
,
72 IUndoContext undoContext
, Taxon taxon
,
73 TaxonDescription description
, Feature feature
,
74 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
75 this(label
, undoContext
, taxon
, description
, feature
, postOperationEnabled
);
77 this.element
= element
;
81 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
82 throws ExecutionException
{
84 if (element
== null) {
85 if(feature
.isSupportsCategoricalData()){
86 element
= CategoricalData
.NewInstance();
89 element
= TextData
.NewInstance();
94 element
.setFeature(feature
);
95 description
.addElement(element
);
98 return postExecute(element
);
102 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
103 throws ExecutionException
{
105 description
.addElement(element
);
107 return postExecute(element
);
111 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
112 throws ExecutionException
{
113 description
.removeElement(element
);
115 return postExecute(null);