editor now updatable via updateSite
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / 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.store.operations;
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.model.description.DescriptionBase;
20 import eu.etaxonomy.cdm.model.media.ImageFile;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.store.model.ImagesUtil;
23
24 /**
25 * @author p.ciardelli
26 * @created 31.03.2009
27 * @version 1.0
28 */
29 public class CreateImageOperation extends AbstractPostOperation {
30
31 private ImageFile imageFile;
32
33 private DescriptionBase<?> description;
34
35 /**
36 * @param text
37 * @param undoContext
38 * @param taxon
39 * @param url
40 */
41 public CreateImageOperation(String label, IUndoContext undoContext,
42 Taxon taxon, DescriptionBase<?> description, ImageFile imageFile, IPostOperationEnabled postOperationEnabled) {
43 super(label, undoContext, taxon, postOperationEnabled);
44 this.imageFile = imageFile;
45 this.description = description;
46 }
47
48 /* (non-Javadoc)
49 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
50 */
51 @Override
52 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
53 throws ExecutionException {
54
55 ImagesUtil.addTaxonImage(taxon, description, imageFile);
56
57 return postExecute(null);
58 }
59
60 /* (non-Javadoc)
61 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 */
63 @Override
64 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
65 throws ExecutionException {
66
67 ImagesUtil.addTaxonImage(taxon, description, imageFile);
68
69 return postExecute(null);
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 @Override
76 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
77 throws ExecutionException {
78
79 ImagesUtil.removeTaxonImage(taxon, description, imageFile);
80
81 return postExecute(null);
82 }
83
84
85 }