2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
.handler
;
10 import org
.eclipse
.core
.commands
.AbstractHandler
;
11 import org
.eclipse
.core
.commands
.ExecutionEvent
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.TreePath
;
16 import org
.eclipse
.jface
.viewers
.TreeSelection
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IEditorPart
;
19 import org
.eclipse
.ui
.IWorkbenchPart
;
20 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
24 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.MoveMediaInListOperation
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 * <p>MoveImageDownInListHandler class.</p>
40 public class MoveImageDownInListHandler
extends AbstractHandler
{
43 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
48 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
50 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
51 if (editor
instanceof FormEditor
) {
52 editor
= ((FormEditor
) editor
).getActiveEditor();
54 IEditorInput input
= editor
.getEditorInput();
55 if (input
instanceof TaxonEditorInput
) {
56 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
58 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
60 if (selection
instanceof TreeSelection
) {
61 TreePath
[] paths
= ((TreeSelection
) selection
).getPaths();
62 int count
= paths
[0].getSegmentCount();
63 DescriptionBase description
= null;
64 for (int i
= 0; i
< count
; i
++ ) {
65 if (paths
[0].getSegment(i
) instanceof DescriptionBase
) {
66 description
= (DescriptionBase
) paths
[0].getSegment(i
);
70 Media media
= (Media
) paths
[0].getLastSegment();
71 AbstractPostOperation operation
= null;
73 // TODO use undo context specific to editor
74 operation
= new MoveMediaInListOperation(event
.getCommand().getName(),
75 EditorUtil
.getUndoContext(), taxon
, description
, media
, MoveMediaInListOperation
.DOWN
, postOperationEnabled
);
76 EditorUtil
.executeOperation(operation
);
77 } catch (NotDefinedException e
) {
78 MessagingUtils
.warn(getClass(), "Command name not set.");