Project

General

Profile

Download (3.12 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.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32

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

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

    
84
}
(5-5/5)