ref #6190 removing svn property place holder in first line of code - java files
[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
22 /**
23 * When a taxon is open in an editor and this editor has focus, its entry in the
24 * navigator's taxonomic tree is selected.
25 *
26 * @author p.ciardelli
27 * @created 03.06.2009
28 * @version 1.0
29 */
30 public class TaxonLinkHelper implements ILinkHelper {
31
32 /** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.taxon"{trunked}</code> */
33 public static final String ID = "eu.etaxonomy.taxeditor.navigation.taxonlinkhelper"; //$NON-NLS-1$
34
35 /* (non-Javadoc)
36 * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
37 */
38 /** {@inheritDoc} */
39 @Override
40 public void activateEditor(IWorkbenchPage page,
41 IStructuredSelection selection) {
42 try {
43 if (selection == null || selection.isEmpty()) {
44 return;
45 }
46 // if (selection.getFirstElement() instanceof TaxonNode) {
47 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
48 // TaxonEditorInput taxonEditorInput;
49 //
50 // taxonEditorInput = TaxonEditorInput.NewInstance(taxonNode.getUuid());
51 //
52 // IEditorPart editor = null;
53 // if ((editor = page.findEditor(taxonEditorInput)) != null) {
54 // page.bringToTop(editor);
55 // }
56 // }
57 } catch (Exception e) {
58 MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
59 }
60 }
61
62 /* (non-Javadoc)
63 * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
64 */
65 /** {@inheritDoc} */
66 @Override
67 public IStructuredSelection findSelection(IEditorInput editorInput) {
68 if (editorInput instanceof TaxonEditorInput) {
69 TaxonNode taxonNode = ((TaxonEditorInput) editorInput).getTaxonNode();
70 if (taxonNode != null) {
71 return new StructuredSelection(taxonNode);
72 }
73 }
74 return StructuredSelection.EMPTY;
75 }
76 }