55523882d52b08a48b041a8c5575cd42f499d16e
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / actions / ui / OpenNewChildNameEditorAction.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.actions.ui;
11
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.PartInitException;
16
17 import eu.etaxonomy.cdm.model.name.BotanicalName;
18 import eu.etaxonomy.cdm.model.name.NonViralName;
19 import eu.etaxonomy.cdm.model.name.Rank;
20 import eu.etaxonomy.cdm.model.name.ZoologicalName;
21 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.ITaxEditorConstants;
24 import eu.etaxonomy.taxeditor.TaxEditorPlugin;
25 import eu.etaxonomy.taxeditor.UiUtil;
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
28 /**
29 * Opens a name editor for a new taxon with a parent taxon
30 *
31 * @author p.ciardelli
32 * @created 02.06.2008
33 * @version 1.0
34 */
35 public class OpenNewChildNameEditorAction extends Action {
36 private static final Logger logger = Logger
37 .getLogger(OpenNewChildNameEditorAction.class);
38
39 private static String text = "Add child taxon";
40 private ImageDescriptor image = TaxEditorPlugin.getDefault()
41 .getImageDescriptor(ITaxEditorConstants.ADD_CHILD_TAXON_ICON);
42
43 private Taxon taxon;
44 private Taxon parentTaxon;
45 public static final String ID = "eu.etaxonomy.taxeditor.actions.opennameeditoraction"; //$NON-NLS-1$
46
47 private OpenNewChildNameEditorAction() {
48 super(text);
49 setImageDescriptor(image);
50 setId(ID);
51 }
52
53 public OpenNewChildNameEditorAction(Taxon parentTaxon) {
54 this();
55
56 this.parentTaxon = parentTaxon;
57 }
58
59 public void run() {
60
61 NonViralName name = PreferencesUtil.getInstanceOfPreferredNameClass();
62 ReferenceBase sec = parentTaxon.getSec();
63 taxon = Taxon.NewInstance(name, sec);
64
65 parentTaxon.addTaxonomicChild(taxon, null, null);
66
67 // Open editor for new taxon
68 try {
69 UiUtil.openTaxonEditor(taxon);
70 } catch (PartInitException e) {
71 e.printStackTrace();
72 }
73
74 //new OpenTaxonEditorAction(taxon).run();
75 }
76 }