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
.TermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
30 public class TermLabelProvider
extends StyledCellLabelProvider
{
32 private static Color vocColor
= Display
.getCurrent().getSystemColor(
34 private Styler vocStyler
;
36 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
43 * org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.
44 * jface.viewers.ViewerCell)
47 public void update(ViewerCell cell
) {
48 Object element
= cell
.getElement();
49 int columnIndex
= cell
.getColumnIndex();
51 String text
= getText(element
);
54 if (element
instanceof TermVocabulary
) {
55 StyledString styledString
= new StyledString(text
, getVocabularyStyler());
56 StyleRange
[] styleRanges
;
57 styleRanges
= styledString
.getStyleRanges();
58 cell
.setStyleRanges(styleRanges
);
63 public StyledString
getStyledText(Object element
) {
65 if(element
instanceof TermVocabulary
){
66 new StyledString(getText(element
), getVocabularyStyler());
68 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
72 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
75 public String
getText(Object element
) {
77 if (element
instanceof TermBase
){
78 return ((TermBase
)element
).getTitleCache();
80 //FIXME : must throw an exception here
81 return element
.toString();
84 private Styler
getVocabularyStyler() {
85 if (vocStyler
== null) {
86 vocStyler
= new Styler() {
88 public void applyStyles(TextStyle textStyle
) {
89 textStyle
.foreground
= vocColor
;