Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java
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.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.IWorkbenchPart;
23
import org.eclipse.ui.forms.editor.FormEditor;
24
import org.eclipse.ui.handlers.HandlerUtil;
25

  
26
import eu.etaxonomy.cdm.model.description.DescriptionBase;
27
import eu.etaxonomy.cdm.model.media.Media;
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.editor.view.descriptive.handler.CreateDescriptionElementHandler;
32
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
34
import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;
35

  
36
/**
37
 * @author p.ciardelli
38
 * @created 11.08.2009
39
 * @version 1.0
40
 */
41
public class MoveImageUpInListHandler extends AbstractHandler {
42
	private static final Logger logger = Logger
43
			.getLogger(CreateDescriptionElementHandler.class);
44

  
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47
	 */
48
	public Object execute(ExecutionEvent event) throws ExecutionException {
49
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
50
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
51
				
52
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
53
		if (editor instanceof FormEditor) {
54
			editor = ((FormEditor) editor).getActiveEditor();
55
		}
56
		IEditorInput input = editor.getEditorInput();
57
		if (input instanceof TaxonEditorInput) {
58
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
59
			
60
			ISelection selection = HandlerUtil.getCurrentSelection(event);
61
			if (selection instanceof TreeSelection) {
62
				TreePath[] paths = ((TreeSelection) selection).getPaths();
63
				int count = paths[0].getSegmentCount();
64
				DescriptionBase element = null;
65
				for (int i = 0; i < count; i++ ) {
66
					if (paths[0].getSegment(i) instanceof DescriptionBase) {
67
						element = (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, element, media, MoveMediaInListOperation.UP, postOperationEnabled);
77
					EditorUtil.executeOperation(operation);
78
				} catch (NotDefinedException e) {
79
					logger.warn("Command name not set");
80
				}
81
			}
82
		} 
83
		return null;
84
	}
85

  
86
}
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.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.IWorkbenchPart;
23
import org.eclipse.ui.forms.editor.FormEditor;
24
import org.eclipse.ui.handlers.HandlerUtil;
25

  
26
import eu.etaxonomy.cdm.model.description.DescriptionBase;
27
import eu.etaxonomy.cdm.model.media.Media;
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.editor.view.descriptive.handler.CreateDescriptionElementHandler;
32
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
34
import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;
35

  
36
/**
37
 * <p>MoveImageUpInListHandler class.</p>
38
 *
39
 * @author p.ciardelli
40
 * @created 11.08.2009
41
 * @version 1.0
42
 */
43
public class MoveImageUpInListHandler extends AbstractHandler {
44
	private static final Logger logger = Logger
45
			.getLogger(CreateDescriptionElementHandler.class);
46

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

  
89
}

Also available in: Unified diff