Class SummaryRowLayer

All Implemented Interfaces:
ILayer, ILayerListener, IUniqueIndexLayer, IPersistable
Direct Known Subclasses:
FixedSummaryRowLayer

public class SummaryRowLayer extends AbstractLayerTransform implements IUniqueIndexLayer
Adds a summary row at the end. Uses ISummaryProvider to calculate the summaries for all columns.

This layer also adds the following labels:

  1. DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + column index
  2. DEFAULT_SUMMARY_ROW_CONFIG_LABEL to all cells in the row
Example: column with index 1 will have the DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 1 label applied. Styling and ISummaryProvider can be hooked up to these labels.
See Also:
  • Field Details

    • DEFAULT_SUMMARY_ROW_CONFIG_LABEL

      public static final String DEFAULT_SUMMARY_ROW_CONFIG_LABEL
      Label that gets attached to the LabelStack for every cell in the summary row.
      See Also:
    • DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX

      public static final String DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX
      Prefix of the labels that get attached to cells in the summary row. The complete label will consist of this prefix and the column index at the end of the label. This way every cell in the summary row can be accessed directly via label mechanism.
      See Also:
  • Constructor Details

    • SummaryRowLayer

      public SummaryRowLayer(IUniqueIndexLayer underlyingDataLayer, IConfigRegistry configRegistry)
      Creates a SummaryRowLayer on top of the given underlying layer. It uses smooth value updates as default.

      Note: This constructor will create the SummaryRowLayer by using the default configuration. The default configuration doesn't fit the needs so you usually will use your custom summary row configuration.

      Parameters:
      underlyingDataLayer - The underlying layer on which the SummaryRowLayer should be build.
      configRegistry - The ConfigRegistry for retrieving the ISummaryProvider per column.
      See Also:
    • SummaryRowLayer

      public SummaryRowLayer(IUniqueIndexLayer underlyingDataLayer, IConfigRegistry configRegistry, boolean autoConfigure)
      Creates a SummaryRowLayer on top of the given underlying layer. It uses smooth value updates as default.

      Note: This constructor will create the SummaryRowLayer by using the default configuration if the autoConfig parameter is set to true. The default configuration doesn't fit the needs so you usually will use your custom summary row configuration. When using a custom configuration you should use this constructor setting autoConfig to false. Otherwise you might get strange behaviour as the default configuration will be set additionally to your configuration.

      Parameters:
      underlyingDataLayer - The underlying layer on which the SummaryRowLayer should be build.
      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.
      See Also:
    • SummaryRowLayer

      public SummaryRowLayer(IUniqueIndexLayer underlyingDataLayer, IConfigRegistry configRegistry, boolean smoothUpdates, boolean autoConfigure)
      Creates a SummaryRowLayer on top of the given underlying layer.

      Note: This constructor will create the SummaryRowLayer by using the default configuration if the autoConfig parameter is set to true. The default configuration doesn't fit the needs so you usually will use your custom summary row configuration. When using a custom configuration you should use this constructor setting autoConfig to false. Otherwise you might get strange behaviour as the default configuration will be set additionally to your configuration.

      Parameters:
      underlyingDataLayer - The underlying layer on which the SummaryRowLayer should be build.
      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.
      See Also:
  • Method Details

    • getDataValueByPosition

      public Object getDataValueByPosition(int columnPosition, int rowPosition)
      Calculates the summary for the column using the ISummaryProvider from the IConfigRegistry. In order to prevent the table from freezing (for large data sets), the summary is calculated in a separate Thread. While summary is being calculated ISummaryProvider.DEFAULT_SUMMARY_VALUE is returned.

      NOTE: Since this is a IUniqueIndexLayer sitting close to the DataLayer, columnPosition == columnIndex

      Specified by:
      getDataValueByPosition in interface ILayer
      Overrides:
      getDataValueByPosition in class AbstractLayerTransform
      Parameters:
      columnPosition - The column position of the cell.
      rowPosition - The row position of the cell.
      Returns:
      The data value for the cell at the given coordinates.
    • isSummaryRowPosition

      public boolean isSummaryRowPosition(int rowPosition)
      Checks if the given row position is the position of the summary row.
      Parameters:
      rowPosition - The row position to check.
      Returns:
      true if the given row position is the summary row position.
      Since:
      1.6
    • getSummaryRowPosition

      public int getSummaryRowPosition()
      Get the position of the summary row in this layer.
      Returns:
      The position of the summary row. Typically rowCount - 1.
      Since:
      1.6
    • 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 AbstractLayerTransform
      Parameters:
      command - The command to execute.
      Returns:
      true if the command has been handled and was therefore consumed, false otherwise.
    • handleLayerEvent

      public void handleLayerEvent(ILayerEvent event)
      Description copied from class: AbstractLayer
      Handle layer event notification. Convert it to your context and propagate UP. If you override this method you MUST NOT FORGET to raise the event up the layer stack by calling super.fireLayerEvent(event) - unless you plan to eat the event yourself.
      Specified by:
      handleLayerEvent in interface ILayerListener
      Overrides:
      handleLayerEvent in class AbstractLayer
      Parameters:
      event - the event
    • clearCache

      public void clearCache()
      Clear the internal cache to trigger new calculations.

      Usually it is not necessary to call this method manually. But for certain use cases it might be useful, e.g. changing the summary provider implementation at runtime.

      See Also:
    • killCache

      public void killCache()
      Clears all values in the internal cache to trigger new calculations. This will also clear all values in the cache copy and will result in rendering like there was never a summary value calculated before.

      Usually it is not necessary to call this method manually. But for certain use cases it might be useful, e.g. changing the summary provider implementation at runtime.

      See Also:
    • getConfigLabelsByPositionWithoutTransformation

      protected LabelStack getConfigLabelsByPositionWithoutTransformation(int columnPosition, int rowPosition)
      This method is a wrapper for calling getConfigLabelsByPosition(int, int). It is needed because sub-classes of the SummaryRowLayer might perform column position-index transformations, which would be executed again if the call for config labels is nested, e.g. in calculateNewSummaryValue(int, boolean). By providing and using this implementation, sub-classes that perform position-index transformations are able to implement this method by directly accessing the super implementation.
      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 AbstractLayerTransform
      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.
    • getCellByPosition

      public ILayerCell getCellByPosition(int columnPosition, int rowPosition)
      Description copied from interface: ILayer
      Returns the cell for the given coordinates on this layer.
      Specified by:
      getCellByPosition in interface ILayer
      Overrides:
      getCellByPosition in class AbstractLayerTransform
      Parameters:
      columnPosition - The column position of the requested cell.
      rowPosition - The row position of the requested cell.
      Returns:
      The ILayerCell for the given coordinates in this layer or null if the coordinates are invalid on this layer.
    • getHeight

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

      public int getPreferredHeight()
      Specified by:
      getPreferredHeight in interface ILayer
      Overrides:
      getPreferredHeight in class AbstractLayerTransform
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface ILayer
      Overrides:
      getRowCount in class AbstractLayerTransform
      Returns:
      The number of rows in this layer.
    • getPreferredRowCount

      public int getPreferredRowCount()
      Specified by:
      getPreferredRowCount in interface ILayer
      Overrides:
      getPreferredRowCount in class AbstractLayerTransform
    • getRowIndexByPosition

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

      public int getRowPositionByY(int y)
      Description copied from interface: ILayer
      Returns the row position that contains the given y coordinate.
      Specified by:
      getRowPositionByY in interface ILayer
      Overrides:
      getRowPositionByY in class AbstractLayerTransform
      Parameters:
      y - a vertical pixel location relative to the pixel boundary of this layer
      Returns:
      a row position relative to the associated coordinate system, or -1 if there is no row that contains y
    • getRowHeightByPosition

      public int getRowHeightByPosition(int rowPosition)
      Description copied from interface: ILayer
      Returns the height in pixels of the given row. The height of invisible and non-existing rows is 0.
      Specified by:
      getRowHeightByPosition in interface ILayer
      Overrides:
      getRowHeightByPosition in class AbstractLayerTransform
      Parameters:
      rowPosition - The row position in this layer.
      Returns:
      The height of the row.
    • getRowPositionByIndex

      public int getRowPositionByIndex(int rowIndex)
      Specified by:
      getRowPositionByIndex in interface IUniqueIndexLayer
    • getColumnPositionByIndex

      public int getColumnPositionByIndex(int columnIndex)
      Specified by:
      getColumnPositionByIndex in interface IUniqueIndexLayer
    • isStandalone

      public boolean isStandalone()
      Returns:
      true if the summary row is rendered standalone, false if it is rendered below the underlying layer.
    • setStandalone

      public void setStandalone(boolean standalone)
      Configure whether the summary row should be rendered below the underlying layer (false) or if it should be rendered standalone in a separate region of a composite (true).
      Parameters:
      standalone - Whether the summary row should be rendered standalone or below the underlying layer.
    • getValueCache

      public ICalculatedValueCache getValueCache()
      Returns:
      The ICalculatedValueCache that contains the summary values and performs summary calculation in background processes if necessary.
      Since:
      1.3
    • setValueCache

      public void setValueCache(ICalculatedValueCache valueCache)
      Set the ICalculatedValueCache that should be used internally to calculate the summary values in a background thread and cache the results.

      Note: By default the CalculatedValueCache is used. Be sure you know what you are doing when you are trying to exchange the implementation.

      Parameters:
      valueCache - The ICalculatedValueCache that contains the summary values and performs summary calculation in background processes if necessary.
      Since:
      1.3
    • getUnderlyingLayersByColumnPosition

      public Collection<ILayer> getUnderlyingLayersByColumnPosition(int columnPosition)
      Description copied from interface: ILayer
      Returns the layers that are directly below this layer for the given column position. For simple layers this collection will typically only have one entry. Layer compositions might return multiple values, e.g. in a default grid there will be 2 layers in the collection as there are two layers involved in a column.
      Specified by:
      getUnderlyingLayersByColumnPosition in interface ILayer
      Overrides:
      getUnderlyingLayersByColumnPosition in class AbstractLayerTransform
      Parameters:
      columnPosition - The column position for which the underlying layers are requested.
      Returns:
      The layers that are directly below this layer for the given column position or null if this layer has no underlying layers.
    • getUnderlyingLayersByRowPosition

      public Collection<ILayer> getUnderlyingLayersByRowPosition(int rowPosition)
      Description copied from interface: ILayer
      Returns the layers that are directly below this layer for the given row position. For simple layers this collection will typically only have one entry. Layer compositions might return multiple values, e.g. in a default grid there will be 2 layers in the collection as there are two layers involved in a row.
      Specified by:
      getUnderlyingLayersByRowPosition in interface ILayer
      Overrides:
      getUnderlyingLayersByRowPosition in class AbstractLayerTransform
      Parameters:
      rowPosition - The row position for which the underlying layers are requested.
      Returns:
      The layers that are directly below this layer for the given row position or null if this layer has no underlying layers.
    • getUnderlyingLayerByPosition

      public ILayer getUnderlyingLayerByPosition(int columnPosition, int rowPosition)
      Description copied from interface: ILayer
      Returns the layer that is directly below this layer for the given cell coordinate.
      Specified by:
      getUnderlyingLayerByPosition in interface ILayer
      Overrides:
      getUnderlyingLayerByPosition in class AbstractLayerTransform
      Parameters:
      columnPosition - The column position for which the underlying layer is requested.
      rowPosition - The row position for which the underlying layer is requested.
      Returns:
      The layer that is directly below this layer for the given cell coordinates or null if this layer has no underlying layers.
    • getProvidedLabels

      public Collection<String> getProvidedLabels()
      Specified by:
      getProvidedLabels in interface ILayer
      Overrides:
      getProvidedLabels in class AbstractLayer
      Returns:
      The collection of labels that are provided by this layer.
      Since:
      1.4