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