performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / AddMediaToImageGalleryOperation.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.api.utility.ImagesUtility;
19 import eu.etaxonomy.cdm.model.description.DescriptionBase;
20 import eu.etaxonomy.cdm.model.media.Media;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 /**
23 * <p>AddMediaToImageGalleryOperation class.</p>
24 *
25 * @author p.ciardelli
26 * @author n.hoffmann
27 * @created 05.02.2009
28 * @version 1.0
29 */
30 public class AddMediaToImageGalleryOperation extends AbstractPostOperation {
31
32 private DescriptionBase description;
33 private Media media;
34
35 /**
36 * <p>Constructor for AddMediaToImageGalleryOperation.</p>
37 *
38 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
39 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
40 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
41 * @param label a {@link java.lang.String} object.
42 * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
43 */
44 public AddMediaToImageGalleryOperation(String label,
45 IUndoContext undoContext, Taxon taxon,
46 DescriptionBase description, IPostOperationEnabled postOperationEnabled) {
47 super(label, undoContext, taxon, postOperationEnabled);
48
49 this.description = description;
50 media = Media.NewInstance();
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 */
56 /** {@inheritDoc} */
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 monitor.worked(20);
62
63 ImagesUtility.addMediaToGallery(description, media);
64
65 monitor.worked(40);
66
67 return postExecute(media);
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
72 */
73 /** {@inheritDoc} */
74 @Override
75 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
76 throws ExecutionException {
77 return execute(monitor, info);
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 */
83 /** {@inheritDoc} */
84 @Override
85 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87 ImagesUtility.removeMediaFromGallery(description, media);
88 return postExecute(description);
89 }
90 }