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
.descriptiontree
.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
.core
.commands
.operations
.IUndoableOperation
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.TreePath
;
19 import org
.eclipse
.jface
.viewers
.TreeSelection
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IEditorPart
;
22 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.api
.utility
.ImagesUtility
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
27 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
30 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
31 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
32 import eu
.etaxonomy
.taxeditor
.operations
.MoveImageInListOperation
;
39 public class MoveImageDownInListHandler
extends AbstractHandler
{
40 private static final Logger logger
= Logger
41 .getLogger(CreateDescriptionElementHandler
.class);
44 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
49 if (editor
instanceof FormEditor
) {
50 editor
= ((FormEditor
) editor
).getActiveEditor();
52 IEditorInput input
= editor
.getEditorInput();
53 if (input
instanceof TaxonEditorInput
) {
54 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
56 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
57 if (selection
instanceof TreeSelection
) {
58 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();
68 IUndoableOperation operation
= null;
70 // TODO use undo context specific to editor
71 operation
= new MoveImageInListOperation(event
.getCommand().getName(),
72 EditorUtil
.getUndoContext(), taxon
, element
, image
, ImagesUtility
.DOWN
, (IPostOperationEnabled
) editor
);
73 EditorUtil
.executeOperation(operation
);
74 } catch (NotDefinedException e
) {
75 logger
.warn("Command name not set");