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
.apache
.commons
.lang
.StringUtils
;
13 import org
.eclipse
.jface
.viewers
.StyledCellLabelProvider
;
14 import org
.eclipse
.jface
.viewers
.StyledString
;
15 import org
.eclipse
.jface
.viewers
.StyledString
.Styler
;
16 import org
.eclipse
.jface
.viewers
.ViewerCell
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.custom
.StyleRange
;
19 import org
.eclipse
.swt
.graphics
.Color
;
20 import org
.eclipse
.swt
.graphics
.TextStyle
;
21 import org
.eclipse
.swt
.widgets
.Display
;
23 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
32 public class TermLabelProvider
extends StyledCellLabelProvider
{
34 private static Color vocColor
= Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
);
35 private Styler vocStyler
;
37 public TermLabelProvider() {
40 public TermLabelProvider(Styler vocStyler
){
41 this.vocStyler
= vocStyler
;
48 * org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.
49 * jface.viewers.ViewerCell)
52 public void update(ViewerCell cell
) {
53 Object element
= cell
.getElement();
54 int columnIndex
= cell
.getColumnIndex();
56 String text
= getText(element
);
59 if (element
instanceof TermVocabulary
) {
60 StyledString styledString
= new StyledString(text
, getVocabularyStyler());
61 StyleRange
[] styleRanges
;
62 styleRanges
= styledString
.getStyleRanges();
63 cell
.setStyleRanges(styleRanges
);
68 public StyledString
getStyledText(Object element
) {
70 if (element
instanceof TermVocabulary
) {
71 new StyledString(getText(element
), getVocabularyStyler());
73 return new StyledString(getText(element
), StyledString
.QUALIFIER_STYLER
);
79 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
82 public String
getText(Object element
) {
84 if (element
instanceof DefinedTermBase
) {
85 DefinedTermBase
<?
> dtb
= (DefinedTermBase
<?
>) element
;
86 if (StringUtils
.isNotBlank(dtb
.getIdInVocabulary())) {
87 return dtb
.getIdInVocabulary() + " : " + dtb
.getTitleCache();
89 return dtb
.getTitleCache();
91 } else if (element
instanceof TermBase
) {
92 return ((TermBase
) element
).getTitleCache();
95 // FIXME : must throw an exception here
96 return element
.toString();
99 private Styler
getVocabularyStyler() {
100 if (vocStyler
== null) {
101 vocStyler
= new Styler() {
103 public void applyStyles(TextStyle textStyle
) {
104 textStyle
.foreground
= vocColor
;