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.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
|
|
24
|
/**
|
25
|
* <p>CreateImageOperation class.</p>
|
26
|
*
|
27
|
* @author p.ciardelli
|
28
|
* @created 31.03.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class CreateImageOperation extends AbstractPostOperation {
|
32
|
|
33
|
private ImageFile imageFile;
|
34
|
|
35
|
private DescriptionBase<?> description;
|
36
|
|
37
|
/**
|
38
|
* <p>Constructor for CreateImageOperation.</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 label a {@link java.lang.String} object.
|
43
|
* @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
|
44
|
* @param imageFile a {@link eu.etaxonomy.cdm.model.media.ImageFile} object.
|
45
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
|
46
|
*/
|
47
|
public CreateImageOperation(String label, IUndoContext undoContext,
|
48
|
Taxon taxon, DescriptionBase<?> description, ImageFile imageFile, IPostOperationEnabled postOperationEnabled) {
|
49
|
super(label, undoContext, taxon, postOperationEnabled);
|
50
|
this.imageFile = imageFile;
|
51
|
this.description = description;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* <p>Constructor for CreateImageOperation.</p>
|
56
|
*
|
57
|
* @param label a {@link java.lang.String} object.
|
58
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
59
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
60
|
* @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
|
61
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
|
62
|
*/
|
63
|
public CreateImageOperation(String label, IUndoContext undoContext,
|
64
|
Taxon taxon, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
|
65
|
super(label, undoContext, taxon, postOperationEnabled);
|
66
|
this.description = description;
|
67
|
}
|
68
|
|
69
|
/* (non-Javadoc)
|
70
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
71
|
*/
|
72
|
/** {@inheritDoc} */
|
73
|
@Override
|
74
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
75
|
throws ExecutionException {
|
76
|
|
77
|
if (imageFile == null) {
|
78
|
imageFile = ImageFile.NewInstance(null, null);
|
79
|
}
|
80
|
monitor.worked(20);
|
81
|
|
82
|
ImagesUtility.addTaxonImage(taxon, description, imageFile);
|
83
|
monitor.worked(40);
|
84
|
|
85
|
return postExecute(imageFile);
|
86
|
}
|
87
|
|
88
|
/* (non-Javadoc)
|
89
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
90
|
*/
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
94
|
throws ExecutionException {
|
95
|
|
96
|
ImagesUtility.addTaxonImage(taxon, description, imageFile);
|
97
|
|
98
|
return postExecute(imageFile);
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
103
|
*/
|
104
|
/** {@inheritDoc} */
|
105
|
@Override
|
106
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
107
|
throws ExecutionException {
|
108
|
|
109
|
ImagesUtility.removeTaxonImage(taxon, description, imageFile);
|
110
|
|
111
|
return postExecute(null);
|
112
|
}
|
113
|
|
114
|
|
115
|
}
|