Class ColumnReorderLayer
java.lang.Object
org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer
- All Implemented Interfaces:
ILayer
,ILayerListener
,IUniqueIndexLayer
,IPersistable
- Direct Known Subclasses:
BaseColumnReorderLayerFixture
,ColumnReorderLayerFixture
Layer that is used to add the functionality for column reordering.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.eclipse.collections.api.list.primitive.MutableIntList
The internal cache of the column index order.protected final org.eclipse.collections.api.map.primitive.MutableIntIntMap
The internal mapping of index to position values.static final String
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
ConstructorDescriptionColumnReorderLayer
(IUniqueIndexLayer underlyingLayer) Creates aColumnReorderLayer
on top of the givenIUniqueIndexLayer
and adds theDefaultColumnReorderLayerConfiguration
.ColumnReorderLayer
(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) Creates aColumnReorderLayer
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
getColumnIndexByPosition
(int columnPosition) Gets the underlying non-transformed column index for the given column position on this layer.int[]
int
getColumnPositionByIndex
(int columnIndex) int
getColumnPositionByX
(int x) Returns the column position that contains the given x coordinate.int
Returns the column position from where the reorder process started.int
getRowPositionByIndex
(int rowIndex) int
getStartXOfColumnPosition
(int targetColumnPosition) Returns the x offset in pixels of the given column.void
handleLayerEvent
(ILayerEvent event) Handle layer event notification.protected void
Clear the internal cache.protected boolean
isRestoredStateValid
(int[] newColumnIndexOrder) Ensure that columns haven't changed in the underlying data sourcevoid
loadState
(String prefix, Properties properties) Underlying layers must load state first.int
localToUnderlyingColumnPosition
(int localColumnPosition) Convert a column position to the coordinates of the underlying layer.protected void
Initialize the internal column index ordering from a clean state, which means it reflects the ordering from the underlying layer.protected void
Initializes the internal index-position-mapping to reflect the internal column-index-order.protected void
Layers should use this method to register their command handlers and call it from their constructor.void
reorderColumnPosition
(int fromColumnPosition, int toColumnPosition) Moves the given from-column to the left edge of the column to move to.void
reorderColumnPosition
(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-column to the specified edge of the column to move to and fires aColumnReorderEvent
.void
reorderMultipleColumnIndexes
(int[] fromColumnIndexes, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns identified by index to the specified edge of the column to move to and fires aColumnReorderEvent
.void
reorderMultipleColumnIndexes
(List<Integer> fromColumnIndexes, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns identified by index to the specified edge of the column to move to and fires aColumnReorderEvent
.void
reorderMultipleColumnPositions
(int[] fromColumnPositions, int toColumnPosition) Reorders the given from-columns to the left edge of the column to move to.void
reorderMultipleColumnPositions
(int[] fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns to the specified edge of the column to move to and fires aColumnReorderEvent
.void
reorderMultipleColumnPositions
(List<Integer> fromColumnPositions, int toColumnPosition) Reorders the given from-columns to the left edge of the column to move to.void
reorderMultipleColumnPositions
(List<Integer> fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns to the specified edge of the column to move to and fires aColumnReorderEvent
.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
setReorderFromColumnPosition
(int fromColumnPosition) Sets the column position where a reorder process started.int
underlyingToLocalColumnPosition
(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) Transforms the column position relative to the given underlying layer to this layer coordinates.underlyingToLocalColumnPositions
(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) Transforms the column 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, getColumnWidthByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getHeight, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRegionLabelsByXY, getRowCount, getRowHeightByPosition, getRowIndexByPosition, getRowPositionByY, getStartYOfRowPosition, getUnderlyingLayer, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, isColumnPositionResizable, isDynamicSizeLayer, isRowPositionResizable, localToUnderlyingRowPosition, setClientAreaProvider, setUnderlyingLayer, underlyingToLocalRowPosition, underlyingToLocalRowPositions
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, getColumnWidthByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getHeight, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getProvidedLabels, getRegionLabelsByXY, getRowCount, getRowHeightByPosition, getRowIndexByPosition, getRowPositionByY, getStartYOfRowPosition, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, hasLayerListener, isColumnPositionResizable, isDynamicSizeLayer, isRowPositionResizable, localToUnderlyingRowPosition, registerCommandHandler, registerPersistable, removeLayerListener, setClientAreaProvider, underlyingToLocalRowPosition, underlyingToLocalRowPositions, unregisterCommandHandler, unregisterPersistable
-
Field Details
-
PERSISTENCE_KEY_COLUMN_INDEX_ORDER
- See Also:
-
columnIndexOrder
protected final org.eclipse.collections.api.list.primitive.MutableIntList columnIndexOrderThe internal cache of the column index order. Used to track the reordering performed by this layer. Position X in the List contains the index of column at position X. -
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
-
ColumnReorderLayer
Creates aColumnReorderLayer
on top of the givenIUniqueIndexLayer
and adds theDefaultColumnReorderLayerConfiguration
.- Parameters:
underlyingLayer
- The underlying layer.
-
ColumnReorderLayer
Creates aColumnReorderLayer
on top of the givenIUniqueIndexLayer
.- Parameters:
underlyingLayer
- The underlying layer.useDefaultConfiguration
-true
to add theDefaultColumnReorderLayerConfiguration
-
-
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[] newColumnIndexOrder) Ensure that columns haven't changed in the underlying data source- Parameters:
newColumnIndexOrder
- restored from the properties file.- Since:
- 2.0
-
getColumnIndexOrder
- Returns:
- the internal kept ordering of column indexes.
-
getColumnIndexOrderArray
public int[] getColumnIndexOrderArray()- Returns:
- the internal kept ordering of column indexes.
- Since:
- 2.0
-
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 interfaceILayer
- Overrides:
getColumnIndexByPosition
in classAbstractLayerTransform
- 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.
-
getColumnPositionByIndex
public int getColumnPositionByIndex(int columnIndex) - Specified by:
getColumnPositionByIndex
in interfaceIUniqueIndexLayer
-
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 interfaceILayer
- Overrides:
localToUnderlyingColumnPosition
in classAbstractLayerTransform
- 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 interfaceILayer
- Overrides:
underlyingToLocalColumnPosition
in classAbstractLayerTransform
- 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 interfaceILayer
- Overrides:
underlyingToLocalColumnPositions
in classAbstractLayerTransform
- 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.
-
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 interfaceILayer
- Overrides:
getColumnPositionByX
in classAbstractLayerTransform
- 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 targetColumnPosition) Description copied from interface:ILayer
Returns the x offset in pixels of the given column.- Specified by:
getStartXOfColumnPosition
in interfaceILayer
- Overrides:
getStartXOfColumnPosition
in classAbstractLayerTransform
- Parameters:
targetColumnPosition
- The column position in this layer.- Returns:
- The x offset of the column, or -1.
-
populateIndexOrder
protected void populateIndexOrder()Initialize the internal column index ordering from a clean state, which means it reflects the ordering from the underlying layer.- Since:
- 1.6
-
refreshIndexPositionMapping
protected void refreshIndexPositionMapping()Initializes the internal index-position-mapping to reflect the internal column-index-order.- Since:
- 1.6
-
getRowPositionByIndex
public int getRowPositionByIndex(int rowIndex) - Specified by:
getRowPositionByIndex
in interfaceIUniqueIndexLayer
-
reorderColumnPosition
public void reorderColumnPosition(int fromColumnPosition, int toColumnPosition) Moves the given from-column to the left edge of the column to move to.- Parameters:
fromColumnPosition
- column position to movetoColumnPosition
- position to move the column to
-
reorderColumnPosition
public void reorderColumnPosition(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-column to the specified edge of the column to move to and fires aColumnReorderEvent
.- Parameters:
fromColumnPosition
- column position to movetoColumnPosition
- position to move the column toreorderToLeftEdge
-true
if the column should be moved to the left of the given column to move to,false
if it should be positioned to the right
-
reorderMultipleColumnPositions
Reorders the given from-columns to the left edge of the column to move to.- Parameters:
fromColumnPositions
- column positions to movetoColumnPosition
- position to move the columns to
-
reorderMultipleColumnPositions
public void reorderMultipleColumnPositions(int[] fromColumnPositions, int toColumnPosition) Reorders the given from-columns to the left edge of the column to move to.- Parameters:
fromColumnPositions
- column positions to movetoColumnPosition
- position to move the columns to- Since:
- 2.0
-
reorderMultipleColumnPositions
public void reorderMultipleColumnPositions(List<Integer> fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns to the specified edge of the column to move to and fires aColumnReorderEvent
.- Parameters:
fromColumnPositions
- column positions to movetoColumnPosition
- position to move the columns toreorderToLeftEdge
-true
if the columns should be moved to the left of the given column to move to,false
if they should be positioned to the right
-
reorderMultipleColumnPositions
public void reorderMultipleColumnPositions(int[] fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns to the specified edge of the column to move to and fires aColumnReorderEvent
.- Parameters:
fromColumnPositions
- column positions to movetoColumnPosition
- position to move the columns toreorderToLeftEdge
-true
if the columns should be moved to the left of the given column to move to,false
if they should be positioned to the right- Since:
- 2.0
-
reorderMultipleColumnIndexes
public void reorderMultipleColumnIndexes(List<Integer> fromColumnIndexes, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns identified by index to the specified edge of the column to move to and fires aColumnReorderEvent
. This method can be used to reorder columns that are hidden in a higher level, e.g. to reorder a column group that has hidden columns.- Parameters:
fromColumnIndexes
- column indexes to movetoColumnPosition
- position to move the columns toreorderToLeftEdge
-true
if the columns should be moved to the left of the given column to move to,false
if they should be positioned to the right- Since:
- 1.6
-
reorderMultipleColumnIndexes
public void reorderMultipleColumnIndexes(int[] fromColumnIndexes, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns identified by index to the specified edge of the column to move to and fires aColumnReorderEvent
. This method can be used to reorder columns that are hidden in a higher level, e.g. to reorder a column group that has hidden columns.- Parameters:
fromColumnIndexes
- column indexes to movetoColumnPosition
- position to move the columns toreorderToLeftEdge
-true
if the columns should be moved to the left of the given column to move to,false
if they should be positioned to the right- Since:
- 2.0
-
invalidateCache
protected void invalidateCache()Clear the internal cache.- Since:
- 1.6
-
getReorderFromColumnPosition
public int getReorderFromColumnPosition()Returns the column position from where the reorder process started. Used by theColumnReorderEndCommandHandler
which is triggered by theColumnReorderDragMode
when dragging a column is finished.- Returns:
- The column position where the reorder started.
-
setReorderFromColumnPosition
public void setReorderFromColumnPosition(int fromColumnPosition) Sets the column position where a reorder process started. Typically done by calling theColumnReorderStartCommand
which is triggered by theColumnReorderDragMode
.- Parameters:
fromColumnPosition
- The column position where the reorder started.
-
resetReorder
public void resetReorder()Resets the reordering tracked by this layer.- Since:
- 1.6
-