The IStyledLabelProvider
is used to style the representation of the tree viewer, as used by the Java outline viewer for displaying the return type of the method, and by the team's decorator when showing when changes have occurred.
Add the
IStyledLabelProvider
interface to theTimeZoneLabelProvider
, and create thegetStyledText()
method. If the selected element is aMap.Entry
that contains aTimeZone
, add the offset afterwards in brackets.public class TimeZoneLabelProvider extends LabelProvider implements IStyledLabelProvider { public StyledString getStyledText(Object element) { String text = getText(element); StyledString ss = new StyledString(text); if (element instanceof TimeZone) { int offset = -((TimeZone) element).getOffset(0); ss.append(" (" + offset / 3600000 + "h)", StyledString.DECORATIONS_STYLER); } return ss; } }
In order to use the styled label provider, it has to be wrapped within a
DelegatingStyledCellLabelProvider...