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
FieldsModifier and TypeFieldDescriptionprotected final org.eclipse.collections.api.list.primitive.MutableIntListThe internal cache of the column index order.protected final org.eclipse.collections.api.map.primitive.MutableIntIntMapThe internal mapping of index to position values.static final StringFields 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
ConstructorsConstructorDescriptionColumnReorderLayer(IUniqueIndexLayer underlyingLayer) Creates aColumnReorderLayeron top of the givenIUniqueIndexLayerand adds theDefaultColumnReorderLayerConfiguration.ColumnReorderLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) Creates aColumnReorderLayeron top of the givenIUniqueIndexLayer. -
Method Summary
Modifier and TypeMethodDescriptionbooleandoCommand(ILayerCommand command) Opportunity to respond to a command as it flows down the stack.intgetColumnIndexByPosition(int columnPosition) Gets the underlying non-transformed column index for the given column position on this layer.int[]intgetColumnPositionByIndex(int columnIndex) intgetColumnPositionByX(int x) Returns the column position that contains the given x coordinate.intReturns the column position from where the reorder process started.intgetRowPositionByIndex(int rowIndex) intgetStartXOfColumnPosition(int targetColumnPosition) Returns the x offset in pixels of the given column.voidhandleLayerEvent(ILayerEvent event) Handle layer event notification.protected voidClear the internal cache.protected booleanisRestoredStateValid(int[] newColumnIndexOrder) Ensure that columns haven't changed in the underlying data sourcevoidloadState(String prefix, Properties properties) Underlying layers must load state first.intlocalToUnderlyingColumnPosition(int localColumnPosition) Convert a column position to the coordinates of the underlying layer.protected voidInitialize the internal column index ordering from a clean state, which means it reflects the ordering from the underlying layer.protected voidInitializes the internal index-position-mapping to reflect the internal column-index-order.protected voidLayers should use this method to register their command handlers and call it from their constructor.voidreorderColumnPosition(int fromColumnPosition, int toColumnPosition) Moves the given from-column to the left edge of the column to move to.voidreorderColumnPosition(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-column to the specified edge of the column to move to and fires aColumnReorderEvent.voidreorderMultipleColumnIndexes(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.voidreorderMultipleColumnIndexes(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.voidreorderMultipleColumnPositions(int[] fromColumnPositions, int toColumnPosition) Reorders the given from-columns to the left edge of the column to move to.voidreorderMultipleColumnPositions(int[] fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) Reorders the given from-columns to the specified edge of the column to move to and fires aColumnReorderEvent.voidreorderMultipleColumnPositions(List<Integer> fromColumnPositions, int toColumnPosition) Reorders the given from-columns to the left edge of the column to move to.voidreorderMultipleColumnPositions(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.voidResets the reordering tracked by this layer.voidsaveState(String prefix, Properties properties) Saves the state to the given Properties using the specified prefix.voidsetReorderFromColumnPosition(int fromColumnPosition) Sets the column position where a reorder process started.intunderlyingToLocalColumnPosition(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, underlyingToLocalRowPositionsMethods 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, 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 aColumnReorderLayeron top of the givenIUniqueIndexLayerand adds theDefaultColumnReorderLayerConfiguration.- Parameters:
underlyingLayer- The underlying layer.
-
ColumnReorderLayer
Creates aColumnReorderLayeron top of the givenIUniqueIndexLayer.- Parameters:
underlyingLayer- The underlying layer.useDefaultConfiguration-trueto add theDefaultColumnReorderLayerConfiguration
-
-
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[] 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:ILayerGets the underlying non-transformed column index for the given column position on this layer.- Specified by:
getColumnIndexByPositionin interfaceILayer- Overrides:
getColumnIndexByPositionin 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:
getColumnPositionByIndexin interfaceIUniqueIndexLayer
-
localToUnderlyingColumnPosition
public int localToUnderlyingColumnPosition(int localColumnPosition) Description copied from interface:ILayerConvert a column position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.- Specified by:
localToUnderlyingColumnPositionin interfaceILayer- Overrides:
localToUnderlyingColumnPositionin 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:ILayerTransforms the column position relative to the given underlying layer to this layer coordinates.- Specified by:
underlyingToLocalColumnPositionin interfaceILayer- Overrides:
underlyingToLocalColumnPositionin 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:ILayerTransforms the column position ranges relative to the given underlying layer to this layer coordinates.- Specified by:
underlyingToLocalColumnPositionsin interfaceILayer- Overrides:
underlyingToLocalColumnPositionsin 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:ILayerReturns the column position that contains the given x coordinate.- Specified by:
getColumnPositionByXin interfaceILayer- Overrides:
getColumnPositionByXin 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:ILayerReturns the x offset in pixels of the given column.- Specified by:
getStartXOfColumnPositionin interfaceILayer- Overrides:
getStartXOfColumnPositionin 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:
getRowPositionByIndexin 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-trueif the column should be moved to the left of the given column to move to,falseif 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-trueif the columns should be moved to the left of the given column to move to,falseif 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-trueif the columns should be moved to the left of the given column to move to,falseif 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-trueif the columns should be moved to the left of the given column to move to,falseif 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-trueif the columns should be moved to the left of the given column to move to,falseif 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 theColumnReorderEndCommandHandlerwhich is triggered by theColumnReorderDragModewhen 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 theColumnReorderStartCommandwhich 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
-