3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.concept
;
13 import java
.util
.Map
.Entry
;
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
;
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
;
28 * @created Jan 24, 2011
31 public class ConceptLabelProvider
extends LabelProvider
implements IStyledLabelProvider
{
34 public Image
getImage(Object element
) {
35 if(element
instanceof Entry
){
36 return getTaxonRelationshipImage((TaxonRelationship
) ((Entry
<TaxonRelationship
, Taxon
>) element
).getKey());
38 return super.getImage(element
);
42 public String
getText(Object element
) {
43 if(element
instanceof Entry
){
44 return formatRelationship((Entry
<TaxonRelationship
, Taxon
>) element
);
51 * Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
52 * the currently selected and accepted taxon.
55 * @return a formatted String representation of the relationship
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
);
67 public StyledString
getStyledText(Object element
) {
68 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
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.
78 private Image
getTaxonRelationshipImage(TaxonRelationship relationship
) {
79 TaxonRelationshipType type
= (relationship
).getType();
80 return ImageResources
.getImage(ImageResources
.CONCEPT_ICON
);