performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / CreateTaxonDescriptionOperation.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.operations;
11
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;
17
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
24 /**
25 * <p>CreateTaxonDescriptionOperation class.</p>
26 *
27 * @author p.ciardelli
28 * @author n.hoffmann
29 * @created 05.02.2009
30 * @version 1.0
31 */
32 public class CreateTaxonDescriptionOperation extends AbstractPostOperation {
33
34 private TaxonDescription description;
35 private boolean isImageGallery;
36
37 /**
38 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
39 *
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.
44 */
45 public CreateTaxonDescriptionOperation(String label, IUndoContext undoContext,
46 Taxon taxon, IPostOperationEnabled postOperationEnabled) {
47 this(label, undoContext, taxon, postOperationEnabled, false);
48 }
49
50 /**
51 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
52 *
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.
58 */
59 public CreateTaxonDescriptionOperation(String label, IUndoContext undoContext,
60 Taxon taxon, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
61 super(label, undoContext, taxon, postOperationEnabled);
62
63 this.isImageGallery = isImageGallery;
64 }
65
66 /* (non-Javadoc)
67 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 */
69 /** {@inheritDoc} */
70 @Override
71 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
72 throws ExecutionException {
73
74 description = TaxonDescription.NewInstance(taxon);
75 monitor.worked(20);
76
77 if(isImageGallery){
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);
83 }
84 monitor.worked(40);
85
86 return postExecute(description);
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 */
92 /** {@inheritDoc} */
93 @Override
94 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
95 throws ExecutionException {
96
97 taxon.addDescription(description);
98
99 return postExecute(description);
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
104 */
105 /** {@inheritDoc} */
106 @Override
107 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
108 throws ExecutionException {
109
110 taxon.removeDescription(description);
111
112 return postExecute(null);
113 }
114 }