Package org.eclipse.jface.viewers
Class StyledCellLabelProvider
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.jface.viewers.BaseLabelProvider
-
- org.eclipse.jface.viewers.CellLabelProvider
-
- org.eclipse.jface.viewers.OwnerDrawLabelProvider
-
- org.eclipse.jface.viewers.StyledCellLabelProvider
-
- All Implemented Interfaces:
IBaseLabelProvider
,IToolTipProvider
- Direct Known Subclasses:
DelegatingStyledCellLabelProvider
public abstract class StyledCellLabelProvider extends OwnerDrawLabelProvider
AStyledCellLabelProvider
supports styled labels by using owner draw. Besides the styles in labels, the label provider preserves native viewer behavior:- similar image and label positioning
- native drawing of focus and selection
For providing the label's styles, create a subclass and overwrite
update(ViewerCell)
to return set all information needed to render a element. UseViewerCell.setStyleRanges(StyleRange[])
to set style ranges on the label.- Since:
- 3.4
-
-
Field Summary
Fields Modifier and Type Field Description static int
COLORS_ON_SELECTION
Style constant for indicating that the styled colors are to be applied even it the viewer's item is selected.static int
NO_FOCUS
Style constant for indicating to draw the focus if requested by the owner draw event.
-
Constructor Summary
Constructors Constructor Description StyledCellLabelProvider()
Creates a new StyledCellLabelProvider.StyledCellLabelProvider(int style)
Creates a new StyledCellLabelProvider.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
TheBaseLabelProvider
implementation of thisIBaseLabelProvider
method clears its internal listener list.protected void
erase(Event event, Object element)
Handle the erase event.protected ViewerColumn
getColumn()
Returns the column on which this label provider is installed on ornull
if the label provider is not installed.protected ColumnViewer
getViewer()
Returns the viewer on which this label provider is installed on ornull
if the label provider is not installed.void
initialize(ColumnViewer viewer, ViewerColumn column)
This implementation ofCellLabelProvider.initialize(ColumnViewer, ViewerColumn)
delegates toOwnerDrawLabelProvider.initialize(ColumnViewer, ViewerColumn, boolean)
with a value oftrue
forenableOwnerDraw
.boolean
isOwnerDrawEnabled()
Returnstrue
is the owner draw rendering is enabled for this label provider.protected void
measure(Event event, Object element)
Handle the measure event.protected void
paint(Event event, Object element)
Handle the paint event.protected StyleRange
prepareStyleRange(StyleRange styleRange, boolean applyColors)
Prepares the given style range before it is applied to the label.void
setOwnerDrawEnabled(boolean enabled)
Specifies whether owner draw rendering is enabled for this label provider.static StyledString
styleDecoratedString(String decoratedString, StyledString.Styler decorationStyler, StyledString styledString)
Applies decoration styles to the decorated string and adds the styles of the previously undecorated string.void
update(ViewerCell cell)
Update the label for cell.-
Methods inherited from class org.eclipse.jface.viewers.OwnerDrawLabelProvider
dispose, initialize, setOwnerDrawEnabled, setUpOwnerDraw
-
Methods inherited from class org.eclipse.jface.viewers.CellLabelProvider
getToolTipBackgroundColor, getToolTipDisplayDelayTime, getToolTipFont, getToolTipForegroundColor, getToolTipImage, getToolTipShift, getToolTipStyle, getToolTipText, getToolTipTimeDisplayed, useNativeToolTip
-
Methods inherited from class org.eclipse.jface.viewers.BaseLabelProvider
addListener, fireLabelProviderChanged, isLabelProperty, removeListener
-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
-
-
-
Field Detail
-
COLORS_ON_SELECTION
public static final int COLORS_ON_SELECTION
Style constant for indicating that the styled colors are to be applied even it the viewer's item is selected. Default is not to apply colors.- See Also:
- Constant Field Values
-
NO_FOCUS
public static final int NO_FOCUS
Style constant for indicating to draw the focus if requested by the owner draw event. Default is to draw the focus.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StyledCellLabelProvider
public StyledCellLabelProvider()
Creates a new StyledCellLabelProvider. By default, owner draw is enabled, focus is drawn and no colors are painted on selected elements.
-
StyledCellLabelProvider
public StyledCellLabelProvider(int style)
Creates a new StyledCellLabelProvider. By default, owner draw is enabled.- Parameters:
style
- the style bits- See Also:
COLORS_ON_SELECTION
,NO_FOCUS
-
-
Method Detail
-
isOwnerDrawEnabled
public boolean isOwnerDrawEnabled()
Returnstrue
is the owner draw rendering is enabled for this label provider. By default owner draw rendering is enabled. If owner draw rendering is disabled, rending is done by the viewer and no styled ranges (seeViewerCell.getStyleRanges()
) are drawn.- Returns:
true
is the rendering of styles is enabled.
-
setOwnerDrawEnabled
public void setOwnerDrawEnabled(boolean enabled)
Specifies whether owner draw rendering is enabled for this label provider. By default owner draw rendering is enabled. If owner draw rendering is disabled, rendering is done by the viewer and no styled ranges (seeViewerCell.getStyleRanges()
) are drawn. It is the caller's responsibility to also callStructuredViewer.refresh()
or similar methods to update the underlying widget.- Parameters:
enabled
- specifies if owner draw rendering is enabled
-
getViewer
protected final ColumnViewer getViewer()
Returns the viewer on which this label provider is installed on ornull
if the label provider is not installed.- Returns:
- the viewer on which this label provider is installed on or
null
if the label provider is not installed.
-
getColumn
protected final ViewerColumn getColumn()
Returns the column on which this label provider is installed on ornull
if the label provider is not installed.- Returns:
- the column on which this label provider is installed on or
null
if the label provider is not installed.
-
initialize
public void initialize(ColumnViewer viewer, ViewerColumn column)
Description copied from class:OwnerDrawLabelProvider
This implementation ofCellLabelProvider.initialize(ColumnViewer, ViewerColumn)
delegates toOwnerDrawLabelProvider.initialize(ColumnViewer, ViewerColumn, boolean)
with a value oftrue
forenableOwnerDraw
. Subclasses may override this method but should either call the super implementation or, alternatively,OwnerDrawLabelProvider.initialize(ColumnViewer, ViewerColumn, boolean)
.- Overrides:
initialize
in classOwnerDrawLabelProvider
- Parameters:
viewer
- the viewercolumn
- the column, ornull
if a column is not available.
-
dispose
public void dispose()
Description copied from class:BaseLabelProvider
TheBaseLabelProvider
implementation of thisIBaseLabelProvider
method clears its internal listener list. Subclasses may extend but should call the super implementation.- Specified by:
dispose
in interfaceIBaseLabelProvider
- Overrides:
dispose
in classBaseLabelProvider
-
update
public void update(ViewerCell cell)
Description copied from class:CellLabelProvider
Update the label for cell.- Overrides:
update
in classOwnerDrawLabelProvider
- Parameters:
cell
-ViewerCell
-
prepareStyleRange
protected StyleRange prepareStyleRange(StyleRange styleRange, boolean applyColors)
Prepares the given style range before it is applied to the label. This method makes sure that no colors are drawn when the element is selected. Clients can override.- Parameters:
styleRange
- the style range to prepare. the style range element must not be modifiedapplyColors
- specifies if colors should be applied.- Returns:
- returns the style range to use on the label
-
erase
protected void erase(Event event, Object element)
Handle the erase event. The default implementation does nothing to ensure keep native selection highlighting working.- Overrides:
erase
in classOwnerDrawLabelProvider
- Parameters:
event
- the erase eventelement
- the model object- See Also:
SWT.EraseItem
-
measure
protected void measure(Event event, Object element)
Description copied from class:OwnerDrawLabelProvider
Handle the measure event.- Specified by:
measure
in classOwnerDrawLabelProvider
- Parameters:
event
- the measure eventelement
- the model element- See Also:
SWT.MeasureItem
-
paint
protected void paint(Event event, Object element)
Description copied from class:OwnerDrawLabelProvider
Handle the paint event.- Specified by:
paint
in classOwnerDrawLabelProvider
- Parameters:
event
- the paint eventelement
- the model element- See Also:
SWT.PaintItem
-
styleDecoratedString
public static StyledString styleDecoratedString(String decoratedString, StyledString.Styler decorationStyler, StyledString styledString)
Applies decoration styles to the decorated string and adds the styles of the previously undecorated string.If the
decoratedString
contains thestyledString
, then the result keeps the styles of thestyledString
and styles the decorations with thedecorationStyler
. Otherwise, the decorated string is returned without any styles.- Parameters:
decoratedString
- the decorated stringdecorationStyler
- the styler to use for the decoration ornull
for no stylesstyledString
- the original styled string- Returns:
- the styled decorated string (can be the given
styledString
) - Since:
- 3.5
-
-