Class FixedSummaryRowLayer

  • All Implemented Interfaces:
    ILayer, ILayerListener, IUniqueIndexLayer, IPersistable

    public class FixedSummaryRowLayer
    extends SummaryRowLayer
    This layer is a specialization of the SummaryRowLayer and is intended to be used in a composition below a GridLayer or a vertical composition like one with a column header and a body. It is horizontal dependent to the layer above and configured as a standalone summary row, which means that only the summary row is rendered.

    A typical composition to use this layer could look like this:

     +---------------+---------------+
    | CompositeLayer |
    |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
    | +---------------------------+ |
    | | GridLayer | |
    | +~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
    | | Corner | ColHeader | |
    | +-----------+---------------+ |
    | | RowHeader | Body | |
    | +-----------+---------------+ |
    +-------------------------------+
    | FixedSummaryRowLayer |
    +-------------------------------+

    It would be created by the following code:

          GridLayer gridLayer = new GridLayer(...);
          FixedSummaryRowLayer summaryRowLayer =
              new FixedSummaryRowLayer(bodyDataLayer, gridLayer, configRegistry);
    
          CompositeLayer composite = new CompositeLayer(1, 2);
          composite.setChildLayer("GRID", gridLayer, 0, 0);
          composite.setChildLayer(SUMMARY_REGION, summaryRowLayer, 0, 1);
    
          NatTable natTable = new NatTable(panel, composite);
     

    Note that the bodyDataLayer needs to be accessible somehow and the creation of the GridLayer is not specified in detail in the above example.

    Using this layer in a composition as shown above will result in a fixed summary row that doesn't scroll if the viewport is scrolled. This is different to the typical approach of adding the SummaryRowLayer on top of the body DataLayer where the summary row will scroll as part of the body region.

    • Field Detail

      • summaryRowLabel

        protected String summaryRowLabel
      • horizontalLayerDependency

        protected ILayer horizontalLayerDependency
        The layer to which fixed summary row should be horizontally dependent. Typically a GridLayer or the body layer stack in case of a simple vertical composition.
    • Constructor Detail

      • FixedSummaryRowLayer

        public FixedSummaryRowLayer​(IUniqueIndexLayer bodyDataLayer,
                                    ILayer horizontalLayerDependency,
                                    IConfigRegistry configRegistry)
        Creates a standalone FixedSummaryRowLayer that is horizontal dependent to the given layer and calculates the summary values from the given bodyDataLayer. It will register the default configurations and perform smooth value updates.

        Note:
        The FixedSummaryRowLayer constructor is setting a GridLineCellLayerPainter that is configured for clipTop to the given bodyDataLayer. This is necessary as otherwise the body region would paint over the summary row. In case you want to use a different ILayerPainter ensure to set it AFTER creating the FixedSummaryRowLayer.

        Parameters:
        bodyDataLayer - The underlying layer on which this layer should be build. Typically the DataLayer of the body region.
        horizontalLayerDependency - The layer that is above this layer in the surrounding composition. Typically a GridLayer.
        configRegistry - The ConfigRegistry for retrieving the ISummaryProvider per column.
      • FixedSummaryRowLayer

        public FixedSummaryRowLayer​(IUniqueIndexLayer bodyDataLayer,
                                    ILayer horizontalLayerDependency,
                                    IConfigRegistry configRegistry,
                                    boolean autoConfigure)
        Creates a standalone FixedSummaryRowLayer that is horizontal dependent to the given layer and calculates the summary values from the given bodyDataLayer. It will perform smooth value updates.

        Note:
        The FixedSummaryRowLayer constructor is setting a GridLineCellLayerPainter that is configured for clipTop to the given bodyDataLayer. This is necessary as otherwise the body region would paint over the summary row. In case you want to use a different ILayerPainter ensure to set it AFTER creating the FixedSummaryRowLayer.

        Parameters:
        bodyDataLayer - The underlying layer on which this layer should be build. Typically the DataLayer of the body region.
        horizontalLayerDependency - The layer that is above this layer in the surrounding composition. Typically a GridLayer.
        configRegistry - The ConfigRegistry for retrieving the ISummaryProvider per column.
        autoConfigure - true to use the DefaultSummaryRowConfiguration, false if a custom configuration will be set after the creation.
      • FixedSummaryRowLayer

        public FixedSummaryRowLayer​(IUniqueIndexLayer bodyDataLayer,
                                    ILayer horizontalLayerDependency,
                                    IConfigRegistry configRegistry,
                                    boolean smoothUpdates,
                                    boolean autoConfigure)
        Creates a standalone FixedSummaryRowLayer that is horizontal dependent to the given layer and calculates the summary values from the given bodyDataLayer.

        Note:
        The FixedSummaryRowLayer constructor is setting a GridLineCellLayerPainter that is configured for clipTop to the given bodyDataLayer. This is necessary as otherwise the body region would paint over the summary row. In case you want to use a different ILayerPainter ensure to set it AFTER creating the FixedSummaryRowLayer.

        Parameters:
        bodyDataLayer - The underlying layer on which this layer should be build. Typically the DataLayer of the body region.

        Note: When using a different layer than the DataLayer, e.g. the GlazedListsEventLayer to receive automatic updates, you need to ensure that the GridLineCellLayerPainter configured for clipping on top is set to the DataLayer for correct rendering of the fixed summary row.

        horizontalLayerDependency - The layer that is above this layer in the surrounding composition. Typically a GridLayer.
        configRegistry - The ConfigRegistry for retrieving the ISummaryProvider per column.
        smoothUpdates - true if the summary value updates should be performed smoothly, false if on re-calculation the value should be immediately shown as not calculated.
        autoConfigure - true to use the DefaultSummaryRowConfiguration, false if a custom configuration will be set after the creation.
    • Method Detail

      • doCommand

        public boolean doCommand​(ILayerCommand command)
        Description copied from interface: ILayer
        Opportunity to respond to a command as it flows down the stack. If the layer is not interested in the command it should allow the command to keep traveling down the stack.

        Note: Before the layer can process a command it must convert the command to its local coordinates using ILayerCommand.convertToTargetLayer(ILayer)

        Specified by:
        doCommand in interface ILayer
        Overrides:
        doCommand in class SummaryRowLayer
        Parameters:
        command - The command to execute.
        Returns:
        true if the command has been handled and was therefore consumed, false otherwise.
      • isBodyColumn

        protected boolean isBodyColumn​(int columnPosition)
        Parameters:
        columnPosition - The column position that should be checked.
        Returns:
        true if the column at the given position is a column of the body, false if it is a column of another region, e.g. the row header in a grid.
      • hasHorizontalCompositeDependency

        public boolean hasHorizontalCompositeDependency()
        Returns:
        true if the horizontal dependency is itself a composite that has an additional column, e.g. a GridLayer with a row header. false if the horizontal dependency is not a composite, e.g. the body layer stack.
      • setHorizontalCompositeDependency

        public void setHorizontalCompositeDependency​(boolean compositeDependency)
        Specify if the horizontal dependency is a CompositeLayer that adds additional columns.
        Parameters:
        compositeDependency - true to specify that the horizontal dependency is itself a composite that has an additional column, e.g. a GridLayer with a row header. false if the horizontal dependency is not a composite, e.g. the body layer stack.
      • getSummaryRowLabel

        public String getSummaryRowLabel()
        Returns:
        The label that is used as data value for the horizontal dependent cell to the row header column.
      • setSummaryRowLabel

        public void setSummaryRowLabel​(String summaryRowLabel)
        Parameters:
        summaryRowLabel - The label that should be used as data value for the horizontal dependent cell to the row header column.
      • getConfigLabelsByPositionWithoutTransformation

        protected LabelStack getConfigLabelsByPositionWithoutTransformation​(int columnPosition,
                                                                            int rowPosition)
        This implementation directly calls the super implementation. This is done to skip the column position-index transformation since it was done already.
        Overrides:
        getConfigLabelsByPositionWithoutTransformation in class SummaryRowLayer
        Parameters:
        columnPosition - The column position of the cell for which the config labels are requested. If transformations are necessary, this value should be already transformed.
        rowPosition - The row position of the cell for which the config labels are requested. If transformations are necessary, this value should be already transformed.
        Returns:
        The LabelStack for the cell at the given coordinates.
      • getConfigLabelsByPosition

        public LabelStack getConfigLabelsByPosition​(int columnPosition,
                                                    int rowPosition)
        Description copied from interface: ILayer
        Returns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of the IConfigRegistry.
        Specified by:
        getConfigLabelsByPosition in interface ILayer
        Overrides:
        getConfigLabelsByPosition in class SummaryRowLayer
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        The LabelStack with the config labels for the cell at the given coordinates.
      • getColumnIndexByPosition

        public int getColumnIndexByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Gets the underlying non-transformed column index for the given column position on this layer.
        Specified by:
        getColumnIndexByPosition in interface ILayer
        Overrides:
        getColumnIndexByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position relative to this layer.
        Returns:
        An underlying non-transformed column index, or -1 if the given column position does not exist within this coordinate system.
      • localToUnderlyingColumnPosition

        public int localToUnderlyingColumnPosition​(int localColumnPosition)
        Description copied from interface: ILayer
        Convert a column position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.
        Specified by:
        localToUnderlyingColumnPosition in interface ILayer
        Overrides:
        localToUnderlyingColumnPosition in class AbstractLayerTransform
        Parameters:
        localColumnPosition - column position in local (the layer's own) coordinates
        Returns:
        column position in the underlying layer's coordinates
      • underlyingToLocalColumnPosition

        public int underlyingToLocalColumnPosition​(ILayer sourceUnderlyingLayer,
                                                   int underlyingColumnPosition)
        Description copied from interface: ILayer
        Transforms the column position relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPosition in interface ILayer
        Overrides:
        underlyingToLocalColumnPosition in class AbstractLayerTransform
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column position matches.
        underlyingColumnPosition - The column position in the given underlying layer that should be converted to a local column position.
        Returns:
        The given column position transformed to be local to this layer.
      • underlyingToLocalColumnPositions

        public Collection<Range> underlyingToLocalColumnPositions​(ILayer sourceUnderlyingLayer,
                                                                  Collection<Range> underlyingColumnPositionRanges)
        Description copied from interface: ILayer
        Transforms the column position ranges relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPositions in interface ILayer
        Overrides:
        underlyingToLocalColumnPositions in class AbstractLayerTransform
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column positions match.
        underlyingColumnPositionRanges - The column position ranges relative to the given underlying layer that should be converted to local column positions.
        Returns:
        The given column position ranges transformed to this layer.
      • getWidth

        public int getWidth()
        Description copied from interface: ILayer
        Returns the total width in pixels of this layer.
        Specified by:
        getWidth in interface ILayer
        Overrides:
        getWidth in class AbstractLayerTransform
        Returns:
        The total width in pixels of this layer.
      • getColumnWidthByPosition

        public int getColumnWidthByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the width in pixels of the given column. The width of invisible and non-existing columns is 0.
        Specified by:
        getColumnWidthByPosition in interface ILayer
        Overrides:
        getColumnWidthByPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The width of the column.
      • isColumnPositionResizable

        public boolean isColumnPositionResizable​(int columnPosition)
        Description copied from interface: ILayer
        Check if the column at the given position is resizable.
        Specified by:
        isColumnPositionResizable in interface ILayer
        Overrides:
        isColumnPositionResizable in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position to check.
        Returns:
        true if the column is resizable, false if not.
      • getColumnPositionByX

        public int getColumnPositionByX​(int x)
        Description copied from interface: ILayer
        Returns the column position that contains the given x coordinate.
        Specified by:
        getColumnPositionByX in interface ILayer
        Overrides:
        getColumnPositionByX in class AbstractLayerTransform
        Parameters:
        x - A horizontal pixel location relative to the pixel boundary of this layer.
        Returns:
        A column position relative to the associated coordinate system, or -1 if there is no column that contains x.
      • getStartXOfColumnPosition

        public int getStartXOfColumnPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the x offset in pixels of the given column.
        Specified by:
        getStartXOfColumnPosition in interface ILayer
        Overrides:
        getStartXOfColumnPosition in class AbstractLayerTransform
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The x offset of the column, or -1.