2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.controller
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.TreeSelection
;
16 import org
.eclipse
.ui
.IViewPart
;
17 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.taxeditor
.navigation
.TaxonomicTreeView
;
21 import eu
.etaxonomy
.taxeditor
.navigation
.TaxonomicTreeViewer
;
28 public class TreeController
{
29 private static final Logger logger
= Logger
.getLogger(TreeController
.class);
30 private static IViewPart treeView
;
33 * Returns the <code>TaxonomicTreeViewer</code> used for navigation. Not to
34 * be confused with the window that contains it, <code>TaxonomicTreeView</code>.
38 public static TaxonomicTreeViewer
getTreeViewer() {
39 TaxonomicTreeView view
= getTreeView();
43 return view
.getTreeViewer();
47 * @see eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView#createTreeViewer()
51 public static TaxonomicTreeViewer
createTreeViewer() {
52 TaxonomicTreeView view
= getTreeView();
56 return view
.createTreeViewer();
60 * Returns the <code>TaxonomicTreeView</code> containing the
61 * <code>TaxonomicTreeViewer</code> used for navigation.
65 public static TaxonomicTreeView
getTreeView() {
66 if (treeView
== null) {
67 treeView
= GlobalController
.getViewById(TaxonomicTreeView
.ID
);
68 if (!(treeView
instanceof TaxonomicTreeView
)) {
72 return (TaxonomicTreeView
) treeView
;
77 * Returns the selected taxon for referencing in context menus
82 public static Taxon
getCurrentSelection(ExecutionEvent event
){
84 ISelection menuSelection
= HandlerUtil
.getActiveMenuSelection(event
);
86 // The selection should always be a tree selection since we are in the
87 // taxonomic tree view. Just in case this will be used in another spot.
88 if(menuSelection
instanceof TreeSelection
){
89 Taxon taxon
= (Taxon
) ((TreeSelection
) menuSelection
).getFirstElement();
90 logger
.debug("Selected taxon: " + taxon
);