Moving editor sources back into trunk
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / taxonomictree / TaxonomicTreeLabelProvider.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.navigation.taxonomictree;
5
6 import org.eclipse.jface.viewers.ColumnLabelProvider;
7 import org.eclipse.jface.viewers.ILabelProvider;
8 import org.eclipse.swt.graphics.Image;
9 import org.eclipse.ui.navigator.IDescriptionProvider;
10
11 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
12 import eu.etaxonomy.cdm.model.taxon.Taxon;
13 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14 import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
15 import eu.etaxonomy.taxeditor.store.model.NameUtil;
16
17 /**
18 *
19 * @author n.hoffmann
20 * @created 18.03.2009
21 * @version 1.0
22 */
23 public class TaxonomicTreeLabelProvider extends ColumnLabelProvider implements ILabelProvider, IDescriptionProvider {
24
25 public Image getImage(Object element) {
26 // This code was to distinct a missaplied name from a accepted taxon name
27 // in the taxonomic tree. Unfortunately lazy loading slows this down, so that
28 // the taxonomic tree will take 10 minutes to initialize.
29 // I will leave this in here as a reminder.
30 // if (element instanceof Taxon){
31 // if(((Taxon) element).isMisappliedName()){
32 // // return misapplication image
33 // return PlatformUI.getWorkbench().getSharedImages().getImage(
34 // ISharedImages.IMG_ELCL_SYNCED);
35 // }
36 // // return standard taxon image
37 // return PlatformUI.getWorkbench().getSharedImages().getImage(
38 // ISharedImages.IMG_OBJS_INFO_TSK);
39 // }
40
41
42 // No image for now
43 return null;
44 }
45
46 public String getText(Object element) {
47 if (element instanceof Taxon) {
48 Taxon data = (Taxon) element;
49 return data.getName().getTitleCache(); //$NON-NLS-1$
50 }
51 return null;
52 }
53
54 public String getDescription(Object anElement) {
55 if (anElement instanceof Taxon) {
56 Taxon data = (Taxon) anElement;
57 return "Taxon: " + data.getTitleCache(); //$NON-NLS-1$
58 }
59 return null;
60 }
61
62 public String getToolTipText(Object element) {
63 if (element instanceof Taxon) {
64 return getSynonymyListDisplay((Taxon) element);
65 }
66 return null;
67 }
68
69 /**
70 * @param taxon
71 * @return
72 */
73 private String getSynonymyListDisplay(Taxon taxon) {
74 IterableSynonymyList synonymyList = new IterableSynonymyList(
75 taxon);
76 String synonymyListDisplay = NameUtil
77 .getDisplayName(taxon);
78
79 for (TaxonBase synonymOrMisName : synonymyList) {
80 TaxonNameBase name = synonymOrMisName.getName();
81 if (name != null) {
82 synonymyListDisplay += "\n "
83 + NameUtil.getDisplayName(name);
84 }
85 }
86 return synonymyListDisplay;
87 }
88 }