5ffef32fb593cc3c3e659a28b452346c647c0624
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / DeleteImageOperation.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.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.model.ImagesHelper;
23 import eu.etaxonomy.taxeditor.store.StoreUtil;
24
25 /**
26 * @author p.ciardelli
27 * @created 31.03.2009
28 * @version 1.0
29 */
30 public class DeleteImageOperation extends AbstractPostOperation {
31
32 private ImageFile imageFile;
33
34 private DescriptionBase<?> description;
35
36 /**
37 * @param text
38 * @param undoContext
39 * @param taxon
40 * @param url
41 */
42 public DeleteImageOperation(String label, IUndoContext undoContext,
43 Taxon taxon, DescriptionBase<?> description, ImageFile imageFile, IPostOperationEnabled postOperationEnabled) {
44 super(label, undoContext, taxon, postOperationEnabled);
45
46 this.imageFile = imageFile;
47 this.description = description;
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
52 */
53 @Override
54 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55 throws ExecutionException {
56
57 // Start the main progress monitor.
58 IProgressMonitor newMonitor = StoreUtil.startMainMonitor(monitor,"Deleting Image", 2);
59
60 // Do one step
61 newMonitor.worked(1);
62
63 try {
64 // Operation steps
65
66 ImagesHelper.removeTaxonImage(taxon, description, imageFile);
67 StoreUtil.isCanceled(newMonitor, 1);
68 }
69 finally {
70
71 // Stop the progress monitor.
72 newMonitor.done();
73 }
74
75 return postExecute(null);
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 @Override
82 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
83 throws ExecutionException {
84 return execute(monitor, info);
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 */
90 @Override
91 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92 throws ExecutionException {
93
94 ImagesHelper.addTaxonImage(taxon, description, imageFile);
95
96 return postExecute(null);
97 }
98
99
100 }