Revision 118295d6
Added by Andreas Kohlbecker about 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
19 | 19 |
import org.eclipse.swt.graphics.TextStyle; |
20 | 20 |
import org.eclipse.swt.widgets.Display; |
21 | 21 |
|
22 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
22 | 23 |
import eu.etaxonomy.cdm.model.common.TermBase; |
23 | 24 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
24 | 25 |
|
... | ... | |
35 | 36 |
/* (non-Javadoc) |
36 | 37 |
* @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) |
37 | 38 |
*/ |
38 |
|
|
39 |
|
|
39 | 40 |
/* |
40 | 41 |
* (non-Javadoc) |
41 |
*
|
|
42 |
* |
|
42 | 43 |
* @see |
43 | 44 |
* org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse. |
44 | 45 |
* jface.viewers.ViewerCell) |
... | ... | |
48 | 49 |
Object element = cell.getElement(); |
49 | 50 |
int columnIndex = cell.getColumnIndex(); |
50 | 51 |
|
51 |
String text = getText(element);
|
|
52 |
String text = getText(element); |
|
52 | 53 |
cell.setText(text); |
53 |
|
|
54 |
if (element instanceof TermVocabulary) {
|
|
54 |
|
|
55 |
if (element instanceof TermVocabulary) { |
|
55 | 56 |
StyledString styledString = new StyledString(text, getVocabularyStyler()); |
56 | 57 |
StyleRange[] styleRanges; |
57 | 58 |
styleRanges = styledString.getStyleRanges(); |
58 | 59 |
cell.setStyleRanges(styleRanges); |
59 |
}
|
|
60 |
} |
|
60 | 61 |
super.update(cell); |
61 | 62 |
} |
62 |
|
|
63 |
|
|
63 | 64 |
public StyledString getStyledText(Object element) { |
64 |
|
|
65 |
|
|
65 | 66 |
if(element instanceof TermVocabulary){ |
66 | 67 |
new StyledString(getText(element), getVocabularyStyler()); |
67 | 68 |
} |
68 | 69 |
return new StyledString(getText(element), StyledString.QUALIFIER_STYLER); |
69 | 70 |
} |
70 |
|
|
71 |
|
|
71 | 72 |
/* (non-Javadoc) |
72 | 73 |
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
73 | 74 |
*/ |
74 |
|
|
75 |
|
|
75 | 76 |
public String getText(Object element) { |
76 |
|
|
77 |
if (element instanceof TermBase){ |
|
78 |
return ((TermBase)element).getTitleCache(); |
|
79 |
} |
|
77 |
|
|
78 |
if(element instanceof DefinedTermBase){ |
|
79 |
DefinedTermBase<?> dtb = (DefinedTermBase<?>)element; |
|
80 |
return dtb.getIdInVocabulary() + " : " + dtb.getTitleCache(); |
|
81 |
} else if (element instanceof TermBase){ |
|
82 |
return ((TermBase)element).getTitleCache(); |
|
83 |
} |
|
84 |
|
|
80 | 85 |
//FIXME : must throw an exception here |
81 | 86 |
return element.toString(); |
82 | 87 |
} |
83 |
|
|
88 |
|
|
84 | 89 |
private Styler getVocabularyStyler() { |
85 | 90 |
if (vocStyler == null) { |
86 | 91 |
vocStyler = new Styler() { |
Also available in: Unified diff
implementing #4123 (add idInVocabulary to term labels in editor)