1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.definedterm;
|
10
|
|
11
|
import org.eclipse.jface.viewers.StyledCellLabelProvider;
|
12
|
import org.eclipse.jface.viewers.StyledString;
|
13
|
import org.eclipse.jface.viewers.StyledString.Styler;
|
14
|
import org.eclipse.jface.viewers.ViewerCell;
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.custom.StyleRange;
|
17
|
import org.eclipse.swt.graphics.Color;
|
18
|
import org.eclipse.swt.graphics.TextStyle;
|
19
|
import org.eclipse.swt.widgets.Display;
|
20
|
|
21
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
23
|
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
|
24
|
|
25
|
/**
|
26
|
*
|
27
|
* @author pplitzner
|
28
|
* @since Oct 29, 2018
|
29
|
*
|
30
|
*/
|
31
|
public class TermDtoLabelProvider extends StyledCellLabelProvider {
|
32
|
|
33
|
private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
|
34
|
private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
|
35
|
private Styler vocStyler;
|
36
|
private Styler kindOfStyler;
|
37
|
|
38
|
public TermDtoLabelProvider() {
|
39
|
}
|
40
|
|
41
|
public TermDtoLabelProvider(Styler vocStyler){
|
42
|
this.vocStyler = vocStyler;
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public void update(ViewerCell cell) {
|
47
|
Object element = cell.getElement();
|
48
|
|
49
|
String text = getText(element);
|
50
|
cell.setText(text);
|
51
|
|
52
|
Styler styler = null;
|
53
|
if (element instanceof TermVocabularyDto && text != null) {
|
54
|
styler = getVocabularyStyler();
|
55
|
}
|
56
|
//TODO: add kindOf UUID to TermDto
|
57
|
// else if(element instanceof TermDto && ((TermDto) element).getKindOf()!=null){
|
58
|
// styler = getKindOfStyler();
|
59
|
// }
|
60
|
if(styler!=null){
|
61
|
StyledString styledString = new StyledString(text, styler);
|
62
|
StyleRange[] styleRanges;
|
63
|
styleRanges = styledString.getStyleRanges();
|
64
|
cell.setStyleRanges(styleRanges);
|
65
|
}
|
66
|
super.update(cell);
|
67
|
}
|
68
|
|
69
|
public String getText(Object element) {
|
70
|
String label = null;
|
71
|
if(element instanceof AbstractTermDto){
|
72
|
AbstractTermDto termDto = (AbstractTermDto)element;
|
73
|
termDto.localize(new TermRepresentation_L10n());
|
74
|
label = termDto.getRepresentation_L10n();
|
75
|
|
76
|
//TODO: add idInVocabulary to TermDto
|
77
|
// label = CdmUtils.concat(" : ", termDto.getIdInVocabulary(), label);
|
78
|
}
|
79
|
// TODO add fallback for label
|
80
|
if(label==null){
|
81
|
label = element.toString();
|
82
|
}
|
83
|
return label;
|
84
|
}
|
85
|
|
86
|
protected Styler getVocabularyStyler() {
|
87
|
if (vocStyler == null) {
|
88
|
vocStyler = new Styler() {
|
89
|
@Override
|
90
|
public void applyStyles(TextStyle textStyle) {
|
91
|
textStyle.foreground = vocColor;
|
92
|
}
|
93
|
};
|
94
|
}
|
95
|
return vocStyler;
|
96
|
}
|
97
|
|
98
|
protected Styler getKindOfStyler() {
|
99
|
if (kindOfStyler == null) {
|
100
|
kindOfStyler = new Styler() {
|
101
|
@Override
|
102
|
public void applyStyles(TextStyle textStyle) {
|
103
|
textStyle.foreground = kindOfColor;
|
104
|
}
|
105
|
};
|
106
|
}
|
107
|
return kindOfStyler;
|
108
|
}
|
109
|
|
110
|
}
|