3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
;
12 import org
.eclipse
.jface
.viewers
.StyledCellLabelProvider
;
13 import org
.eclipse
.jface
.viewers
.StyledString
;
14 import org
.eclipse
.jface
.viewers
.StyledString
.Styler
;
15 import org
.eclipse
.jface
.viewers
.ViewerCell
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.custom
.StyleRange
;
18 import org
.eclipse
.swt
.graphics
.Color
;
19 import org
.eclipse
.swt
.graphics
.TextStyle
;
20 import org
.eclipse
.swt
.widgets
.Display
;
22 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
31 public class TermLabelProvider
extends StyledCellLabelProvider
{
33 private static Color vocColor
= Display
.getCurrent().getSystemColor(
35 private Styler vocStyler
;
37 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
44 * org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.
45 * jface.viewers.ViewerCell)
48 public void update(ViewerCell cell
) {
49 Object element
= cell
.getElement();
50 int columnIndex
= cell
.getColumnIndex();
52 String text
= getText(element
);
55 if (element
instanceof TermVocabulary
) {
56 StyledString styledString
= new StyledString(text
, getVocabularyStyler());
57 StyleRange
[] styleRanges
;
58 styleRanges
= styledString
.getStyleRanges();
59 cell
.setStyleRanges(styleRanges
);
64 public StyledString
getStyledText(Object element
) {
66 if(element
instanceof TermVocabulary
){
67 new StyledString(getText(element
), getVocabularyStyler());
69 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
73 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
76 public String
getText(Object element
) {
78 if(element
instanceof DefinedTermBase
){
79 DefinedTermBase
<?
> dtb
= (DefinedTermBase
<?
>)element
;
80 if (dtb
.getIdInVocabulary() != null && dtb
.getIdInVocabulary() != ""){
81 return dtb
.getIdInVocabulary() + " : " + dtb
.getTitleCache();
83 return dtb
.getTitleCache();
85 } else if (element
instanceof TermBase
){
86 return ((TermBase
)element
).getTitleCache();
89 //FIXME : must throw an exception here
90 return element
.toString();
93 private Styler
getVocabularyStyler() {
94 if (vocStyler
== null) {
95 vocStyler
= new Styler() {
97 public void applyStyles(TextStyle textStyle
) {
98 textStyle
.foreground
= vocColor
;