Project

General

Profile

Download (2.41 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.eclipse.jface.viewers.ColumnLabelProvider;
14
import org.eclipse.jface.viewers.ILabelProvider;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.ui.navigator.IDescriptionProvider;
17
import org.hibernate.LazyInitializationException;
18

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

    
25
/**
26
 * <p>TaxonNodeLabelProvider class.</p>
27
 *
28
 * @author p.ciardelli
29
 * @created 04.06.2009
30
 * @version 1.0
31
 */
32
public class TaxonNodeLabelProvider extends ColumnLabelProvider 
33
		implements ILabelProvider, IDescriptionProvider {
34
	
35
	/** {@inheritDoc} */
36
	@Override
37
	public Image getImage(Object element) {
38
		return null;
39
	}
40

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