Class TableCellPainter
java.lang.Object
org.eclipse.nebula.widgets.nattable.painter.cell.AbstractCellPainter
org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
org.eclipse.nebula.widgets.nattable.painter.cell.TableCellPainter
- All Implemented Interfaces:
ICellPainter
ICellPainter that renders a data collection as sub cells within a NatTable
cell. It uses an internal ICellPainter that can be set to render the contents
of the sub cells and inserts grid lines between the elements in the list.
Note:
- As this painter simulates but is not really an internal table, on selection the whole internal table will get selected.
- As the internal table structure that is rendered by this painter is not related to NatTable table structure, the NatTable configuration mechanism doesn'apply to the internal sub cells differently. Instead the same configuration will be applied to all sub cells.
This painter is intended for an editable NatTable in combination with the TableCellEditor.
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a TableCellPainter that uses the following default settings: internal painter = TextPainter grid color = gray selected grid color = white fixed sub cell row height = 20 calculate parent cell height = true Despite the internal painter you can change these settings after creation with the corresponding setters.TableCellPainter
(ICellPainter internalPainter) Creates a TableCellPainter that uses the given ICellPainter as internal painter for the sub cells created and rendered by this painter.TableCellPainter
(ICellPainter internalPainter, org.eclipse.swt.graphics.Color gridColor, org.eclipse.swt.graphics.Color selectedGridColor, int fixedSubCellHeight, boolean calculateParentCellHeight) Creates a TableCellPainter that uses the given values for configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected ILayerCell
createSubLayerCell
(ILayerCell cell, Object dataValue) Creating a temporary sub cell that represents one data value in the collection of data to be shown in the cell.protected Object[]
getDataAsArray
(ILayerCell cell) Checks if the data value of the given cell is of type Collection or Array.int
org.eclipse.swt.graphics.Color
protected ICellPainter
This getter is introduced to allow overriding in subclasses to add support for mixed internal painters, like for example different painters dependent on the data type.int
getPreferredHeight
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the preferred height of the cell when rendered by this painter.int
getPreferredWidth
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the preferred width of the cell when rendered by this painter.org.eclipse.swt.graphics.Color
protected int
getSubCellHeight
(ILayerCell subCell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the height for the sub cell.boolean
void
paintCell
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, IConfigRegistry configRegistry) void
setCalculateParentCellHeight
(boolean calculateParentCellHeight) void
setFixedSubCellHeight
(int fixedSubCellHeight) Setting a value >= 0 will result in using a fixed height of the sub cells.void
setGridColor
(org.eclipse.swt.graphics.Color gridColor) void
setPaintBg
(boolean paintBg) void
setSelectedGridColor
(org.eclipse.swt.graphics.Color selectedGridColor) Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
getBackgroundColour
Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
getCellPainterAt, getWrappedPainter, getWrappedPainterBounds, setWrappedPainter
-
Constructor Details
-
TableCellPainter
public TableCellPainter()Creates a TableCellPainter that uses the following default settings:- internal painter = TextPainter
- grid color = gray
- selected grid color = white
- fixed sub cell row height = 20
- calculate parent cell height = true
-
TableCellPainter
Creates a TableCellPainter that uses the given ICellPainter as internal painter for the sub cells created and rendered by this painter.Will use the following default settings:
- grid color = gray
- selected grid color = white
- fixed sub cell row height = 20
- calculate parent cell height = true
- Parameters:
internalPainter
- The ICellPainter that should be used to render the internal sub cells.
-
TableCellPainter
public TableCellPainter(ICellPainter internalPainter, org.eclipse.swt.graphics.Color gridColor, org.eclipse.swt.graphics.Color selectedGridColor, int fixedSubCellHeight, boolean calculateParentCellHeight) Creates a TableCellPainter that uses the given values for configuration.- Parameters:
internalPainter
- The ICellPainter that should be used to render the internal sub cells.gridColor
- The color that should be used to render the grid lines in the sub table inDisplayMode.NORMAL
selectedGridColor
- The color that should be used to render the grid lines in the sub table inDisplayMode.SELECT
fixedSubCellHeight
- The height of the sub cells to use. Setting a value >= 0 will result in using the specified fixed sub cell heights, a negative value will result in dynamically calculated sub cell heights dependent on the content.calculateParentCellHeight
- Whether this painter shall resize the row height of the parent cell to show all available data in the internal table or not.
-
-
Method Details
-
paintCell
public void paintCell(ILayerCell cell, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, IConfigRegistry configRegistry) - Specified by:
paintCell
in interfaceICellPainter
- Overrides:
paintCell
in classBackgroundPainter
-
getPreferredWidth
public int getPreferredWidth(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Description copied from interface:ICellPainter
Get the preferred width of the cell when rendered by this painter. Used for auto-resize.- Specified by:
getPreferredWidth
in interfaceICellPainter
- Overrides:
getPreferredWidth
in classCellPainterWrapper
- Parameters:
cell
- The cell for which the preferred width is requested.gc
- The GC that is used for rendering.configRegistry
- The IConfigRegistry that contains the configuration used for rendering.- Returns:
- The preferred width of the given cell when rendered by this painter.
-
getPreferredHeight
public int getPreferredHeight(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Description copied from interface:ICellPainter
Get the preferred height of the cell when rendered by this painter. Used for auto-resize.- Specified by:
getPreferredHeight
in interfaceICellPainter
- Overrides:
getPreferredHeight
in classCellPainterWrapper
- Parameters:
cell
- The cell for which the preferred height is requested.gc
- The GC that is used for rendering.configRegistry
- The IConfigRegistry that contains the configuration used for rendering.- Returns:
- The preferred height of the given cell when rendered by this painter.
-
getDataAsArray
Checks if the data value of the given cell is of type Collection or Array. Will return the Collection or Array as Object[] ornull
if the data value is not a Collection or Array.- Parameters:
cell
- The cell that should be checked for its data.- Returns:
- The Object[] representation of the data value if it is of type
Collection or Array, or
null
if the data value is not a Collection or Array.
-
createSubLayerCell
Creating a temporary sub cell that represents one data value in the collection of data to be shown in the cell. This is then used to get the size and paint the cell using the underlying painter.- Parameters:
cell
- The parent cell for which the sub cell should be createddataValue
- The data value that should be contained in the sub cell- Returns:
- A temporary sub cell of the given parent cell used to paint and calculate inner cells.
-
getSubCellHeight
protected int getSubCellHeight(ILayerCell subCell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the height for the sub cell.- Parameters:
subCell
- The temporary sub cell that is used to ask the internal painter for renderinggc
- The GC that is used for renderingconfigRegistry
- The ConfigRegistry that contains the configurations of the current NatTable- Returns:
- The height for the sub cell dependent on the fixedSubCellHeight configuration
-
getInternalPainter
This getter is introduced to allow overriding in subclasses to add support for mixed internal painters, like for example different painters dependent on the data type.Note: As the internal table structure that is rendered by this painter is not related to NatTable table structure, the NatTable configuration mechanism doesn'apply to the internal sub cells differently. Instead the same configuration will be applied to all sub cells.
- Returns:
- The ICellPainter that should be used to render the internal sub cells.
-
getGridColor
public org.eclipse.swt.graphics.Color getGridColor()- Returns:
- The color that is used to render the grid lines in the sub table
in
DisplayMode.NORMAL
-
setGridColor
public void setGridColor(org.eclipse.swt.graphics.Color gridColor) - Parameters:
gridColor
- The color that should be used to render the grid lines in the sub table inDisplayMode.NORMAL
-
getSelectedGridColor
public org.eclipse.swt.graphics.Color getSelectedGridColor()- Returns:
- The color that is used to render the grid lines in the sub table
in
DisplayMode.SELECT
-
setSelectedGridColor
public void setSelectedGridColor(org.eclipse.swt.graphics.Color selectedGridColor) - Parameters:
selectedGridColor
- The color that should be used to render the grid lines in the sub table inDisplayMode.SELECT
-
getFixedSubCellHeight
public int getFixedSubCellHeight()- Returns:
- The height of the sub cells to use. A value >= 0 results in using the specified fixed sub cell heights, a negative value results in dynamically calculated sub cell heights dependent on the content.
-
setFixedSubCellHeight
public void setFixedSubCellHeight(int fixedSubCellHeight) Setting a value >= 0 will result in using a fixed height of the sub cells. Setting the value to a negative number will ask the internal painter for the sub cells to calculate the height regarding the content.- Parameters:
fixedSubCellHeight
- The height of the sub cells to use.
-
isCalculateParentCellHeight
public boolean isCalculateParentCellHeight()- Returns:
true
if this painter resizes the row height of the parent cell to show all available data in the internal table,false
if not.
-
setCalculateParentCellHeight
public void setCalculateParentCellHeight(boolean calculateParentCellHeight) - Parameters:
calculateParentCellHeight
- Whether this painter shall resize the row height of the parent cell to show all available data in the internal table or not.
-
setPaintBg
public void setPaintBg(boolean paintBg) - Parameters:
paintBg
-true
to paint the background,false
if not.true
is default- Since:
- 1.4
-