3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
;
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
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
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.
32 public class TaxonLinkHelper
implements ILinkHelper
{
33 private static final Logger logger
= Logger
34 .getLogger(TaxonLinkHelper
.class);
36 public static final String ID
= "eu.etaxonomy.taxeditor.navigation.taxonlinkhelper"; //$NON-NLS-1$
39 * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
41 public void activateEditor(IWorkbenchPage page
,
42 IStructuredSelection selection
) {
43 if (selection
== null || selection
.isEmpty()) {
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
);
57 * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
59 public IStructuredSelection
findSelection(IEditorInput editorInput
) {
60 if (editorInput
instanceof TaxonEditorInput
) {
61 Taxon taxon
= ((TaxonEditorInput
) editorInput
).getTaxon();
63 return new StructuredSelection(taxon
);
66 return StructuredSelection
.EMPTY
;