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
;
23 public class CreateTaxonUseOperation
extends AbstractPostOperation
{
24 private TaxonDescription description
;
25 private boolean isImageGallery
;
26 private Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
27 private Marker marker
;
30 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
32 * @param label a {@link java.lang.String} object.
33 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
34 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
35 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
37 public CreateTaxonUseOperation(String label
, IUndoContext undoContext
,
38 Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
39 this(label
, undoContext
, taxon
, postOperationEnabled
, false);
43 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
45 * @param label a {@link java.lang.String} object.
46 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
48 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
49 * @param isImageGallery a boolean.
51 public CreateTaxonUseOperation(String label
, IUndoContext undoContext
,
52 Taxon taxon
, IPostOperationEnabled postOperationEnabled
, boolean isImageGallery
) {
53 super(label
, undoContext
, taxon
, postOperationEnabled
);
54 this.isImageGallery
= isImageGallery
;
58 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
63 throws ExecutionException
{
65 description
= TaxonDescription
.NewInstance(taxon
);
67 //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());
68 this.markerTypes
.addAll(CdmStore
.getTermManager().getPreferredTerms(MarkerType
.class));
69 Set
<MarkerType
> typesToDisdplay
= new HashSet
<MarkerType
>();
70 for (MarkerType markerType
: markerTypes
) {
71 if (markerType
.getTitleCache().equals("use")) {
72 marker
= Marker
.NewInstance(markerType
, true);
73 description
.addMarker(marker
);
77 description
.setImageGallery(isImageGallery
);
78 // add the description element to hold the media elements for this image gallery
79 TextData element
= TextData
.NewInstance(Feature
.IMAGE());
80 element
.addMedia(Media
.NewInstance());
81 description
.addElement(element
);
85 return postExecute(description
);
89 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
94 throws ExecutionException
{
96 taxon
.addDescription(description
);
98 return postExecute(description
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
109 taxon
.removeDescription(description
);
111 return postExecute(null);