Project

General

Profile

Download (2.23 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 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.navigation.navigator.handler;
11

    
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.IHandler;
16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

    
21
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
24
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
25
import eu.etaxonomy.taxeditor.navigation.navigator.operation.CopyOperation;
26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27
import eu.etaxonomy.taxeditor.store.StoreUtil;
28

    
29
/**
30
 * @author l.morris
31
 * @date 23 Jan 2012
32
 *
33
 */
34
public class CopyHandler extends AbstractHandler implements IHandler {
35
	
36
	private TaxonNavigator taxonNavigator;
37

    
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40
	 */
41
	@Override
42
	public Object execute(ExecutionEvent event) throws ExecutionException {
43
		
44
		taxonNavigator = NavigationUtil.showNavigator();
45
		
46
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
47
				.getCurrentSelection(event);
48

    
49
		if(selection.size() == 1) {
50
			
51
			Object selectedObject = selection.getFirstElement();
52
			
53
			if (selectedObject instanceof TaxonNode) {
54
				
55
				try {
56
					
57
					AbstractPostOperation operation = new CopyOperation(event.getCommand().getName(), StoreUtil.getUndoContext(),
58
					(TaxonNode)selectedObject, taxonNavigator);
59
					
60
					IStatus status = NavigationUtil.executeOperation(operation);
61
					
62
				} catch (NotDefinedException e) {
63
					MessagingUtils.warn(getClass(), "Command name not set");
64
				}
65
			}
66
		}
67
		
68
		
69
		return null;
70
	}
71

    
72
}
(2-2/11)