2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.concept
;
12 import java
.util
.Map
.Entry
;
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
;
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
;
27 * @created Jan 24, 2011
30 public class ConceptLabelProvider
extends LabelProvider
implements IStyledLabelProvider
{
33 public Image
getImage(Object element
) {
34 if(element
instanceof Entry
){
35 return getTaxonRelationshipImage((TaxonRelationship
) ((Entry
<TaxonRelationship
, Taxon
>) element
).getKey());
37 return super.getImage(element
);
41 public String
getText(Object element
) {
42 if(element
instanceof Entry
){
43 return formatRelationship((Entry
<TaxonRelationship
, Taxon
>) element
);
46 return ""; //$NON-NLS-1$
50 * Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
51 * the currently selected and accepted taxon.
54 * @return a formatted String representation of the relationship
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$
66 public StyledString
getStyledText(Object element
) {
67 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
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.
77 private Image
getTaxonRelationshipImage(TaxonRelationship relationship
) {
78 TaxonRelationshipType type
= (relationship
).getType();
79 return ImageResources
.getImage(ImageResources
.CONCEPT_ICON
);