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
.IEditorPart
;
14 import org
.eclipse
.ui
.IWorkbenchPart
;
15 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
16 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
18 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
19 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
20 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.AddMediaToImageGalleryOperation
;
21 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
22 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
25 * <p>CreateMediaHandler class.</p>
30 public class CreateMediaHandler
extends AbstractHandler
{
33 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
37 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
38 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
41 DescriptionBase description
= null;
43 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
44 if (editor
instanceof FormEditor
) {
45 editor
= ((FormEditor
) editor
).getActiveEditor();
48 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
49 if (selection
instanceof TreeSelection
) {
50 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
52 int count
= paths
[0].getSegmentCount();
54 for (int i
= 0; i
< count
; i
++ ) {
55 if (paths
[0].getSegment(i
) instanceof DescriptionBase
) {
56 description
= (DescriptionBase
) paths
[0].getSegment(i
);
62 if(description
!= null){
63 AbstractPostOperation operation
= null;
65 // TODO use undo context specific to editor
66 operation
= new AddMediaToImageGalleryOperation(event
.getCommand().getName(),
67 EditorUtil
.getUndoContext(), description
, postOperationEnabled
);
68 EditorUtil
.executeOperation(operation
);
69 } catch (NotDefinedException e
) {
70 EditorUtil
.warn(getClass(), "Command name not set.");