Project

General

Profile

Download (3.2 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10
package eu.etaxonomy.taxeditor.editor.view.media.handler;
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.common.NotDefinedException;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.TreePath;
17
import org.eclipse.jface.viewers.TreeSelection;
18
import org.eclipse.ui.IEditorInput;
19
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.IWorkbenchPart;
21
import org.eclipse.ui.forms.editor.FormEditor;
22
import org.eclipse.ui.handlers.HandlerUtil;
23

    
24
import eu.etaxonomy.cdm.model.description.DescriptionBase;
25
import eu.etaxonomy.cdm.model.media.Media;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
28
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
29
import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation;
30
import eu.etaxonomy.taxeditor.model.MessagingUtils;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
33

    
34
/**
35
 * <p>MoveImageDownInListHandler class.</p>
36
 *
37
 * @author p.ciardelli
38
 * @created 11.08.2009
39
 * @version 1.0
40
 */
41
public class MoveImageDownInListHandler extends AbstractHandler {
42

    
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45
	 */
46
	/** {@inheritDoc} */
47
	public Object execute(ExecutionEvent event) throws ExecutionException {
48
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
49
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
50
				
51
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
52
		if (editor instanceof FormEditor) {
53
			editor = ((FormEditor) editor).getActiveEditor();
54
		}
55
		IEditorInput input = editor.getEditorInput();
56
		if (input instanceof TaxonEditorInput) {
57
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
58
			
59
			ISelection selection = HandlerUtil.getCurrentSelection(event);
60
						
61
			if (selection instanceof TreeSelection) {
62
				TreePath[] paths = ((TreeSelection) selection).getPaths();
63
				int count = paths[0].getSegmentCount();
64
				DescriptionBase description = null;
65
				for (int i = 0; i < count; i++ ) {
66
					if (paths[0].getSegment(i) instanceof DescriptionBase) {
67
						description = (DescriptionBase) paths[0].getSegment(i);
68
						break;
69
					}
70
				}				
71
				Media media = (Media) paths[0].getLastSegment();
72
				AbstractPostOperation operation = null;
73
				try {
74
					// TODO use undo context specific to editor
75
					operation = new MoveMediaInListOperation(event.getCommand().getName(), 
76
							EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, postOperationEnabled);
77
					EditorUtil.executeOperation(operation);
78
				} catch (NotDefinedException e) {
79
					MessagingUtils.warn(getClass(), "Command name not set.");
80
				}
81
			}
82
		} 
83
		return null;
84
	}
85

    
86
}
(4-4/5)