Class NatGridLayerPainter

java.lang.Object
org.eclipse.nebula.widgets.nattable.painter.layer.NatLayerPainter
org.eclipse.nebula.widgets.nattable.painter.layer.NatGridLayerPainter
All Implemented Interfaces:
ILayerCommandHandler<RowSizeConfigurationCommand>, ILayerPainter

public class NatGridLayerPainter extends NatLayerPainter implements ILayerCommandHandler<RowSizeConfigurationCommand>
Specialization of NatLayerPainter that fills the background with grid lines to create the same look and feel as native table controls. It is possible to specify the grid line color directly or via ConfigRegistry CellConfigAttributes.GRID_LINE_COLOR, where the ConfigRegistry entry will win over direct configuration.

If there should be several fake rows rendered, you need to set the default row height that should be used for rendering the fake row lines. Otherwise this will be skipped and only the column lines will be rendered to the bottom.

  • Constructor Details

    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable, org.eclipse.swt.graphics.Color gridColor)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
      gridColor - The Color that should be used to render the grid lines. Note that an entry for CellConfigAttributes.GRID_LINE_COLOR will override this value at runtime.
    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable, int defaultRowHeight)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
      defaultRowHeight - The row height that should be used to render fake rows to the bottom. Setting a value of 0 will avoid rendering fake row lines.
    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable, int defaultRowHeight, boolean registerCommandHandler)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
      defaultRowHeight - The row height that should be used to render fake rows to the bottom. Setting a value of 0 will avoid rendering fake row lines.
      registerCommandHandler - If set to true this class registers as ILayerCommandHandler for the RowSizeConfigurationCommand on the NatTable instance.
      Since:
      2.3
    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable, org.eclipse.swt.graphics.Color gridColor, int defaultRowHeight)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
      gridColor - The Color that should be used to render the grid lines. Note that an entry for CellConfigAttributes.GRID_LINE_COLOR will override this value at runtime.
      defaultRowHeight - The row height that should be used to render fake rows to the bottom. Setting a value of 0 will avoid rendering fake row lines.
    • NatGridLayerPainter

      public NatGridLayerPainter(NatTable natTable, org.eclipse.swt.graphics.Color gridColor, int defaultRowHeight, boolean registerCommandHandler)
      Parameters:
      natTable - The NatTable instance for which the NatGridLayerPainter should render the background.
      gridColor - The Color that should be used to render the grid lines. Note that an entry for CellConfigAttributes.GRID_LINE_COLOR will override this value at runtime.
      defaultRowHeight - The row height that should be used to render fake rows to the bottom. Setting a value of 0 will avoid rendering fake row lines.
      registerCommandHandler - If set to true this class registers as ILayerCommandHandler for the RowSizeConfigurationCommand on the NatTable instance.
      Since:
      2.3
  • Method Details

    • paintBackground

      protected void paintBackground(ILayer natLayer, org.eclipse.swt.graphics.GC gc, int xOffset, int yOffset, org.eclipse.swt.graphics.Rectangle rectangle, IConfigRegistry configRegistry)
      Overrides:
      paintBackground in class NatLayerPainter
    • getConfiguredDefaultRowHeight

      public int getConfiguredDefaultRowHeight()
      Returns:
      The currently configured unscaled height that is used to render fake rows.
      Since:
      2.3
    • getDefaultRowHeight

      public int getDefaultRowHeight()
      Returns:
      The currently used height that is used to render fake rows scaled to match the NatTable scaling.
    • setDefaultRowHeight

      public void setDefaultRowHeight(int defaultRowHeight)
      Parameters:
      defaultRowHeight - The value that should be used to render fake rows. The value needs to be given in pixels, as the scaling calculation is done on rendering.
    • registerCommandHandler

      public void registerCommandHandler()
      Register ourself as ILayerCommandHandler for the RowSizeConfigurationCommand on the NatTable instance. This enables automatic updates of the defaultRowHeight if it is updated via RowSizeConfigurationCommand.
      Since:
      2.3
    • unregisterCommandHandler

      public void unregisterCommandHandler()
      Unregister ourself as ILayerCommandHandler for the RowSizeConfigurationCommand from the NatTable instance.
      Since:
      2.3
    • doCommand

      public boolean doCommand(ILayer targetLayer, RowSizeConfigurationCommand command)
      Specified by:
      doCommand in interface ILayerCommandHandler<RowSizeConfigurationCommand>
      Parameters:
      targetLayer - the target layer
      command - the command
      Returns:
      true if the command has been handled, false otherwise
      Since:
      2.3
    • getCommandClass

      public Class<RowSizeConfigurationCommand> getCommandClass()
      Specified by:
      getCommandClass in interface ILayerCommandHandler<RowSizeConfigurationCommand>