Class RowReorderLayer

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

public class RowReorderLayer extends AbstractLayerTransform implements IUniqueIndexLayer
Layer that is used to add the functionality for row reordering.
See Also:
  • Field Details

    • PERSISTENCE_KEY_ROW_INDEX_ORDER

      public static final String PERSISTENCE_KEY_ROW_INDEX_ORDER
      See Also:
    • rowIndexOrder

      protected final org.eclipse.collections.api.list.primitive.MutableIntList rowIndexOrder
      The local cache of the row index order. Used to track the reordering performed by this layer. Position Y in the List contains the index of row at position Y.
    • indexPositionMapping

      protected final org.eclipse.collections.api.map.primitive.MutableIntIntMap indexPositionMapping
      The internal mapping of index to position values. Used for performance reasons in getColumnPositionByIndex(int) because List.indexOf(Object) doesn't scale well.
      Since:
      1.5
  • Constructor Details

  • Method Details

    • 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
    • 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.
    • registerCommandHandlers

      protected void registerCommandHandlers()
      Description copied from class: AbstractLayer
      Layers should use this method to register their command handlers and call it from their constructor. This allows easy overriding if required of command handlers
      Overrides:
      registerCommandHandlers in class AbstractLayer
    • saveState

      public void saveState(String prefix, Properties properties)
      Description copied from interface: IPersistable
      Saves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.
      Specified by:
      saveState in interface IPersistable
      Overrides:
      saveState in class AbstractLayerTransform
      Parameters:
      prefix - The prefix to use for the state keys. Is also used as the state configuration name.
      properties - The Properties instance to save the state to.
    • loadState

      public void loadState(String prefix, Properties properties)
      Description copied from class: AbstractLayerTransform
      Underlying layers must load state first. If this is not done, IStructuralChangeEvent from underlying layers will reset caches after state has been loaded
      Specified by:
      loadState in interface IPersistable
      Overrides:
      loadState in class AbstractLayerTransform
      Parameters:
      prefix - The prefix to use for the state keys. Is also used as the state configuration name.
      properties - The Properties instance to load the state from.
    • isRestoredStateValid

      protected boolean isRestoredStateValid(int[] newRowIndexOrder)
      Ensure that rows haven't changed in the underlying data source
      Parameters:
      newRowIndexOrder - restored from the properties file.
      Since:
      2.0
    • getColumnPositionByIndex

      public int getColumnPositionByIndex(int columnIndex)
      Specified by:
      getColumnPositionByIndex in interface IUniqueIndexLayer
    • 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
    • getStartYOfRowPosition

      public int getStartYOfRowPosition(int targetRowPosition)
      Description copied from interface: ILayer
      Returns the y offset in pixels of the given row.
      Specified by:
      getStartYOfRowPosition in interface ILayer
      Overrides:
      getStartYOfRowPosition in class AbstractLayerTransform
      Parameters:
      targetRowPosition - the row position in this layer
      Returns:
      the y offset of the row, or -1
    • populateIndexOrder

      protected void populateIndexOrder()
      Initially populate the index order to the local cache.
      Since:
      1.6
    • refreshIndexPositionMapping

      protected void refreshIndexPositionMapping()
      Initializes the internal index-position-mapping to reflect the internal row-index-order.
      Since:
      1.6
    • getRowIndexOrder

      public List<Integer> getRowIndexOrder()
      Returns:
      The local cache of the row index order.
    • getRowIndexOrderArray

      public int[] getRowIndexOrderArray()
      Returns:
      The local cache of the row index order.
      Since:
      2.0
    • 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.
    • getRowPositionByIndex

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

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

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

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

      public void reorderRowPosition(int fromRowPosition, int toRowPosition)
      Reorders the row at the given from position to the TOP of the of the given to position. Will calculate whether the move is done above the to position or not regarding the position in the NatTable.
      Parameters:
      fromRowPosition - row position to move
      toRowPosition - position to move the row to
    • reorderRowPosition

      public void reorderRowPosition(int fromRowPosition, int toRowPosition, boolean reorderToTopEdge)
      Reorders the row at the given from position to the TOP of the of the given to position.
      Parameters:
      fromRowPosition - row position to move
      toRowPosition - position to move the row to
      reorderToTopEdge - whether the move should be done above the given to position or not
    • reorderMultipleRowPositions

      public void reorderMultipleRowPositions(List<Integer> fromRowPositions, int toRowPosition)
      Reorders the rows at the given from positions to the TOP of the of the given to position. Will calculate whether the move is done above the to position or not regarding the position in the NatTable.
      Parameters:
      fromRowPositions - row positions to move
      toRowPosition - position to move the rows to
    • reorderMultipleRowPositions

      public void reorderMultipleRowPositions(int[] fromRowPositions, int toRowPosition)
      Reorders the rows at the given from positions to the TOP of the of the given to position. Will calculate whether the move is done above the to position or not regarding the position in the NatTable.
      Parameters:
      fromRowPositions - row positions to move
      toRowPosition - position to move the rows to
      Since:
      2.0
    • reorderMultipleRowPositions

      public void reorderMultipleRowPositions(List<Integer> fromRowPositions, int toRowPosition, boolean reorderToTopEdge)
      Reorders the rows at the given from positions to the TOP of the of the given to position.
      Parameters:
      fromRowPositions - row positions to move
      toRowPosition - position to move the rows to
      reorderToTopEdge - whether the move should be done above the given to position or not
    • reorderMultipleRowPositions

      public void reorderMultipleRowPositions(int[] fromRowPositions, int toRowPosition, boolean reorderToTopEdge)
      Reorders the rows at the given from positions to the TOP of the of the given to position.
      Parameters:
      fromRowPositions - row positions to move
      toRowPosition - position to move the rows to
      reorderToTopEdge - whether the move should be done above the given to position or not
      Since:
      2.0
    • reorderMultipleRowIndexes

      public void reorderMultipleRowIndexes(List<Integer> fromRowIndexes, int toRowPosition, boolean reorderToTopEdge)
      Reorders the given from-rows identified by index to the specified edge of the row to move to and fires a RowReorderEvent. This method can be used to reorder rows that are hidden in a higher level, e.g. to reorder a row group that has hidden rows.
      Parameters:
      fromRowIndexes - row indexes to move
      toRowPosition - position to move the rows to
      reorderToTopEdge - whether the move should be done above the given to position or not
      Since:
      1.6
    • reorderMultipleRowIndexes

      public void reorderMultipleRowIndexes(int[] fromRowIndexes, int toRowPosition, boolean reorderToTopEdge)
      Reorders the given from-rows identified by index to the specified edge of the row to move to and fires a RowReorderEvent. This method can be used to reorder rows that are hidden in a higher level, e.g. to reorder a row group that has hidden rows.
      Parameters:
      fromRowIndexes - row indexes to move
      toRowPosition - position to move the rows to
      reorderToTopEdge - whether the move should be done above the given to position or not
      Since:
      2.0
    • invalidateCache

      protected void invalidateCache()
      Clear the caching of the starting Y positions
      Since:
      1.6
    • getReorderFromRowPosition

      public int getReorderFromRowPosition()
      Returns:
      Local cached position of the row that is currently reordered.
    • setReorderFromRowPosition

      public void setReorderFromRowPosition(int fromRowPosition)
      Locally cache the position of the row that is currently reordered.
      Parameters:
      fromRowPosition - Position of the row that is currently reordered.
    • resetReorder

      public void resetReorder()
      Resets the reordering tracked by this layer.
      Since:
      1.6