- fixed compile error in test
[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 java.util.Iterator;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.IHandler;
18 import org.eclipse.core.commands.common.NotDefinedException;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.ui.handlers.HandlerUtil;
22
23 import eu.etaxonomy.cdm.model.common.TermBase;
24 import eu.etaxonomy.cdm.model.taxon.Taxon;
25 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
26 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27 import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
28 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
29 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
30 import eu.etaxonomy.taxeditor.navigation.navigator.operation.CopyOperation;
31 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32 import eu.etaxonomy.taxeditor.store.StoreUtil;
33
34 /**
35 * @author l.morris
36 * @date 23 Jan 2012
37 *
38 */
39 public class CopyHandler extends AbstractHandler implements IHandler {
40
41 private TaxonNavigator taxonNavigator;
42
43 /* (non-Javadoc)
44 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45 */
46 @Override
47 public Object execute(ExecutionEvent event) throws ExecutionException {
48
49 taxonNavigator = NavigationUtil.showNavigator();
50
51 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
52 .getCurrentSelection(event);
53
54 if(selection.size() == 1) {
55
56 Object selectedObject = selection.getFirstElement();
57
58 if (selectedObject instanceof TaxonNode) {
59
60 try {
61
62 AbstractPostOperation operation = new CopyOperation(event.getCommand().getName(), StoreUtil.getUndoContext(),
63 (TaxonNode)selectedObject, taxonNavigator);
64
65 IStatus status = NavigationUtil.executeOperation(operation);
66
67 } catch (NotDefinedException e) {
68 NavigationUtil.warn(getClass(), "Command name not set");
69 }
70 }
71 }
72
73
74 return null;
75 }
76
77 }