tabbed_properties branch merged into trunk completely
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / OpenTaxonActionProvider.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
11 package eu.etaxonomy.taxeditor.navigation.navigator;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.StructuredViewer;
17 import org.eclipse.jface.viewers.TreeSelection;
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.navigator.CommonActionProvider;
20 import org.eclipse.ui.navigator.ICommonActionConstants;
21 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
22
23 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
24 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
25
26 /**
27 * @author p.ciardelli
28 * @created 04.06.2009
29 * @version 1.0
30 */
31 public class OpenTaxonActionProvider extends CommonActionProvider {
32 private static final Logger logger = Logger
33 .getLogger(OpenTaxonActionProvider.class);
34
35 OpenTaxonAction openTaxonAction;
36
37 /* (non-Javadoc)
38 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
39 */
40 public void init(ICommonActionExtensionSite aSite) {
41 super.init(aSite);
42 openTaxonAction = new OpenTaxonAction(aSite.getStructuredViewer());
43
44 }
45
46 /* (non-Javadoc)
47 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
48 */
49 public void fillActionBars(IActionBars actionBars) {
50 super.fillActionBars(actionBars);
51 // forward doubleClick to doubleClickAction
52 actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
53 openTaxonAction);
54 }
55
56 class OpenTaxonAction extends Action {
57
58 private StructuredViewer structuredViewer;
59
60 /**
61 * @param structuredViewer
62 */
63 public OpenTaxonAction(StructuredViewer structuredViewer) {
64 this.structuredViewer = structuredViewer;
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.jface.action.Action#run()
69 */
70 public void run() {
71 ISelection selection = structuredViewer.getSelection();
72 if (selection instanceof TreeSelection) {
73 Object[] selections = ((TreeSelection) selection).toArray();
74 for (Object element : ((TreeSelection) selection).toArray()) {
75 if (element instanceof TaxonNode) {
76 NavigationUtil.openEditor((TaxonNode) element);
77 }
78 }
79 }
80 }
81 }
82 }