Class TableCellPainter

All Implemented Interfaces:
ICellPainter

public class TableCellPainter extends BackgroundPainter
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 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
      Despite the internal painter you can change these settings after creation with the corresponding setters. If you want to use a different internal painter you should use the corresponding constructor. Changing the internal painter at runtime is not intended.
    • TableCellPainter

      public TableCellPainter(ICellPainter internalPainter)
      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
      You can change these settings after creation with the corresponding setters.
      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 in DisplayMode.NORMAL
      selectedGridColor - The color that should be used to render the grid lines in the sub table in DisplayMode.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 interface ICellPainter
      Overrides:
      paintCell in class BackgroundPainter
    • 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 interface ICellPainter
      Overrides:
      getPreferredWidth in class CellPainterWrapper
      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 interface ICellPainter
      Overrides:
      getPreferredHeight in class CellPainterWrapper
      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

      protected Object[] getDataAsArray(ILayerCell cell)
      Checks if the data value of the given cell is of type Collection or Array. Will return the Collection or Array as Object[] or null 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

      protected 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. 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 created
      dataValue - 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 rendering
      gc - The GC that is used for rendering
      configRegistry - The ConfigRegistry that contains the configurations of the current NatTable
      Returns:
      The height for the sub cell dependent on the fixedSubCellHeight configuration
    • getInternalPainter

      protected ICellPainter 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 in DisplayMode.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 in DisplayMode.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