Project

General

Profile

Download (3.15 KB) Statistics
| Branch: | Tag: | Revision:
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.IEditorInput;
16
import org.eclipse.ui.PartInitException;
17

    
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;
26

    
27
/**
28
 * Opens a taxon editor for an existing or new taxon.
29
 * 
30
 * @author p.ciardelli
31
 * @created 02.06.2008
32
 * @version 1.0
33
 */
34
public class OpenTaxonEditorAction extends Action {
35
	private static final Logger logger = Logger
36
			.getLogger(OpenTaxonEditorAction.class);
37

    
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;
43
	
44
	private Taxon taxon;
45
	public static final String ID = "eu.etaxonomy.taxeditor.actions.opennameeditoraction"; //$NON-NLS-1$
46
	
47
	public OpenTaxonEditorAction(Taxon taxon) {
48
		this();
49
		
50
		this.taxon = taxon;
51
		if (taxon != null) {
52
			setText(editTaxonText);
53
		}
54
	}
55

    
56
	public OpenTaxonEditorAction() {
57
		super(newTaxonText);
58
		setImageDescriptor(image);	
59
		setId(ID);
60
	}
61
	
62
	@Override
63
	public void run() {
64
		
65
		// Initialize taxon
66
		if (taxon == null) {
67
			
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
//			BotanicalName name = BotanicalName.NewInstance(Rank.GENUS());
73
			this.taxon = Taxon.NewInstance(name, CdmUtil.getSessionDefaultSec());
74
		} else {
75
			
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);
80
			}
81
		}
82
				
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);
88
		}
89

    
90
		IEditorInput input = new NameEditorInput(taxon);
91
    	try {
92
			UiUtil.openEditor(input, MultiPageTaxonEditor.ID);
93
		} catch (PartInitException e) {
94
			e.printStackTrace();
95
		}
96
		
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
99
		taxon = null;
100
	}
101
}
(16-16/17)