Class RowReorderLayer
java.lang.Object
org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer
- All Implemented Interfaces:
ILayer
,ILayerListener
,IUniqueIndexLayer
,IPersistable
- Direct Known Subclasses:
BaseRowReorderLayerFixture
,RowReorderLayerFixture
Layer that is used to add the functionality for row reordering.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.eclipse.collections.api.map.primitive.MutableIntIntMap
The internal mapping of index to position values.static final String
protected final org.eclipse.collections.api.list.primitive.MutableIntList
The local cache of the row index order.Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
underlyingLayer
Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
commandHandlers, eventHandlers, eventHelperLock, layerPainter
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
-
Constructor Summary
ConstructorDescriptionRowReorderLayer
(IUniqueIndexLayer underlyingLayer) Creates aRowReorderLayer
on top of the givenIUniqueIndexLayer
and adds theDefaultRowReorderLayerConfiguration
.RowReorderLayer
(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) Creates aRowReorderLayer
on top of the givenIUniqueIndexLayer
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
doCommand
(ILayerCommand command) Opportunity to respond to a command as it flows down the stack.int
getColumnPositionByIndex
(int columnIndex) int
int
getRowIndexByPosition
(int rowPosition) Gets the underlying non-transformed row index for the given row position on this layer.int[]
int
getRowPositionByIndex
(int rowIndex) int
getRowPositionByY
(int y) Returns the row position that contains the given y coordinate.int
getStartYOfRowPosition
(int targetRowPosition) Returns the y offset in pixels of the given row.void
handleLayerEvent
(ILayerEvent event) Handle layer event notification.protected void
Clear the caching of the starting Y positionsprotected boolean
isRestoredStateValid
(int[] newRowIndexOrder) Ensure that rows haven't changed in the underlying data sourcevoid
loadState
(String prefix, Properties properties) Underlying layers must load state first.int
localToUnderlyingRowPosition
(int localRowPosition) Convert a row position to the coordinates of the underlying layer.protected void
Initially populate the index order to the local cache.protected void
Initializes the internal index-position-mapping to reflect the internal row-index-order.protected void
Layers should use this method to register their command handlers and call it from their constructor.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 aRowReorderEvent
.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 aRowReorderEvent
.void
reorderMultipleRowPositions
(int[] fromRowPositions, int toRowPosition) Reorders the rows at the given from positions to the TOP of the of the given to position.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.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.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.void
reorderRowPosition
(int fromRowPosition, int toRowPosition) Reorders the row at the given from position to the TOP of the of the given to position.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.void
Resets the reordering tracked by this layer.void
saveState
(String prefix, Properties properties) Saves the state to the given Properties using the specified prefix.void
setReorderFromRowPosition
(int fromRowPosition) Locally cache the position of the row that is currently reordered.int
underlyingToLocalRowPosition
(ILayer sourceUnderlyingLayer, int underlyingRowPosition) Transforms the row position relative to the given underlying layer to this layer coordinates.underlyingToLocalRowPositions
(ILayer sourceUnderlyingLayer, Collection<Range> underlyingRowPositionRanges) Transforms the row position ranges relative to the given underlying layer to this layer coordinates.Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
configure, dispose, getCellByPosition, getCellPainter, getColumnCount, getColumnIndexByPosition, getColumnPositionByX, getColumnWidthByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getHeight, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRegionLabelsByXY, getRowCount, getRowHeightByPosition, getStartXOfColumnPosition, getUnderlyingLayer, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, isColumnPositionResizable, isDynamicSizeLayer, isRowPositionResizable, localToUnderlyingColumnPosition, setClientAreaProvider, setUnderlyingLayer, underlyingToLocalColumnPosition, underlyingToLocalColumnPositions
Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
addConfiguration, addLayerListener, clearConfiguration, fireLayerEvent, getBoundsByPosition, getClientAreaProvider, getConfigLabelAccumulator, getProvidedLabels, getRegionName, hasLayerListener, registerCommandHandler, registerEventHandler, registerPersistable, removeLayerListener, setConfigLabelAccumulator, setLayerPainter, setRegionName, toString, unregisterCommandHandler, unregisterEventHandler, unregisterPersistable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayer
addLayerListener, configure, dispose, fireLayerEvent, getBoundsByPosition, getCellByPosition, getCellPainter, getClientAreaProvider, getColumnCount, getColumnIndexByPosition, getColumnPositionByX, getColumnWidthByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getHeight, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getProvidedLabels, getRegionLabelsByXY, getRowCount, getRowHeightByPosition, getStartXOfColumnPosition, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, hasLayerListener, isColumnPositionResizable, isDynamicSizeLayer, isRowPositionResizable, localToUnderlyingColumnPosition, registerCommandHandler, registerPersistable, removeLayerListener, setClientAreaProvider, underlyingToLocalColumnPosition, underlyingToLocalColumnPositions, unregisterCommandHandler, unregisterPersistable
-
Field Details
-
PERSISTENCE_KEY_ROW_INDEX_ORDER
- See Also:
-
rowIndexOrder
protected final org.eclipse.collections.api.list.primitive.MutableIntList rowIndexOrderThe 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 indexPositionMappingThe internal mapping of index to position values. Used for performance reasons ingetColumnPositionByIndex(int)
becauseList.indexOf(Object)
doesn't scale well.- Since:
- 1.5
-
-
Constructor Details
-
RowReorderLayer
Creates aRowReorderLayer
on top of the givenIUniqueIndexLayer
and adds theDefaultRowReorderLayerConfiguration
.- Parameters:
underlyingLayer
- The underlying layer.
-
RowReorderLayer
Creates aRowReorderLayer
on top of the givenIUniqueIndexLayer
.- Parameters:
underlyingLayer
- The underlying layer.useDefaultConfiguration
-true
to add theDefaultRowReorderLayerConfiguration
-
-
Method Details
-
handleLayerEvent
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 callingsuper.fireLayerEvent(event)
- unless you plan to eat the event yourself.- Specified by:
handleLayerEvent
in interfaceILayerListener
- Overrides:
handleLayerEvent
in classAbstractLayer
- Parameters:
event
- the event
-
doCommand
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 interfaceILayer
- Overrides:
doCommand
in classAbstractLayerTransform
- 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 classAbstractLayer
-
saveState
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 interfaceIPersistable
- Overrides:
saveState
in classAbstractLayerTransform
- 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
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 interfaceIPersistable
- Overrides:
loadState
in classAbstractLayerTransform
- 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 interfaceIUniqueIndexLayer
-
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 interfaceILayer
- Overrides:
getRowPositionByY
in classAbstractLayerTransform
- 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 interfaceILayer
- Overrides:
getStartYOfRowPosition
in classAbstractLayerTransform
- 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
- 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 interfaceILayer
- Overrides:
getRowIndexByPosition
in classAbstractLayerTransform
- 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 interfaceIUniqueIndexLayer
-
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 interfaceILayer
- Overrides:
localToUnderlyingRowPosition
in classAbstractLayerTransform
- Parameters:
localRowPosition
- row position in local (the layer's own) coordinates- Returns:
- row position in the underlying layer's coordinates
-
underlyingToLocalRowPosition
Description copied from interface:ILayer
Transforms the row position relative to the given underlying layer to this layer coordinates.- Specified by:
underlyingToLocalRowPosition
in interfaceILayer
- Overrides:
underlyingToLocalRowPosition
in classAbstractLayerTransform
- 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 interfaceILayer
- Overrides:
underlyingToLocalRowPositions
in classAbstractLayerTransform
- 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 movetoRowPosition
- 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 movetoRowPosition
- position to move the row toreorderToTopEdge
- whether the move should be done above the given to position or not
-
reorderMultipleRowPositions
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 movetoRowPosition
- 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 movetoRowPosition
- 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 movetoRowPosition
- position to move the rows toreorderToTopEdge
- 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 movetoRowPosition
- position to move the rows toreorderToTopEdge
- 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 aRowReorderEvent
. 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 movetoRowPosition
- position to move the rows toreorderToTopEdge
- 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 aRowReorderEvent
. 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 movetoRowPosition
- position to move the rows toreorderToTopEdge
- 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
-