Project

General

Profile

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

    
10
package eu.etaxonomy.taxeditor.editor.view.concept;
11

    
12
import java.util.Map.Entry;
13

    
14
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
15
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.jface.viewers.StyledString;
17
import org.eclipse.swt.graphics.Image;
18

    
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
21
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
22
import eu.etaxonomy.taxeditor.model.ImageResources;
23
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
24

    
25
/**
26
 * @author n.hoffmann
27
 * @created Jan 24, 2011
28
 * @version 1.0
29
 */
30
public class ConceptLabelProvider extends LabelProvider implements IStyledLabelProvider {
31

    
32
	@Override
33
	public Image getImage(Object element) {
34
		if(element instanceof Entry){
35
			return getTaxonRelationshipImage((TaxonRelationship) ((Entry<TaxonRelationship, Taxon>) element).getKey());
36
		}
37
		return super.getImage(element);
38
	}
39
	
40
	@Override
41
	public String getText(Object element) {
42
		if(element instanceof Entry){
43
			return formatRelationship((Entry<TaxonRelationship, Taxon>) element);
44
		}
45
		
46
		return ""; //$NON-NLS-1$
47
	}
48
	
49
	/**
50
	 * Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
51
	 * the currently selected and accepted taxon.
52
	 * 
53
	 * @param relationship
54
	 * @return a formatted String representation of the relationship
55
	 */
56
	private String formatRelationship(Entry<TaxonRelationship, Taxon> entry){
57
		Taxon sourceTaxon = entry.getValue();
58
		TaxonRelationshipTypeInverseContainer container = TaxonRelationshipTypeInverseContainer.CreateFromSource(sourceTaxon, entry.getKey());
59
		Taxon relatedTaxon = TaxonRelationshipTypeInverseContainer.RelatedTaxon(sourceTaxon, entry.getKey());
60
		String string = String.format("%s %s", container.getAbbreviatedLabel(), relatedTaxon); //$NON-NLS-1$
61
		
62
		return string;
63
	}
64
	
65
	@Override
66
	public StyledString getStyledText(Object element) {
67
		return  new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
68
	}
69

    
70
	/**
71
	 * TODO we will get the proper relationship symbol from the type's abbreviated label as a character.
72
	 * The image may be omitted then.
73
	 * 
74
	 * @param type
75
	 * @return
76
	 */
77
	private Image getTaxonRelationshipImage(TaxonRelationship relationship) {
78
		TaxonRelationshipType type = (relationship).getType();
79
		return ImageResources.getImage(ImageResources.CONCEPT_ICON);
80
	}
81
}
(2-2/3)