merged campanula branch to trunk. Main features are: BioCase Query via Imports, Deriv...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / media / operation / 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.editor.view.media.operation;
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.taxeditor.operation.AbstractPostTaxonOperation;
22 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23 /**
24 * <p>AddMediaToImageGalleryOperation class.</p>
25 *
26 * @author p.ciardelli
27 * @author n.hoffmann
28 * @created 05.02.2009
29 * @version 1.0
30 */
31 public class AddMediaToImageGalleryOperation extends AbstractPostTaxonOperation {
32
33 private DescriptionBase description;
34 private Media media;
35
36 /**
37 * <p>Constructor for AddMediaToImageGalleryOperation.</p>
38 *
39 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
40 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
41 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
42 * @param label a {@link java.lang.String} object.
43 * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
44 */
45 public AddMediaToImageGalleryOperation(String label,
46 IUndoContext undoContext, DescriptionBase description, IPostOperationEnabled postOperationEnabled) {
47 super(label, undoContext, 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 }