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
.api
.utility
.ImagesUtility
;
19 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
25 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
26 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
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 // Start the main progress monitor.
76 IProgressMonitor newMonitor
= StoreUtil
.startMainMonitor(monitor
,"Creating Description Element", 3);
84 if (element
== null) {
85 if (feature
.isSupportsCommonTaxonName()) {
86 element
= CommonTaxonName
.NewInstance("", null);
87 } else if (feature
.isSupportsDistribution()) {
88 element
= Distribution
.NewInstance();
89 } else if (feature
.equals(Feature
.IMAGE())){
90 element
= ImagesUtility
.createImageElement(ImageFile
.NewInstance(null, null));
91 } else if(feature
.isSupportsTaxonInteraction()){
92 element
= TaxonInteraction
.NewInstance(feature
);
94 element
= TextData
.NewInstance(feature
);
97 StoreUtil
.isCanceled(newMonitor
, 1);
99 description
.addElement(element
);
100 StoreUtil
.isCanceled(newMonitor
, 1);
104 // Stop the progress monitor.
108 return postExecute(element
);
112 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
116 throws ExecutionException
{
118 description
.addElement(element
);
120 return postExecute(element
);
124 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
127 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
128 throws ExecutionException
{
130 description
.removeElement(element
);
132 return postExecute(null);