Project

General

Profile

Download (2.61 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
package eu.etaxonomy.taxeditor.editor.view.concept;
10

    
11
import java.util.Map.Entry;
12

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

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

    
24
/**
25
 * @author n.hoffmann
26
 */
27
public class ConceptLabelProvider extends LabelProvider implements IStyledLabelProvider {
28

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

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