AT: Comminting updates to comply to TaxEditor CDMStore functions
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / operation / CreateTaxonUseOperation.java
1 package eu.etaxonomy.taxeditor.editor.view.uses.operation;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
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;
11
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;
22
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;
28
29 /**
30 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
31 *
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.
36 */
37 public CreateTaxonUseOperation(String label, IUndoContext undoContext,
38 Taxon taxon, IPostOperationEnabled postOperationEnabled) {
39 this(label, undoContext, taxon, postOperationEnabled, false);
40 }
41
42 /**
43 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
44 *
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.
50 */
51 public CreateTaxonUseOperation(String label, IUndoContext undoContext,
52 Taxon taxon, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
53 super(label, undoContext, taxon, postOperationEnabled);
54 this.isImageGallery = isImageGallery;
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 */
60 /** {@inheritDoc} */
61 @Override
62 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63 throws ExecutionException {
64
65 description = TaxonDescription.NewInstance(taxon);
66 monitor.worked(20);
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);
74 }
75 }
76 if(isImageGallery){
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);
82 }
83 monitor.worked(40);
84
85 return postExecute(description);
86 }
87
88 /* (non-Javadoc)
89 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 */
91 /** {@inheritDoc} */
92 @Override
93 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95
96 taxon.addDescription(description);
97
98 return postExecute(description);
99 }
100
101 /* (non-Javadoc)
102 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
103 */
104 /** {@inheritDoc} */
105 @Override
106 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
107 throws ExecutionException {
108
109 taxon.removeDescription(description);
110
111 return postExecute(null);
112 }
113 }
114