Merge branch 'develop' into wset
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / TaxonLinkHelper.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.navigation.navigator;
11
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.jface.viewers.StructuredSelection;
14 import org.eclipse.ui.IEditorInput;
15 import org.eclipse.ui.IWorkbenchPage;
16 import org.eclipse.ui.navigator.ILinkHelper;
17
18 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
19 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
22
23 /**
24 * When a taxon is open in an editor and this editor has focus, its entry in the
25 * navigator's taxonomic tree is selected.
26 *
27 * @author p.ciardelli
28 * @created 03.06.2009
29 * @version 1.0
30 */
31 public class TaxonLinkHelper implements ILinkHelper {
32
33 /** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.taxon"{trunked}</code> */
34 public static final String ID = "eu.etaxonomy.taxeditor.navigation.taxonlinkhelper"; //$NON-NLS-1$
35
36 /* (non-Javadoc)
37 * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
38 */
39 /** {@inheritDoc} */
40 @Override
41 public void activateEditor(IWorkbenchPage page,
42 IStructuredSelection selection) {
43 try {
44 if (selection == null || selection.isEmpty()) {
45 return;
46 }
47 // if (selection.getFirstElement() instanceof TaxonNode) {
48 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
49 // TaxonEditorInput taxonEditorInput;
50 //
51 // taxonEditorInput = TaxonEditorInput.NewInstance(taxonNode.getUuid());
52 //
53 // IEditorPart editor = null;
54 // if ((editor = page.findEditor(taxonEditorInput)) != null) {
55 // page.bringToTop(editor);
56 // }
57 // }
58 } catch (Exception e) {
59 MessagingUtils.warningDialog(Messages.TaxonLinkHelper_CREATE_FAIL, this, e.getMessage());
60 }
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
65 */
66 /** {@inheritDoc} */
67 @Override
68 public IStructuredSelection findSelection(IEditorInput editorInput) {
69 if (editorInput instanceof TaxonEditorInput) {
70 TaxonNode taxonNode = ((TaxonEditorInput) editorInput).getTaxonNode();
71 if (taxonNode != null) {
72 return new StructuredSelection(taxonNode);
73 }
74 }
75 return StructuredSelection.EMPTY;
76 }
77 }