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
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
30 * <p>DeleteMediaHandler class.</p>
35 public class DeleteMediaHandler
extends AbstractHandler
{
38 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
42 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
43 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
45 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
46 if (editor
instanceof FormEditor
) {
47 editor
= ((FormEditor
) editor
).getActiveEditor();
49 IEditorInput input
= editor
.getEditorInput();
50 if (input
instanceof TaxonEditorInput
) {
51 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
53 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
54 if (selection
instanceof TreeSelection
) {
55 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
57 int count
= paths
[0].getSegmentCount();
58 DescriptionElementBase element
= null;
59 for (int i
= 0; i
< count
; i
++ ) {
60 if (paths
[0].getSegment(i
) instanceof DescriptionElementBase
) {
61 element
= (DescriptionElementBase
) paths
[0].getSegment(i
);
65 ImageFile image
= (ImageFile
) paths
[0].getLastSegment();
67 AbstractPostOperation operation
= null;
69 // TODO use undo context specific to editor
70 operation
= new RemoveImageFromDescriptionElementOperation(event
.getCommand().getName(),
71 EditorUtil
.getUndoContext(), taxon
, image
, element
, postOperationEnabled
);
72 EditorUtil
.executeOperation(operation
);
73 } catch (NotDefinedException e
) {
74 MessagingUtils
.warn(getClass(), "Command name not set.");