1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
|
10
|
|
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.IHandler;
|
15
|
import org.eclipse.core.commands.common.NotDefinedException;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
import org.eclipse.ui.handlers.HandlerUtil;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
23
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
|
24
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.CopyOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
26
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
27
|
|
28
|
/**
|
29
|
* @author l.morris
|
30
|
* @date 23 Jan 2012
|
31
|
*
|
32
|
*/
|
33
|
public class CopyHandler extends AbstractHandler implements IHandler {
|
34
|
|
35
|
private TaxonNavigator taxonNavigator;
|
36
|
|
37
|
/* (non-Javadoc)
|
38
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
39
|
*/
|
40
|
@Override
|
41
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
42
|
|
43
|
taxonNavigator = NavigationUtil.showNavigator();
|
44
|
|
45
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil
|
46
|
.getCurrentSelection(event);
|
47
|
|
48
|
if(selection.size() == 1) {
|
49
|
|
50
|
Object selectedObject = selection.getFirstElement();
|
51
|
|
52
|
if (selectedObject instanceof TaxonNode) {
|
53
|
|
54
|
try {
|
55
|
|
56
|
AbstractPostOperation operation = new CopyOperation(event.getCommand().getName(), StoreUtil.getUndoContext(),
|
57
|
(TaxonNode)selectedObject, taxonNavigator);
|
58
|
|
59
|
IStatus status = NavigationUtil.executeOperation(operation);
|
60
|
|
61
|
} catch (NotDefinedException e) {
|
62
|
MessagingUtils.warn(getClass(), "Command name not set"); //$NON-NLS-1$
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
}
|