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/MoveImageDownInListHandler.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.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.TreePath;
18
import org.eclipse.jface.viewers.TreeSelection;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorPart;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.forms.editor.FormEditor;
23
import org.eclipse.ui.handlers.HandlerUtil;
24

  
25
import eu.etaxonomy.cdm.model.description.DescriptionBase;
26
import eu.etaxonomy.cdm.model.media.Media;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
30
import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler;
31
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
32
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
33
import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;
34

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

  
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46
	 */
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
					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.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.TreePath;
18
import org.eclipse.jface.viewers.TreeSelection;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorPart;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.forms.editor.FormEditor;
23
import org.eclipse.ui.handlers.HandlerUtil;
24

  
25
import eu.etaxonomy.cdm.model.description.DescriptionBase;
26
import eu.etaxonomy.cdm.model.media.Media;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
30
import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler;
31
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
32
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
33
import eu.etaxonomy.taxeditor.operations.MoveMediaInListOperation;
34

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

  
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48
	 */
49
	/** {@inheritDoc} */
50
	public Object execute(ExecutionEvent event) throws ExecutionException {
51
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
52
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
53
				
54
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
55
		if (editor instanceof FormEditor) {
56
			editor = ((FormEditor) editor).getActiveEditor();
57
		}
58
		IEditorInput input = editor.getEditorInput();
59
		if (input instanceof TaxonEditorInput) {
60
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
61
			
62
			ISelection selection = HandlerUtil.getCurrentSelection(event);
63
						
64
			if (selection instanceof TreeSelection) {
65
				TreePath[] paths = ((TreeSelection) selection).getPaths();
66
				int count = paths[0].getSegmentCount();
67
				DescriptionBase description = null;
68
				for (int i = 0; i < count; i++ ) {
69
					if (paths[0].getSegment(i) instanceof DescriptionBase) {
70
						description = (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, description, media, MoveMediaInListOperation.DOWN, 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