Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / TaxonLinkHelper.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.viewers.IStructuredSelection;
15 import org.eclipse.jface.viewers.StructuredSelection;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.navigator.ILinkHelper;
20
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
23
24 /**
25 * When a taxon is open in an editor and this editor has focus, its entry in the
26 * navigator's taxonomic tree is selected.
27 *
28 * @author p.ciardelli
29 * @created 03.06.2009
30 * @version 1.0
31 */
32 public class TaxonLinkHelper implements ILinkHelper {
33 private static final Logger logger = Logger
34 .getLogger(TaxonLinkHelper.class);
35
36 public static final String ID = "eu.etaxonomy.taxeditor.navigation.taxonlinkhelper"; //$NON-NLS-1$
37
38 /* (non-Javadoc)
39 * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
40 */
41 public void activateEditor(IWorkbenchPage page,
42 IStructuredSelection selection) {
43 if (selection == null || selection.isEmpty()) {
44 return;
45 }
46 if (selection.getFirstElement() instanceof Taxon) {
47 Taxon taxon = (Taxon) selection.getFirstElement();
48 TaxonEditorInput taxonEditorInput = TaxonEditorInput.NewInstance(taxon.getUuid());
49 IEditorPart editor = null;
50 if ((editor = page.findEditor(taxonEditorInput)) != null) {
51 page.bringToTop(editor);
52 }
53 }
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
58 */
59 public IStructuredSelection findSelection(IEditorInput editorInput) {
60 if (editorInput instanceof TaxonEditorInput) {
61 Taxon taxon = ((TaxonEditorInput) editorInput).getTaxon();
62 if (taxon != null) {
63 return new StructuredSelection(taxon);
64 }
65 }
66 return StructuredSelection.EMPTY;
67 }
68 }