-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-package eu.etaxonomy.taxeditor.editor.view.media.handler;\r
-import org.apache.log4j.Logger;\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.commands.common.NotDefinedException;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.TreePath;\r
-import org.eclipse.jface.viewers.TreeSelection;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.forms.editor.FormEditor;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-\r
-import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
-import eu.etaxonomy.cdm.model.media.Media;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
-import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;\r
-import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler;\r
-import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;\r
-import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;\r
-import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;\r
-\r
-/**\r
- * @author p.ciardelli\r
- * @created 11.08.2009\r
- * @version 1.0\r
- */\r
-public class MoveImageDownInListHandler extends AbstractHandler {\r
- private static final Logger logger = Logger\r
- .getLogger(CreateDescriptionElementHandler.class);\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)\r
- */\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
- IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;\r
- \r
- IEditorPart editor = HandlerUtil.getActiveEditor(event);\r
- if (editor instanceof FormEditor) {\r
- editor = ((FormEditor) editor).getActiveEditor();\r
- }\r
- IEditorInput input = editor.getEditorInput();\r
- if (input instanceof TaxonEditorInput) {\r
- Taxon taxon = ((TaxonEditorInput) input).getTaxon();\r
- \r
- ISelection selection = HandlerUtil.getCurrentSelection(event);\r
- \r
- if (selection instanceof TreeSelection) {\r
- TreePath[] paths = ((TreeSelection) selection).getPaths();\r
- int count = paths[0].getSegmentCount();\r
- DescriptionBase description = null;\r
- for (int i = 0; i < count; i++ ) {\r
- if (paths[0].getSegment(i) instanceof DescriptionBase) {\r
- description = (DescriptionBase) paths[0].getSegment(i);\r
- break;\r
- }\r
- } \r
- Media media = (Media) paths[0].getLastSegment();\r
- AbstractPostOperation operation = null;\r
- try {\r
- // TODO use undo context specific to editor\r
- operation = new MoveMediaInListOperation(event.getCommand().getName(), \r
- EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, postOperationEnabled);\r
- EditorUtil.executeOperation(operation);\r
- } catch (NotDefinedException e) {\r
- logger.warn("Command name not set");\r
- }\r
- }\r
- } \r
- return null;\r
- }\r
-\r
-}\r
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.view.media.handler;
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler;
+import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;
+
+/**
+ * <p>MoveImageDownInListHandler class.</p>
+ *
+ * @author p.ciardelli
+ * @created 11.08.2009
+ * @version 1.0
+ */
+public class MoveImageDownInListHandler extends AbstractHandler {
+ private static final Logger logger = Logger
+ .getLogger(CreateDescriptionElementHandler.class);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ /** {@inheritDoc} */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);
+ IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
+
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+ if (editor instanceof FormEditor) {
+ editor = ((FormEditor) editor).getActiveEditor();
+ }
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof TaxonEditorInput) {
+ Taxon taxon = ((TaxonEditorInput) input).getTaxon();
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ if (selection instanceof TreeSelection) {
+ TreePath[] paths = ((TreeSelection) selection).getPaths();
+ int count = paths[0].getSegmentCount();
+ DescriptionBase description = null;
+ for (int i = 0; i < count; i++ ) {
+ if (paths[0].getSegment(i) instanceof DescriptionBase) {
+ description = (DescriptionBase) paths[0].getSegment(i);
+ break;
+ }
+ }
+ Media media = (Media) paths[0].getLastSegment();
+ AbstractPostOperation operation = null;
+ try {
+ // TODO use undo context specific to editor
+ operation = new MoveMediaInListOperation(event.getCommand().getName(),
+ EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, postOperationEnabled);
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ logger.warn("Command name not set");
+ }
+ }
+ }
+ return null;
+ }
+
+}