2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.operations
;
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
;
18 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
22 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
25 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.model
.ImagesHelper
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class CreateDescriptionElementOperation
extends AbstractPostOperation
{
38 private TaxonDescription description
;
39 private Feature feature
;
40 private DescriptionElementBase element
;
42 public CreateDescriptionElementOperation(String label
, IUndoContext undoContext
,
43 Taxon taxon
, TaxonDescription description
, Feature feature
, IPostOperationEnabled postOperationEnabled
) {
44 super(label
, undoContext
, taxon
, postOperationEnabled
);
46 this.description
= description
;
47 this.feature
= feature
;
57 * @param postOperationEnabled
59 public CreateDescriptionElementOperation(String label
,
60 IUndoContext undoContext
, Taxon taxon
,
61 TaxonDescription description
, Feature feature
,
62 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
63 this(label
, undoContext
, taxon
, description
, feature
, postOperationEnabled
);
65 this.element
= element
;
69 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
72 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
73 throws ExecutionException
{
75 if (element
== null) {
76 if (feature
.isSupportsCommonTaxonName()) {
77 element
= CommonTaxonName
.NewInstance("", null);
78 } else if (feature
.isSupportsDistribution()) {
79 element
= Distribution
.NewInstance();
80 } else if (feature
.equals(Feature
.IMAGE())){
81 element
= ImagesHelper
.createImageElement(ImageFile
.NewInstance(null, null));
82 } else if(feature
.isSupportsTaxonInteraction()){
83 element
= TaxonInteraction
.NewInstance(feature
);
85 element
= TextData
.NewInstance(feature
);
88 description
.addElement(element
);
90 return postExecute(element
);
94 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
98 throws ExecutionException
{
100 description
.addElement(element
);
102 return postExecute(element
);
106 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
110 throws ExecutionException
{
112 description
.removeElement(element
);
114 return postExecute(null);