Project

General

Profile

Download (3.26 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 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.common.Language;
19
import eu.etaxonomy.cdm.model.common.Representation;
20
import eu.etaxonomy.cdm.model.reference.IReference;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
26
import eu.etaxonomy.taxeditor.model.ImageResources;
27
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author n.hoffmann
32
 * @created Jan 24, 2011
33
 * @version 1.0
34
 */
35
public class ConceptLabelProvider extends LabelProvider implements IStyledLabelProvider {
36

    
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
39
	 */
40
	@Override
41
	public Image getImage(Object element) {
42
		if(element instanceof TaxonRelationship){
43
			return getTaxonRelationshipImage((TaxonRelationship) element);
44
		}
45
		return super.getImage(element);
46
	}
47
	
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
50
	 */
51
	@Override
52
	public String getText(Object element) {
53
		if(element instanceof TaxonRelationship){
54
			return formatRelationship((TaxonRelationship) element);
55
		}
56
		
57
		return "";
58
	}
59
	
60
	/**
61
	 * Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
62
	 * the accepted taxon of the currently active {@link MultiPageTaxonEditor}.
63
	 * 
64
	 * @param relationship
65
	 * @return a formatted String representation of the relationship
66
	 */
67
	private String formatRelationship(TaxonRelationship relationship){
68
		Taxon sourceTaxon = EditorUtil.getActiveMultiPageTaxonEditor().getTaxon();
69
		TaxonRelationshipTypeInverseContainer container = TaxonRelationshipTypeInverseContainer.CreateFromSource(sourceTaxon, relationship);
70
		Taxon relatedTaxon = TaxonRelationshipTypeInverseContainer.RelatedTaxon(sourceTaxon, relationship);
71
		String string = String.format("%s %s", container.getAbbreviatedLabel(), relatedTaxon);
72
		
73
		return string;
74
	}
75
	
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
78
	 */
79
	@Override
80
	public StyledString getStyledText(Object element) {
81
		return  new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
82
	}
83

    
84
	/**
85
	 * TODO we will get the proper relationship symbol from the type's abbreviated label as a character.
86
	 * The image may be omitted then.
87
	 * 
88
	 * @param type
89
	 * @return
90
	 */
91
	private Image getTaxonRelationshipImage(TaxonRelationship relationship) {
92
		TaxonRelationshipType type = (relationship).getType();
93
		return ImageResources.getImage(ImageResources.CONCEPT_ICON);
94
	}
95
}
(2-2/4)