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