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
FieldsModifier and TypeFieldDescriptionprotected final org.eclipse.collections.api.map.primitive.MutableIntIntMapThe internal mapping of index to position values.static final Stringprotected final org.eclipse.collections.api.list.primitive.MutableIntListThe local cache of the row index order.Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
underlyingLayerFields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
commandHandlers, eventHandlers, eventHelperLock, layerPainterFields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionRowReorderLayer(IUniqueIndexLayer underlyingLayer) Creates aRowReorderLayeron top of the givenIUniqueIndexLayerand adds theDefaultRowReorderLayerConfiguration.RowReorderLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) Creates aRowReorderLayeron top of the givenIUniqueIndexLayer. -
Method Summary
Modifier and TypeMethodDescriptionbooleandoCommand(ILayerCommand command) Opportunity to respond to a command as it flows down the stack.intgetColumnPositionByIndex(int columnIndex) intintgetRowIndexByPosition(int rowPosition) Gets the underlying non-transformed row index for the given row position on this layer.int[]intgetRowPositionByIndex(int rowIndex) intgetRowPositionByY(int y) Returns the row position that contains the given y coordinate.intgetStartYOfRowPosition(int targetRowPosition) Returns the y offset in pixels of the given row.voidhandleLayerEvent(ILayerEvent event) Handle layer event notification.protected voidClear the caching of the starting Y positionsprotected booleanisRestoredStateValid(int[] newRowIndexOrder) Ensure that rows haven't changed in the underlying data sourcevoidloadState(String prefix, Properties properties) Underlying layers must load state first.intlocalToUnderlyingRowPosition(int localRowPosition) Convert a row position to the coordinates of the underlying layer.protected voidInitially populate the index order to the local cache.protected voidInitializes the internal index-position-mapping to reflect the internal row-index-order.protected voidLayers should use this method to register their command handlers and call it from their constructor.voidreorderMultipleRowIndexes(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.voidreorderMultipleRowIndexes(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.voidreorderMultipleRowPositions(int[] fromRowPositions, int toRowPosition) Reorders the rows at the given from positions to the TOP of the of the given to position.voidreorderMultipleRowPositions(int[] fromRowPositions, int toRowPosition, boolean reorderToTopEdge) Reorders the rows at the given from positions to the TOP of the of the given to position.voidreorderMultipleRowPositions(List<Integer> fromRowPositions, int toRowPosition) Reorders the rows at the given from positions to the TOP of the of the given to position.voidreorderMultipleRowPositions(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.voidreorderRowPosition(int fromRowPosition, int toRowPosition) Reorders the row at the given from position to the TOP of the of the given to position.voidreorderRowPosition(int fromRowPosition, int toRowPosition, boolean reorderToTopEdge) Reorders the row at the given from position to the TOP of the of the given to position.voidResets the reordering tracked by this layer.voidsaveState(String prefix, Properties properties) Saves the state to the given Properties using the specified prefix.voidsetReorderFromRowPosition(int fromRowPosition) Locally cache the position of the row that is currently reordered.intunderlyingToLocalRowPosition(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, underlyingToLocalColumnPositionsMethods 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, unregisterPersistableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 aRowReorderLayeron top of the givenIUniqueIndexLayerand adds theDefaultRowReorderLayerConfiguration.- Parameters:
underlyingLayer- The underlying layer.
-
RowReorderLayer
Creates aRowReorderLayeron top of the givenIUniqueIndexLayer.- Parameters:
underlyingLayer- The underlying layer.useDefaultConfiguration-trueto add theDefaultRowReorderLayerConfiguration
-
-
Method Details
-
handleLayerEvent
Description copied from class:AbstractLayerHandle 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:
handleLayerEventin interfaceILayerListener- Overrides:
handleLayerEventin classAbstractLayer- Parameters:
event- the event
-
doCommand
Description copied from interface:ILayerOpportunity 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:
doCommandin interfaceILayer- Overrides:
doCommandin classAbstractLayerTransform- Parameters:
command- The command to execute.- Returns:
trueif the command has been handled and was therefore consumed,falseotherwise.
-
registerCommandHandlers
protected void registerCommandHandlers()Description copied from class:AbstractLayerLayers 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:
registerCommandHandlersin classAbstractLayer
-
saveState
Description copied from interface:IPersistableSaves 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:
saveStatein interfaceIPersistable- Overrides:
saveStatein 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:AbstractLayerTransformUnderlying layers must load state first. If this is not done,IStructuralChangeEventfrom underlying layers will reset caches after state has been loaded- Specified by:
loadStatein interfaceIPersistable- Overrides:
loadStatein 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:
getColumnPositionByIndexin interfaceIUniqueIndexLayer
-
getRowPositionByY
public int getRowPositionByY(int y) Description copied from interface:ILayerReturns the row position that contains the given y coordinate.- Specified by:
getRowPositionByYin interfaceILayer- Overrides:
getRowPositionByYin 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:ILayerReturns the y offset in pixels of the given row.- Specified by:
getStartYOfRowPositionin interfaceILayer- Overrides:
getStartYOfRowPositionin 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:ILayerGets the underlying non-transformed row index for the given row position on this layer.- Specified by:
getRowIndexByPositionin interfaceILayer- Overrides:
getRowIndexByPositionin 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:
getRowPositionByIndexin interfaceIUniqueIndexLayer
-
localToUnderlyingRowPosition
public int localToUnderlyingRowPosition(int localRowPosition) Description copied from interface:ILayerConvert a row position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.- Specified by:
localToUnderlyingRowPositionin interfaceILayer- Overrides:
localToUnderlyingRowPositionin 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:ILayerTransforms the row position relative to the given underlying layer to this layer coordinates.- Specified by:
underlyingToLocalRowPositionin interfaceILayer- Overrides:
underlyingToLocalRowPositionin 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:ILayerTransforms the row position ranges relative to the given underlying layer to this layer coordinates.- Specified by:
underlyingToLocalRowPositionsin interfaceILayer- Overrides:
underlyingToLocalRowPositionsin 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
-