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
.DelegatingStyledCellLabelProvider
.IStyledLabelProvider
;
13 import org
.eclipse
.jface
.viewers
.StyledString
.Styler
;
14 import org
.eclipse
.jface
.viewers
.LabelProvider
;
15 import org
.eclipse
.jface
.viewers
.StyledCellLabelProvider
;
16 import org
.eclipse
.jface
.viewers
.StyledString
;
17 import org
.eclipse
.jface
.viewers
.ViewerCell
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.custom
.StyleRange
;
20 import org
.eclipse
.swt
.graphics
.Color
;
21 import org
.eclipse
.swt
.graphics
.TextStyle
;
22 import org
.eclipse
.swt
.widgets
.Display
;
24 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
27 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
34 public class TermLabelProvider
extends StyledCellLabelProvider
{
36 private static Color vocColor
= Display
.getCurrent().getSystemColor(
38 private Styler vocStyler
;
40 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
47 * org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.
48 * jface.viewers.ViewerCell)
51 public void update(ViewerCell cell
) {
52 Object element
= cell
.getElement();
53 int columnIndex
= cell
.getColumnIndex();
55 String text
= getText(element
);
58 if (element
instanceof TermVocabulary
) {
59 StyledString styledString
= new StyledString(text
, getVocabularyStyler());
60 StyleRange
[] styleRanges
;
61 styleRanges
= styledString
.getStyleRanges();
62 cell
.setStyleRanges(styleRanges
);
67 public StyledString
getStyledText(Object element
) {
69 if(element
instanceof TermVocabulary
){
70 new StyledString(getText(element
), getVocabularyStyler());
72 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
76 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
79 public String
getText(Object element
) {
81 if (element
instanceof TermBase
){
82 return ((TermBase
)element
).getTitleCache();
84 //FIXME : must throw an exception here
85 return element
.toString();
88 private Styler
getVocabularyStyler() {
89 if (vocStyler
== null) {
90 vocStyler
= new Styler() {
92 public void applyStyles(TextStyle textStyle
) {
93 textStyle
.foreground
= vocColor
;