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.ColumnLabelProvider;
|
12
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
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.Image;
|
20
|
import org.eclipse.swt.graphics.TextStyle;
|
21
|
import org.eclipse.swt.widgets.Display;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n;
|
24
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
25
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
26
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
27
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
28
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
29
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* @author pplitzner
|
34
|
* @since Oct 29, 2018
|
35
|
*
|
36
|
*/
|
37
|
public class TermDtoLabelProvider //extends StyledCellLabelProvider implements ILabelProvider{
|
38
|
extends ColumnLabelProvider implements IStyledLabelProvider{
|
39
|
|
40
|
private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
|
41
|
private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
|
42
|
private Styler vocStyler;
|
43
|
private Styler kindOfStyler;
|
44
|
protected boolean showIdInVoc = false;
|
45
|
|
46
|
public TermDtoLabelProvider() {
|
47
|
showIdInVoc = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS, true);
|
48
|
}
|
49
|
|
50
|
public TermDtoLabelProvider(Styler vocStyler){
|
51
|
this.vocStyler = vocStyler;
|
52
|
showIdInVoc = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS, true);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public void update(ViewerCell cell) {
|
57
|
Object element = cell.getElement();
|
58
|
// boolean showIdInVoc = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_VOCABULARY_ID_FOR_TERM_LABELS, true);
|
59
|
String text = getText(element);
|
60
|
cell.setText(text);
|
61
|
|
62
|
Styler styler = null;
|
63
|
if (element instanceof TermVocabularyDto && text != null) {
|
64
|
styler = getVocabularyStyler();
|
65
|
}
|
66
|
else if(element instanceof TermDto && ((TermDto) element).getKindOfUuid()!=null){
|
67
|
styler = getKindOfStyler();
|
68
|
}
|
69
|
if(styler!=null){
|
70
|
StyledString styledString = new StyledString(text, styler);
|
71
|
StyleRange[] styleRanges;
|
72
|
styleRanges = styledString.getStyleRanges();
|
73
|
cell.setStyleRanges(styleRanges);
|
74
|
}
|
75
|
super.update(cell);
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public String getText(Object element) {
|
80
|
String label = null;
|
81
|
if(element instanceof AbstractTermDto){
|
82
|
AbstractTermDto termDto = (AbstractTermDto)element;
|
83
|
termDto.localize(new TermRepresentation_L10n());
|
84
|
label = termDto.getRepresentation_L10n();
|
85
|
|
86
|
if(showIdInVoc && element instanceof TermDto && ((TermDto) termDto).getIdInVocabulary()!=null){
|
87
|
label = CdmUtils.concat(" : ", ((TermDto) termDto).getIdInVocabulary(), label);
|
88
|
}
|
89
|
}
|
90
|
// TODO add fallback for label
|
91
|
if(label==null){
|
92
|
label = element.toString();
|
93
|
}
|
94
|
return label;
|
95
|
}
|
96
|
|
97
|
protected Styler getVocabularyStyler() {
|
98
|
if (vocStyler == null) {
|
99
|
vocStyler = new Styler() {
|
100
|
@Override
|
101
|
public void applyStyles(TextStyle textStyle) {
|
102
|
textStyle.foreground = vocColor;
|
103
|
}
|
104
|
};
|
105
|
}
|
106
|
return vocStyler;
|
107
|
}
|
108
|
|
109
|
protected Styler getKindOfStyler() {
|
110
|
if (kindOfStyler == null) {
|
111
|
kindOfStyler = new Styler() {
|
112
|
@Override
|
113
|
public void applyStyles(TextStyle textStyle) {
|
114
|
textStyle.foreground = kindOfColor;
|
115
|
}
|
116
|
};
|
117
|
}
|
118
|
return kindOfStyler;
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
public Image getImage(Object element) {
|
123
|
|
124
|
return null;
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
public StyledString getStyledText(Object element) {
|
129
|
return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
|
130
|
}
|
131
|
|
132
|
|
133
|
|
134
|
}
|