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
.model
.MessagingUtils
;
22 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
23 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
26 * <p>CreateMediaHandler class.</p>
31 public class CreateMediaHandler
extends AbstractHandler
{
34 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
38 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
39 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
42 DescriptionBase description
= null;
44 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
45 if (editor
instanceof FormEditor
) {
46 editor
= ((FormEditor
) editor
).getActiveEditor();
49 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
50 if (selection
instanceof TreeSelection
) {
51 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
53 int count
= paths
[0].getSegmentCount();
55 for (int i
= 0; i
< count
; i
++ ) {
56 if (paths
[0].getSegment(i
) instanceof DescriptionBase
) {
57 description
= (DescriptionBase
) paths
[0].getSegment(i
);
63 if(description
!= null){
64 AbstractPostOperation operation
= null;
66 // TODO use undo context specific to editor
67 operation
= new AddMediaToImageGalleryOperation(event
.getCommand().getName(),
68 EditorUtil
.getUndoContext(), description
, postOperationEnabled
);
69 EditorUtil
.executeOperation(operation
);
70 } catch (NotDefinedException e
) {
71 MessagingUtils
.warn(getClass(), "Command name not set.");