Class SelectionLayer
java.lang.Object
org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
org.eclipse.nebula.widgets.nattable.layer.AbstractIndexLayerTransform
org.eclipse.nebula.widgets.nattable.selection.SelectionLayer
- All Implemented Interfaces:
ILayer,ILayerListener,IUniqueIndexLayer,IPersistable
Enables selection of column, rows, cells etc. on the table. Also responds to
UI bindings by changing the current selection. Internally it uses the
ISelectionModel to track the selection state.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PositionCoordinateThe bottom right cell in a contiguous selection ornullif there is no selection or the selection is not contiguous.protected org.eclipse.swt.graphics.RectangleThe region selected via fill handle to extend the current selection for triggering a fill action.protected final PositionCoordinateprotected org.eclipse.swt.graphics.Rectanglestatic final intstatic final intprotected SelectCellCommandHandlerprotected SelectColumnCommandHandlerprotected final PositionCoordinateprotected ISelectionModelprotected SelectRowCommandHandlerprotected IUniqueIndexLayerFields 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
ConstructorsConstructorDescriptionSelectionLayer(IUniqueIndexLayer underlyingLayer) SelectionLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) SelectionLayer(IUniqueIndexLayer underlyingLayer, ISelectionModel selectionModel, boolean useDefaultConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSelection(org.eclipse.swt.graphics.Rectangle selection) booleanallCellsSelectedInRegion(org.eclipse.swt.graphics.Rectangle region) Test if all cells in a given region are selected.voidclear()voidclear(boolean fireSelectionEvent) voidclearSelection(int columnPosition, int rowPosition) voidclearSelection(org.eclipse.swt.graphics.Rectangle selection) booleandoCommand(ILayerCommand command) Opportunity to respond to a command as it flows down the stack.voidfireCellSelectionEvent(int columnPosition, int rowPosition, boolean forcingEntireCellIntoViewport, boolean withShiftMask, boolean withControlMask) protected PositionCoordinategetCellPositionToMoveFrom(boolean withShiftMask, boolean withControlMask) When extending a selected area via modifier keys, we need to move from the last selected cell.getConfigLabelsByPosition(int columnPosition, int rowPosition) Returns the config labels for the cell at the given coordinates.getDisplayModeByPosition(int columnPosition, int rowPosition) Returns the activeDisplayModefor the cell at the given coordinates.org.eclipse.swt.graphics.RectangleReturns the region that is currently selected via fill handle to extend the current active selection.int[]int[]org.eclipse.swt.graphics.RectangleRetrieves the ILayerCells out of the SelectionLayer that are currently marked as selected in the SelectionModel.int[]intprotected booleanhandleColumnHideCommand(ColumnHideCommand command) Will check if there are fully selected column positions.protected booleanWill check if there are fully selected column positions.protected booleanPrevious to processing the givenMultiColumnHideCommanddown the layer stack, the fully selected column positions selection state will be cleared.protected booleanPrevious to processing the givenMultiRowHideCommanddown the layer stack, the fully selected row positions selection state will be cleared.protected booleanhandleRowHideCommand(RowHideCommand command) Will check if there are fully selected row positions.protected booleanFirst inspects the cell at the position contained in theRowPositionHideCommandand calculates all rows for that cell, taking the spanning into account.protected booleanhandleRowResizeCommand(RowResizeCommand command) Will check if there are fully selected row positions.booleanbooleanbooleanisCellPositionSelected(int columnPosition, int rowPosition) booleanisColumnPositionFullySelected(int columnPosition) booleanisColumnPositionSelected(int columnPosition) booleanisRowPositionFullySelected(int rowPosition) booleanisRowPositionSelected(int rowPosition) voidMarks the bottom right cell in a contiguous selection within theSelectionLayer.voidmoveSelectionAnchor(int startColumnPositionInRegion, int startRowPosition) protected voidLayers should use this method to register their command handlers and call it from their constructor.voidvoidselectCell(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) Calculates the selected cells - taking into account Shift and Ctrl key presses.voidselectColumn(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) voidselectRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight) voidselectRow(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) voidsetFillHandleRegion(org.eclipse.swt.graphics.Rectangle region) Set the region that is currently selected via fill handle to extend the current active selection for triggering a fill action.voidsetLastSelectedCell(int columnPosition, int rowPosition) protected voidsetLastSelectedRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight) protected voidsetLastSelectedRegion(org.eclipse.swt.graphics.Rectangle region) voidsetSelectedCell(int columnPosition, int rowPosition) voidsetSelectionModel(ISelectionModel selectionModel) Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractIndexLayerTransform
configure, dispose, getCellByPosition, getCellPainter, getColumnCount, getColumnIndexByPosition, getColumnPositionByIndex, getColumnPositionByX, getColumnWidthByPosition, getDataValueByPosition, getHeight, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRegionLabelsByXY, getRowCount, getRowHeightByPosition, getRowIndexByPosition, getRowPositionByIndex, getRowPositionByY, getStartXOfColumnPosition, getStartYOfRowPosition, getUnderlyingLayer, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, isColumnPositionResizable, isDynamicSizeLayer, isRowPositionResizable, loadState, localToUnderlyingColumnPosition, localToUnderlyingRowPosition, saveState, setClientAreaProvider, setUnderlyingLayer, underlyingToLocalColumnPosition, underlyingToLocalColumnPositions, underlyingToLocalRowPosition, underlyingToLocalRowPositionsMethods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
addConfiguration, addLayerListener, clearConfiguration, fireLayerEvent, getBoundsByPosition, getClientAreaProvider, getConfigLabelAccumulator, getRegionName, handleLayerEvent, 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, fireLayerEvent, getBoundsByPosition, getClientAreaProvider, hasLayerListener, registerCommandHandler, registerPersistable, removeLayerListener, unregisterCommandHandler, unregisterPersistableMethods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayerListener
handleLayerEvent
-
Field Details
-
MOVE_ALL
public static final int MOVE_ALL- See Also:
-
NO_SELECTION
public static final int NO_SELECTION- See Also:
-
selectionModel
-
underlyingLayer
-
lastSelectedCell
-
selectionAnchor
-
lastSelectedRegion
protected org.eclipse.swt.graphics.Rectangle lastSelectedRegion -
fillHandleRegion
protected org.eclipse.swt.graphics.Rectangle fillHandleRegionThe region selected via fill handle to extend the current selection for triggering a fill action. Can benull.- Since:
- 1.4
-
bottomRightInSelection
The bottom right cell in a contiguous selection ornullif there is no selection or the selection is not contiguous. Needed to identify the cell on which the fill handle should be rendered.- Since:
- 1.4
-
selectRowCommandHandler
-
selectCellCommandHandler
-
selectColumnCommandHandler
-
-
Constructor Details
-
SelectionLayer
-
SelectionLayer
-
SelectionLayer
public SelectionLayer(IUniqueIndexLayer underlyingLayer, ISelectionModel selectionModel, boolean useDefaultConfiguration)
-
-
Method Details
-
getSelectionModel
-
setSelectionModel
-
addSelection
public void addSelection(org.eclipse.swt.graphics.Rectangle selection) -
clear
public void clear() -
clear
public void clear(boolean fireSelectionEvent) -
clearSelection
public void clearSelection(int columnPosition, int rowPosition) -
clearSelection
public void clearSelection(org.eclipse.swt.graphics.Rectangle selection) -
selectAll
public void selectAll() -
isCellPositionSelected
public boolean isCellPositionSelected(int columnPosition, int rowPosition) -
setSelectedCell
public void setSelectedCell(int columnPosition, int rowPosition) -
getCellPositionToMoveFrom
protected PositionCoordinate getCellPositionToMoveFrom(boolean withShiftMask, boolean withControlMask) When extending a selected area via modifier keys, we need to move from the last selected cell. If we are not extending a selection we need to move from the selection anchor.- Parameters:
withShiftMask-trueif the shift mask is active,falseif not.withControlMask-trueif the shift mask is active,falseif not.- Returns:
- The cell position coordinate related to this SelectionLayer, from where to move from.
-
getSelectedCellPositions
-
getSelectedCells
Retrieves the ILayerCells out of the SelectionLayer that are currently marked as selected in the SelectionModel. Takes spanning into account.- Returns:
- The selected ILayerCells
-
selectCell
public void selectCell(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) Calculates the selected cells - taking into account Shift and Ctrl key presses. -
selectRegion
public void selectRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight) -
setLastSelectedRegion
protected void setLastSelectedRegion(org.eclipse.swt.graphics.Rectangle region) -
setLastSelectedRegion
protected void setLastSelectedRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight) -
getSelectionAnchor
-
moveSelectionAnchor
public void moveSelectionAnchor(int startColumnPositionInRegion, int startRowPosition) -
getLastSelectedCellPosition
-
allCellsSelectedInRegion
public boolean allCellsSelectedInRegion(org.eclipse.swt.graphics.Rectangle region) Test if all cells in a given region are selected.- Parameters:
region- The region that should be checked.- Returns:
trueif all cells in a region are selected,falseif at least one cell in the region is not selected.- Since:
- 1.6
-
setLastSelectedCell
public void setLastSelectedCell(int columnPosition, int rowPosition) -
getLastSelectedRegion
public org.eclipse.swt.graphics.Rectangle getLastSelectedRegion() -
hasColumnSelection
public boolean hasColumnSelection() -
getSelectedColumnPositions
public int[] getSelectedColumnPositions() -
isColumnPositionSelected
public boolean isColumnPositionSelected(int columnPosition) -
getFullySelectedColumnPositions
public int[] getFullySelectedColumnPositions() -
isColumnPositionFullySelected
public boolean isColumnPositionFullySelected(int columnPosition) -
selectColumn
public void selectColumn(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) -
hasRowSelection
public boolean hasRowSelection() -
getSelectedRowCount
public int getSelectedRowCount() -
getSelectedRowPositions
-
isRowPositionSelected
public boolean isRowPositionSelected(int rowPosition) -
getFullySelectedRowPositions
public int[] getFullySelectedRowPositions() -
isRowPositionFullySelected
public boolean isRowPositionFullySelected(int rowPosition) -
selectRow
public void selectRow(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask) -
getDisplayModeByPosition
Description copied from interface:ILayerReturns the activeDisplayModefor the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry. The default value isDisplayMode.NORMAL. The SelectionLayer for example overrides this to returnDisplayMode.SELECTfor cells that are currently selected.- Specified by:
getDisplayModeByPositionin interfaceILayer- Overrides:
getDisplayModeByPositionin classAbstractIndexLayerTransform- Parameters:
columnPosition- The column position of the cell.rowPosition- The row position of the cell.- Returns:
DisplayModefor the cell at the given coordinates.
-
getConfigLabelsByPosition
Description copied from interface:ILayerReturns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry.- Specified by:
getConfigLabelsByPositionin interfaceILayer- Overrides:
getConfigLabelsByPositionin classAbstractIndexLayerTransform- Parameters:
columnPosition- The column position of the cell.rowPosition- The row position of the cell.- Returns:
- The
LabelStackwith the config labels for the cell at the given coordinates.
-
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
-
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 classAbstractIndexLayerTransform- Parameters:
command- The command to execute.- Returns:
trueif the command has been handled and was therefore consumed,falseotherwise.
-
fireCellSelectionEvent
public void fireCellSelectionEvent(int columnPosition, int rowPosition, boolean forcingEntireCellIntoViewport, boolean withShiftMask, boolean withControlMask) -
handleColumnHideCommand
Will check if there are fully selected column positions. If there is at least one fully selected column position, theColumnHideCommandwill be consumed and aMultiColumnHideCommandwill be created and executed further down the layer stack, that contains all fully selected column positions. Otherwise the given command will be executed further.
This is necessary because neither the ColumnHideShowLayer nor the action that caused the execution of theColumnHideCommandis aware of the presence of theSelectionLayer. Without this transformation, only the column on which the action was called will be hidden instead of all selected ones.- Parameters:
command- TheColumnHideCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
handleMultiColumnHideCommand
Previous to processing the givenMultiColumnHideCommanddown the layer stack, the fully selected column positions selection state will be cleared. This is necessary so the selection also disappears for the selected columns. Otherwise after hiding the selection will be showed for different columns.- Parameters:
command- TheMultiColumnHideCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
handleRowHideCommand
Will check if there are fully selected row positions. If there is at least one fully selected row position, theRowHideCommandwill be consumed and aMultiRowHideCommandwill be created and executed further down the layer stack, that contains all fully selected row positions. Otherwise the given command will be executed further.
This is necessary because neither the RowHideShowLayer nor the action that caused the execution of theRowHideCommandis aware of the presence of theSelectionLayer. Without this transformation, only the row on which the action was called will be hidden instead of all selected ones.- Parameters:
command- TheRowHideCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
handleMultiRowHideCommand
Previous to processing the givenMultiRowHideCommanddown the layer stack, the fully selected row positions selection state will be cleared. This is necessary so the selection also disappears for the selected rows. Otherwise after hiding the selection will be showed for different rows.- Parameters:
command- TheMultiRowHideCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
handleRowPositionHideCommand
First inspects the cell at the position contained in theRowPositionHideCommandand calculates all rows for that cell, taking the spanning into account. If the cell itself is selected, than also all other selected cells in the column position will be handled for hiding.- Parameters:
command- TheRowPositionHideCommandto process.- Returns:
trueif the command has been handled,falseotherwise- Since:
- 1.6
-
handleColumnResizeCommand
Will check if there are fully selected column positions. If there is at least one fully selected column position, theColumnResizeCommandwill be consumed and aMultiColumnResizeCommandwill be created and executed further down the layer stack, that contains all fully selected column positions. Otherwise the given command will be executed further.
This is necessary because neither the underlying layers are not aware of the presence of theSelectionLayer. Without this transformation, only the column on which the action was called will be resized instead of all selected ones.- Parameters:
command- TheColumnResizeCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
handleRowResizeCommand
Will check if there are fully selected row positions. If there is at least one fully selected row position, theRowResizeCommandwill be consumed and aMultiRowResizeCommandwill be created and executed further down the layer stack, that contains all fully selected row positions. Otherwise the given command will be executed further.
This is necessary because neither the underlying layers are not aware of the presence of theSelectionLayer. Without this transformation, only the row on which the action was called will be resized instead of all selected ones.- Parameters:
command- TheRowResizeCommandto process- Returns:
trueif the command has been handled,falseotherwise
-
setFillHandleRegion
public void setFillHandleRegion(org.eclipse.swt.graphics.Rectangle region) Set the region that is currently selected via fill handle to extend the current active selection for triggering a fill action.- Parameters:
region- The region selected via fill handle.- Since:
- 1.4
- See Also:
-
getFillHandleRegion
public org.eclipse.swt.graphics.Rectangle getFillHandleRegion()Returns the region that is currently selected via fill handle to extend the current active selection. Used to perform actions on drag & drop of the fill handle.- Returns:
- The region selected via fill handle or
null. - Since:
- 1.4
-
markFillHandleCell
public void markFillHandleCell()Marks the bottom right cell in a contiguous selection within theSelectionLayer. Also removes the markup in case there is no selection or the selection is not contiguous.- Since:
- 1.4
-
getProvidedLabels
- Specified by:
getProvidedLabelsin interfaceILayer- Overrides:
getProvidedLabelsin classAbstractLayer- Returns:
- The collection of labels that are provided by this layer.
- Since:
- 1.4
-