4 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
.handler
;
6 import org
.eclipse
.core
.commands
.AbstractHandler
;
7 import org
.eclipse
.core
.commands
.ExecutionEvent
;
8 import org
.eclipse
.core
.commands
.ExecutionException
;
9 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
10 import org
.eclipse
.jface
.viewers
.ISelection
;
11 import org
.eclipse
.jface
.viewers
.TreePath
;
12 import org
.eclipse
.jface
.viewers
.TreeSelection
;
13 import org
.eclipse
.ui
.IEditorInput
;
14 import org
.eclipse
.ui
.IEditorPart
;
15 import org
.eclipse
.ui
.IWorkbenchPart
;
16 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
17 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
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
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
24 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.RemoveImageFromDescriptionElementOperation
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
29 * <p>DeleteMediaHandler class.</p>
34 public class DeleteMediaHandler
extends AbstractHandler
{
37 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
42 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
44 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
45 if (editor
instanceof FormEditor
) {
46 editor
= ((FormEditor
) editor
).getActiveEditor();
48 IEditorInput input
= editor
.getEditorInput();
49 if (input
instanceof TaxonEditorInput
) {
50 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
52 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
53 if (selection
instanceof TreeSelection
) {
54 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
56 int count
= paths
[0].getSegmentCount();
57 DescriptionElementBase element
= null;
58 for (int i
= 0; i
< count
; i
++ ) {
59 if (paths
[0].getSegment(i
) instanceof DescriptionElementBase
) {
60 element
= (DescriptionElementBase
) paths
[0].getSegment(i
);
64 ImageFile image
= (ImageFile
) paths
[0].getLastSegment();
66 AbstractPostOperation operation
= null;
68 // TODO use undo context specific to editor
69 operation
= new RemoveImageFromDescriptionElementOperation(event
.getCommand().getName(),
70 EditorUtil
.getUndoContext(), taxon
, image
, element
, postOperationEnabled
);
71 EditorUtil
.executeOperation(operation
);
72 } catch (NotDefinedException e
) {
73 EditorUtil
.warn(getClass(), "Command name not set.");