merged/implemented cdm3.3 model adaptations
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / CopyHandler.java
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.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 NavigationUtil.warn(getClass(), "Command name not set");
63 }
64 }
65 }
66
67
68 return null;
69 }
70
71 }