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
.editor
.view
.descriptive
.operation
;
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
.Feature
;
19 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
21 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 * <p>CreateTaxonDescriptionOperation class.</p>
34 public class CreateTaxonDescriptionOperation
extends AbstractPostOperation
{
36 private TaxonDescription description
;
37 private boolean isImageGallery
;
40 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
47 public CreateTaxonDescriptionOperation(String label
, IUndoContext undoContext
,
48 Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
49 this(label
, undoContext
, taxon
, postOperationEnabled
, false);
53 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
55 * @param label a {@link java.lang.String} object.
56 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
58 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59 * @param isImageGallery a boolean.
61 public CreateTaxonDescriptionOperation(String label
, IUndoContext undoContext
,
62 Taxon taxon
, IPostOperationEnabled postOperationEnabled
, boolean isImageGallery
) {
63 super(label
, undoContext
, taxon
, postOperationEnabled
);
65 this.isImageGallery
= isImageGallery
;
69 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
73 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
74 throws ExecutionException
{
76 description
= TaxonDescription
.NewInstance(taxon
);
80 description
.setImageGallery(isImageGallery
);
81 // add the description element to hold the media elements for this image gallery
82 TextData element
= TextData
.NewInstance(Feature
.IMAGE());
83 element
.addMedia(Media
.NewInstance());
84 description
.addElement(element
);
88 return postExecute(description
);
92 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
97 throws ExecutionException
{
99 taxon
.addDescription(description
);
101 return postExecute(description
);
105 * @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 taxon
.removeDescription(description
);
114 return postExecute(null);