4 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
.handler
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.eclipse
.core
.commands
.AbstractHandler
;
8 import org
.eclipse
.core
.commands
.ExecutionEvent
;
9 import org
.eclipse
.core
.commands
.ExecutionException
;
10 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
11 import org
.eclipse
.jface
.viewers
.ISelection
;
12 import org
.eclipse
.jface
.viewers
.TreePath
;
13 import org
.eclipse
.jface
.viewers
.TreeSelection
;
14 import org
.eclipse
.ui
.IEditorInput
;
15 import org
.eclipse
.ui
.IEditorPart
;
16 import org
.eclipse
.ui
.IWorkbenchPart
;
17 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
18 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
21 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.operations
.AbstractPostOperation
;
26 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.operations
.RemoveImageFromDescriptionElementOperation
;
30 * <p>DeleteMediaHandler class.</p>
35 public class DeleteMediaHandler
extends AbstractHandler
{
36 private static final Logger logger
= Logger
37 .getLogger(DeleteMediaHandler
.class);
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
45 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
47 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
48 if (editor
instanceof FormEditor
) {
49 editor
= ((FormEditor
) editor
).getActiveEditor();
51 IEditorInput input
= editor
.getEditorInput();
52 if (input
instanceof TaxonEditorInput
) {
53 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
55 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
56 if (selection
instanceof TreeSelection
) {
57 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
59 int count
= paths
[0].getSegmentCount();
60 DescriptionElementBase element
= null;
61 for (int i
= 0; i
< count
; i
++ ) {
62 if (paths
[0].getSegment(i
) instanceof DescriptionElementBase
) {
63 element
= (DescriptionElementBase
) paths
[0].getSegment(i
);
67 ImageFile image
= (ImageFile
) paths
[0].getLastSegment();
69 AbstractPostOperation operation
= null;
71 // TODO use undo context specific to editor
72 operation
= new RemoveImageFromDescriptionElementOperation(event
.getCommand().getName(),
73 EditorUtil
.getUndoContext(), taxon
, image
, element
, postOperationEnabled
);
74 EditorUtil
.executeOperation(operation
);
75 } catch (NotDefinedException e
) {
76 logger
.warn("Command name not set");