2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.operations
;
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 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
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
;
31 public class AddImageToDescriptionElementOperation
extends AbstractPostOperation
{
33 private DescriptionElementBase element
;
34 private ImageFile image
;
41 * @param postOperationEnabled
43 public AddImageToDescriptionElementOperation(String label
,
44 IUndoContext undoContext
, Taxon taxon
,
45 DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
46 super(label
, undoContext
, taxon
, postOperationEnabled
);
48 this.element
= element
;
52 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
56 throws ExecutionException
{
58 // Start the main progress monitor.
59 IProgressMonitor newMonitor
= StoreUtil
.startMainMonitor(monitor
,"Adding Image to Description Element", 2);
66 image
= ImagesHelper
.addImagePart(element
);
67 StoreUtil
.isCanceled(newMonitor
, 1);
71 // Stop the progress monitor.
75 return postExecute(image
);
79 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
83 throws ExecutionException
{
84 return execute(monitor
, info
);
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
93 ImagesHelper
.removeImage(element
, image
);
94 return postExecute(element
);