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
.actions
.ui
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.jface
.action
.Action
;
14 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
15 import org
.eclipse
.ui
.IEditorInput
;
16 import org
.eclipse
.ui
.PartInitException
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
21 import eu
.etaxonomy
.taxeditor
.UiUtil
;
22 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
23 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
24 import eu
.etaxonomy
.taxeditor
.model
.NameEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.navigation
.TaxonomicTreeViewer
;
28 * Opens a taxon editor for an existing or new taxon.
34 public class OpenTaxonEditorAction
extends Action
{
35 private static final Logger logger
= Logger
36 .getLogger(OpenTaxonEditorAction
.class);
38 private static String editTaxonText
= "Edit taxon";
39 private static String newTaxonText
= "Add new taxon";
40 // private ImageDescriptor image = TaxEditorPlugin.getDefault()
41 // .getImageDescriptor(ITaxEditorConstants.OPEN_TAXON_ICON);
42 private ImageDescriptor image
= null;
45 public static final String ID
= "eu.etaxonomy.taxeditor.actions.opennameeditoraction"; //$NON-NLS-1$
47 public OpenTaxonEditorAction(Taxon taxon
) {
52 setText(editTaxonText
);
56 public OpenTaxonEditorAction() {
58 setImageDescriptor(image
);
68 // Passing the parser an empty string will return a new
69 // new name object with the name class specified in the
70 // preference store, i.e. BotanicalName
71 TaxonNameBase name
= CdmUtil
.parseFullReference("", null, null);
72 name
.setFullTitleCache("", false);
73 this.taxon
= Taxon
.NewInstance(name
, CdmUtil
.getSessionDefaultSec());
76 // If this taxon is not visible in the tree, open node
77 TaxonomicTreeViewer treeViewer
= UiUtil
.getTreeViewer();
78 if (treeViewer
!= null) {
79 treeViewer
.revealTaxon(taxon
);
83 // If this is a non-empty taxon being opened for the first time,
84 // add to recent names list
85 if (taxon
.getName() != null &&
86 !TaxEditorPlugin
.getDefault().getObservableRecentNamesList().contains(taxon
)) {
87 TaxEditorPlugin
.getDefault().getObservableRecentNamesList().add(0, taxon
);
90 IEditorInput input
= new NameEditorInput(taxon
);
92 UiUtil
.openEditor(input
, MultiPageTaxonEditor
.ID
);
93 } catch (PartInitException e
) {
97 // For clients who re-use the same instance of this class,
98 // taxon is re-initalized to ensure a new Taxon is opened every time