merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / media / operation / CreateImageOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.view.media.operation;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.api.utility.ImagesUtility;
20 import eu.etaxonomy.cdm.model.description.DescriptionBase;
21 import eu.etaxonomy.cdm.model.media.ImageFile;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25
26 /**
27 * <p>CreateImageOperation class.</p>
28 *
29 * @author p.ciardelli
30 * @created 31.03.2009
31 * @version 1.0
32 */
33 public class CreateImageOperation extends AbstractPostTaxonOperation {
34
35 private ImageFile imageFile;
36
37 private final DescriptionBase<?> description;
38
39 /**
40 * <p>Constructor for CreateImageOperation.</p>
41 *
42 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
43 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
44 * @param label a {@link java.lang.String} object.
45 * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
46 * @param imageFile a {@link eu.etaxonomy.cdm.model.media.ImageFile} object.
47 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
48 */
49 public CreateImageOperation(String label, IUndoContext undoContext,
50 Taxon taxon, DescriptionBase<?> description, ImageFile imageFile, IPostOperationEnabled postOperationEnabled) {
51 super(label, undoContext, taxon, postOperationEnabled);
52 this.imageFile = imageFile;
53 this.description = description;
54 }
55
56 /**
57 * <p>Constructor for CreateImageOperation.</p>
58 *
59 * @param label a {@link java.lang.String} object.
60 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
61 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
62 * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
63 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
64 */
65 public CreateImageOperation(String label, IUndoContext undoContext,
66 Taxon taxon, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
67 super(label, undoContext, taxon, postOperationEnabled);
68 this.description = description;
69 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
73 */
74 /** {@inheritDoc} */
75 @Override
76 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
77 throws ExecutionException {
78
79 if (imageFile == null) {
80 imageFile = ImageFile.NewInstance(null, null);
81 }
82 monitor.worked(20);
83
84 ImagesUtility.addTaxonImage(element, description, imageFile);
85 monitor.worked(40);
86
87 return postExecute(imageFile);
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
92 */
93 /** {@inheritDoc} */
94 @Override
95 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
96 throws ExecutionException {
97
98 ImagesUtility.addTaxonImage(element, description, imageFile);
99
100 return postExecute(imageFile);
101 }
102
103 /* (non-Javadoc)
104 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 */
106 /** {@inheritDoc} */
107 @Override
108 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
109 throws ExecutionException {
110
111 ImagesUtility.removeTaxonImage(element, description, imageFile);
112
113 return postExecute(null);
114 }
115
116
117 }