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.navigation.search;
|
12
|
|
13
|
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
14
|
import org.eclipse.jface.viewers.ILabelProvider;
|
15
|
import org.eclipse.swt.graphics.Color;
|
16
|
import org.eclipse.swt.graphics.Font;
|
17
|
import org.eclipse.swt.graphics.Image;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
23
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
24
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
25
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
26
|
|
27
|
/**
|
28
|
* <p>SearchResultLabelProvider class.</p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created 04.05.2009
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class SearchResultLabelProvider extends ColumnLabelProvider implements ILabelProvider {
|
35
|
|
36
|
/** {@inheritDoc} */
|
37
|
public String getText(Object element) {
|
38
|
if(element instanceof UuidAndTitleCache){
|
39
|
return ((UuidAndTitleCache) element).getTitleCache();
|
40
|
}
|
41
|
return element.toString();
|
42
|
}
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getBackground(java.lang.Object)
|
46
|
*/
|
47
|
/** {@inheritDoc} */
|
48
|
@Override
|
49
|
public Color getBackground(Object element) {
|
50
|
return super.getBackground(element);
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object)
|
55
|
*/
|
56
|
/** {@inheritDoc} */
|
57
|
@Override
|
58
|
public Font getFont(Object element) {
|
59
|
if(element instanceof Taxon){
|
60
|
return NavigationUtil.getFont(Resources.FONT_SEARCH_VIEW_ACCEPTED);
|
61
|
}else if(element instanceof Synonym){
|
62
|
return NavigationUtil.getFont(Resources.FONT_SEARCH_VIEW_SYNONYM);
|
63
|
}else{
|
64
|
return NavigationUtil.getFont(Resources.FONT_SEARCH_VIEW_OTHER);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getForeground(java.lang.Object)
|
70
|
*/
|
71
|
/** {@inheritDoc} */
|
72
|
@Override
|
73
|
public Color getForeground(Object element) {
|
74
|
if(element instanceof UuidAndTitleCache){
|
75
|
Class type = ((UuidAndTitleCache) element).getType();
|
76
|
if(type == Taxon.class){
|
77
|
return NavigationUtil.getColorRegistry().get("eu.etaxonomy.taxeditor.preferences.searchResult.fontColorAccepted");
|
78
|
}else if(type == Synonym.class){
|
79
|
return NavigationUtil.getColorRegistry().get("eu.etaxonomy.taxeditor.preferences.searchResult.fontColorSynonym");
|
80
|
}
|
81
|
}
|
82
|
return NavigationUtil.getColorRegistry().get("eu.etaxonomy.taxeditor.preferences.searchResult.fontColorDefault");
|
83
|
}
|
84
|
|
85
|
/* (non-Javadoc)
|
86
|
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
|
87
|
*/
|
88
|
/** {@inheritDoc} */
|
89
|
@Override
|
90
|
public Image getImage(Object element) {
|
91
|
if(element instanceof UuidAndTitleCache){
|
92
|
Class type = ((UuidAndTitleCache) element).getType();
|
93
|
// unfortunately we can not distinct misapplication anymore
|
94
|
// if(taxon.isMisapplication()){
|
95
|
// return ImageResources.getImage(ImageResources.MISAPPLIED_NAME_ICON);
|
96
|
// }else{
|
97
|
if(type == Taxon.class){
|
98
|
if(((UuidAndTitleCache) element).getIsOrphaned()) {
|
99
|
return ImageResources.getImage(ImageResources.ORPHANED_TAXON);
|
100
|
}
|
101
|
return ImageResources.getImage(ImageResources.BLACK_SQUARE_ICON);
|
102
|
}else if(type == Synonym.class){
|
103
|
return ImageResources.getImage(ImageResources.HETEROTYPIC_SYN_ICON);
|
104
|
}
|
105
|
}
|
106
|
return super.getImage(element);
|
107
|
}
|
108
|
|
109
|
/* (non-Javadoc)
|
110
|
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
|
111
|
*
|
112
|
* does not seem t work right now
|
113
|
*/
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
public String getToolTipText(Object element) {
|
117
|
if(element instanceof TaxonBase){
|
118
|
if(element instanceof Synonym){
|
119
|
return "Synonym: " + ((TaxonBase<?>) element).getName().getTitleCache();
|
120
|
}else{
|
121
|
return "Taxon: " + ((TaxonBase<?>) element).getName().getTitleCache();
|
122
|
}
|
123
|
}
|
124
|
return "Name: " + element.toString();
|
125
|
}
|
126
|
|
127
|
|
128
|
|
129
|
}
|