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.ImageFile;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
23
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
24
|
|
25
|
/**
|
26
|
* <p>CreateImageOperation class.</p>
|
27
|
*
|
28
|
* @author p.ciardelli
|
29
|
* @created 31.03.2009
|
30
|
*/
|
31
|
public class CreateImageOperation extends AbstractPostTaxonOperation {
|
32
|
|
33
|
private ImageFile imageFile;
|
34
|
|
35
|
private final 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.operation.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.operation.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
|
/** {@inheritDoc} */
|
70
|
@Override
|
71
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
72
|
throws ExecutionException {
|
73
|
|
74
|
if (imageFile == null) {
|
75
|
imageFile = ImageFile.NewInstance(null, null);
|
76
|
}
|
77
|
monitor.worked(20);
|
78
|
|
79
|
ImagesUtility.addTaxonImage(element, description, imageFile);
|
80
|
monitor.worked(40);
|
81
|
|
82
|
return postExecute(imageFile);
|
83
|
}
|
84
|
|
85
|
/** {@inheritDoc} */
|
86
|
@Override
|
87
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
88
|
throws ExecutionException {
|
89
|
|
90
|
ImagesUtility.addTaxonImage(element, description, imageFile);
|
91
|
|
92
|
return postExecute(imageFile);
|
93
|
}
|
94
|
|
95
|
/** {@inheritDoc} */
|
96
|
@Override
|
97
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
98
|
throws ExecutionException {
|
99
|
|
100
|
ImagesUtility.removeTaxonImage(element, description, imageFile);
|
101
|
|
102
|
return postExecute(null);
|
103
|
}
|
104
|
|
105
|
|
106
|
}
|