Project

General

Profile

Download (2.56 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.singlesource.navigation.navigator;
12

    
13
import org.apache.log4j.Logger;
14
import org.eclipse.jface.viewers.ColumnLabelProvider;
15
import org.eclipse.jface.viewers.ILabelProvider;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.ui.navigator.IDescriptionProvider;
18
import org.hibernate.LazyInitializationException;
19

    
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
26

    
27
/**
28
 * <p>TaxonNodeLabelProvider class.</p>
29
 *
30
 * @author p.ciardelli
31
 * @created 04.06.2009
32
 * @version 1.0
33
 */
34
public class TaxonNodeLabelProvider extends ColumnLabelProvider 
35
		implements ILabelProvider, IDescriptionProvider {
36

    
37
	private static final Logger logger = Logger
38
			.getLogger(TaxonNodeLabelProvider.class);
39
	
40
	/** {@inheritDoc} */
41
	@Override
42
	public Image getImage(Object element) {
43
		return null;
44
	}
45

    
46
	/** {@inheritDoc} */
47
	@Override
48
	public String getText(Object element) {
49
		if (element instanceof TaxonNode){
50
			TaxonNode taxonNode = (TaxonNode) HibernateProxyHelper.deproxy(element);
51
			
52
			try{
53
				Taxon taxon = (Taxon) HibernateProxyHelper.deproxy(taxonNode.getTaxon());
54
				if(taxon == null){
55
					NavigationUtil.error(getClass(), "The taxon node does not have a taxon attached to it. Please check your import. TaxonNode: " + element, null);
56
//					throw new RuntimeException("The data your are trying to view is corrupt. Please check your import.");
57
				}else{
58
					try{
59
						return taxon.getName() != null ? ((IIdentifiableEntity) HibernateProxyHelper.deproxy(taxon.getName())).getTitleCache() : new String();
60
					}catch(Exception e){
61
						NavigationUtil.error(getClass(), e);
62
					}
63
				}
64
			}catch (LazyInitializationException e){
65
				NavigationUtil.error(getClass(), e);
66
			}
67
			
68
		}
69
		return new String();
70
	}
71
	
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object)
74
	 */
75
	/** {@inheritDoc} */
76
	public String getDescription(Object anElement) {
77
		if (anElement instanceof TaxonNode) {
78
			Taxon data = ((TaxonNode) anElement).getTaxon();
79
			return "Taxon: " + data.getTitleCache(); //$NON-NLS-1$
80
		}
81
		return null;
82
	}
83
}
(3-3/3)