Project

General

Profile

Download (3.23 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.navigation.search;
12

    
13
import org.eclipse.jface.viewers.ColumnLabelProvider;
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.graphics.Image;
17

    
18
import eu.etaxonomy.cdm.model.taxon.Synonym;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23
import eu.etaxonomy.taxeditor.model.ImageResources;
24
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
25
import eu.etaxonomy.taxeditor.preference.Resources;
26

    
27
/**
28
 *
29
 * @author n.hoffmann
30
 * @created 04.05.2009
31
 * @version 1.0
32
 */
33
public class SearchResultLabelProvider extends ColumnLabelProvider {
34

    
35
	/** {@inheritDoc} */
36
	@Override
37
    public String getText(Object element) {
38
		if(element instanceof UuidAndTitleCache){
39
			return ((UuidAndTitleCache) element).getTitleCache();
40
		}
41
		return element.toString();
42
	}
43

    
44
	/** {@inheritDoc} */
45
	@Override
46
	public Color getBackground(Object element) {
47
		return super.getBackground(element);
48
	}
49

    
50
	/** {@inheritDoc} */
51
	@Override
52
	public Font getFont(Object element) {
53
	    if(element instanceof UuidAndTitleCache){
54
	        Class type = ((UuidAndTitleCache) element).getType();
55
	        if(type == Taxon.class){
56
	            return AbstractUtility.getFont(Resources.FONT_SEARCH_VIEW_ACCEPTED);
57
	        }else if(type == Synonym.class){
58
	            return AbstractUtility.getFont(Resources.FONT_SEARCH_VIEW_SYNONYM);
59
	        }
60
	    }
61
	    return AbstractUtility.getFont(Resources.FONT_SEARCH_VIEW_OTHER);
62
	}
63

    
64
	/** {@inheritDoc} */
65
	@Override
66
	public Image getImage(Object element) {
67
		if(element instanceof UuidAndTitleCache){
68
			Class type = ((UuidAndTitleCache) element).getType();
69
			// unfortunately we can not distinct misapplication anymore
70
//			if(taxon.isMisapplication()){
71
//				return ImageResources.getImage(ImageResources.MISAPPLIED_NAME_ICON);
72
//			}else{
73
			if(type == Taxon.class){
74
				if(((UuidAndTitleCache) element).getIsOrphaned()) {
75
					return ImageResources.getImage(ImageResources.ORPHANED_TAXON);
76
				}
77
				return ImageResources.getImage(ImageResources.BLACK_SQUARE_ICON);
78
			}else if(type == Synonym.class){
79
				return ImageResources.getImage(ImageResources.HETEROTYPIC_SYN_ICON);
80
			}
81
		}
82
		return super.getImage(element);
83
	}
84

    
85

    
86
	/** {@inheritDoc} */
87
	@Override
88
	public String getToolTipText(Object element) {
89
	    if(element instanceof UuidAndTitleCache){
90
	        Class type = ((UuidAndTitleCache) element).getType();
91
	        if(TaxonBase.class.isAssignableFrom(type)){
92
	            if(type.equals(Synonym.class)){
93
	                return Messages.SearchResultLabelProvider_SYNONYM + ((TaxonBase<?>) element).getName().getTitleCache();
94
	            }else{
95
	                return Messages.SearchResultLabelProvider_TAXON + ((TaxonBase<?>) element).getName().getTitleCache();
96
	            }
97
	        }
98
	    }
99
	    return Messages.SearchResultLabelProvider_NAME + element.toString();
100
	}
101

    
102
}
(3-3/3)