1 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
.operation
;
3 import java
.util
.HashSet
;
6 import org
.eclipse
.core
.commands
.ExecutionException
;
7 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
8 import org
.eclipse
.core
.runtime
.IAdaptable
;
9 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
10 import org
.eclipse
.core
.runtime
.IStatus
;
12 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
13 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
14 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
15 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
16 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
17 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
19 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
20 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
21 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
27 * @created mar 13, 2012
30 public class CreateTaxonUseOperation
extends AbstractPostOperation
{
31 private TaxonDescription description
;
32 private boolean isImageGallery
;
33 private Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
34 private Marker marker
;
37 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
39 * @param label a {@link java.lang.String} object.
40 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
41 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
42 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
44 public CreateTaxonUseOperation(String label
, IUndoContext undoContext
,
45 Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
46 this(label
, undoContext
, taxon
, postOperationEnabled
, false);
50 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
52 * @param label a {@link java.lang.String} object.
53 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56 * @param isImageGallery a boolean.
58 public CreateTaxonUseOperation(String label
, IUndoContext undoContext
,
59 Taxon taxon
, IPostOperationEnabled postOperationEnabled
, boolean isImageGallery
) {
60 super(label
, undoContext
, taxon
, postOperationEnabled
);
61 this.isImageGallery
= isImageGallery
;
65 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
69 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
70 throws ExecutionException
{
72 description
= TaxonDescription
.NewInstance(taxon
);
74 //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());
75 this.markerTypes
.addAll(CdmStore
.getTermManager().getPreferredTerms(MarkerType
.class));
76 for (MarkerType markerType
: markerTypes
) {
77 if (markerType
.getTitleCache().equals("use")) {
78 marker
= Marker
.NewInstance(markerType
, true);
79 description
.addMarker(marker
);
83 description
.setImageGallery(isImageGallery
);
84 // add the description element to hold the media elements for this image gallery
85 TextData element
= TextData
.NewInstance(Feature
.IMAGE());
86 element
.addMedia(Media
.NewInstance());
87 description
.addElement(element
);
91 return postExecute(description
);
95 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
99 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
100 throws ExecutionException
{
102 taxon
.addDescription(description
);
104 return postExecute(description
);
108 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
113 throws ExecutionException
{
115 taxon
.removeDescription(description
);
117 return postExecute(null);