Project

General

Profile

Download (2.63 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.editor.view.concept;
12

    
13
import java.util.Map.Entry;
14

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

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

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

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

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