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 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
;
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
.store
.CdmStore
;
31 * @created Jan 24, 2011
34 public class ConceptLabelProvider
extends LabelProvider
implements IStyledLabelProvider
{
37 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
40 public Image
getImage(Object element
) {
41 if(element
instanceof TaxonRelationship
){
42 return getTaxonRelationshipImage((TaxonRelationship
) element
);
44 return super.getImage(element
);
48 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
51 public String
getText(Object element
) {
52 if(element
instanceof TaxonRelationship
){
53 return formatRelationship((TaxonRelationship
) element
);
60 * Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
61 * the accepted taxon of the currently active {@link MultiPageTaxonEditor}.
64 * @return a formatted String representation of the relationship
66 private String
formatRelationship(TaxonRelationship relationship
){
67 Taxon acceptedTaxon
= EditorUtil
.getActiveMultiPageTaxonEditor().getTaxon();
68 boolean inverse
= relationship
.getFromTaxon().equals(acceptedTaxon
) ?
true : false;
70 TaxonRelationshipType type
= relationship
.getType();
71 Representation representation
= inverse ? type
.getInverseRepresentation(Language
.ENGLISH()) : type
.getRepresentation(Language
.ENGLISH());
73 Taxon relatedTaxon
= inverse ? relationship
.getToTaxon() : relationship
.getFromTaxon();
75 String symbolString
= representation
.getAbbreviatedLabel();
76 String relatedTaxonString
= relatedTaxon
.getName().getTitleCache();
77 String secReferenceString
= relatedTaxon
.getSec().getTitleCache();
79 String string
= String
.format("%s %s sensu %s", symbolString
, relatedTaxonString
, secReferenceString
);
85 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
88 public StyledString
getStyledText(Object element
) {
89 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
93 * TODO we will get the proper relationship symbol from the type's abbreviated label as a character.
94 * The image may be omitted then.
99 private Image
getTaxonRelationshipImage(TaxonRelationship relationship
) {
100 TaxonRelationshipType type
= (relationship
).getType();
101 return ImageResources
.getImage(ImageResources
.CONCEPT_ICON
);