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
.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
;
25 * <p>CreateTaxonDescriptionOperation class.</p>
32 public class CreateTaxonDescriptionOperation
extends AbstractPostOperation
{
34 private TaxonDescription description
;
35 private boolean isImageGallery
;
38 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
40 * @param label a {@link java.lang.String} object.
41 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
42 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
43 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
45 public CreateTaxonDescriptionOperation(String label
, IUndoContext undoContext
,
46 Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
47 this(label
, undoContext
, taxon
, postOperationEnabled
, false);
51 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
53 * @param label a {@link java.lang.String} object.
54 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
55 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
56 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
57 * @param isImageGallery a boolean.
59 public CreateTaxonDescriptionOperation(String label
, IUndoContext undoContext
,
60 Taxon taxon
, IPostOperationEnabled postOperationEnabled
, boolean isImageGallery
) {
61 super(label
, undoContext
, taxon
, postOperationEnabled
);
63 this.isImageGallery
= isImageGallery
;
67 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
71 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
72 throws ExecutionException
{
74 description
= TaxonDescription
.NewInstance(taxon
);
78 description
.setImageGallery(isImageGallery
);
79 // add the description element to hold the media elements for this image gallery
80 TextData element
= TextData
.NewInstance(Feature
.IMAGE());
81 element
.addMedia(Media
.NewInstance());
82 description
.addElement(element
);
86 return postExecute(description
);
90 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
94 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
95 throws ExecutionException
{
97 taxon
.addDescription(description
);
99 return postExecute(description
);
103 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
107 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
108 throws ExecutionException
{
110 taxon
.removeDescription(description
);
112 return postExecute(null);