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
public class SelectionLayer extends AbstractIndexLayerTransform
Enables selection of column, rows, cells etc. on the table. Also responds to UI bindings by changing the current selection. Internally it uses theISelectionModelto track the selection state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSelectionLayer.MoveDirectionEnum
-
Field Summary
Fields Modifier and Type Field Description protected PositionCoordinatebottomRightInSelectionThe bottom right cell in a contiguous selection ornullif there is no selection or the selection is not contiguous.protected org.eclipse.swt.graphics.RectanglefillHandleRegionThe region selected via fill handle to extend the current selection for triggering a fill action.protected PositionCoordinatelastSelectedCellprotected org.eclipse.swt.graphics.RectanglelastSelectedRegionstatic intMOVE_ALLstatic intNO_SELECTIONprotected SelectCellCommandHandlerselectCellCommandHandlerprotected SelectColumnCommandHandlerselectColumnCommandHandlerprotected PositionCoordinateselectionAnchorprotected ISelectionModelselectionModelprotected SelectRowCommandHandlerselectRowCommandHandlerprotected IUniqueIndexLayerunderlyingLayer-
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
Constructors Constructor Description SelectionLayer(IUniqueIndexLayer underlyingLayer)SelectionLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration)SelectionLayer(IUniqueIndexLayer underlyingLayer, ISelectionModel selectionModel, boolean useDefaultConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSelection(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.LabelStackgetConfigLabelsByPosition(int columnPosition, int rowPosition)Returns the config labels for the cell at the given coordinates.DisplayModegetDisplayModeByPosition(int columnPosition, int rowPosition)Returns the activeDisplayModefor the cell at the given coordinates.org.eclipse.swt.graphics.RectanglegetFillHandleRegion()Returns the region that is currently selected via fill handle to extend the current active selection.int[]getFullySelectedColumnPositions()int[]getFullySelectedRowPositions()PositionCoordinategetLastSelectedCellPosition()org.eclipse.swt.graphics.RectanglegetLastSelectedRegion()Collection<String>getProvidedLabels()PositionCoordinate[]getSelectedCellPositions()Collection<ILayerCell>getSelectedCells()Retrieves the ILayerCells out of the SelectionLayer that are currently marked as selected in the SelectionModel.int[]getSelectedColumnPositions()intgetSelectedRowCount()Set<Range>getSelectedRowPositions()PositionCoordinategetSelectionAnchor()ISelectionModelgetSelectionModel()protected booleanhandleColumnHideCommand(ColumnHideCommand command)Will check if there are fully selected column positions.protected booleanhandleColumnResizeCommand(ColumnResizeCommand command)Will check if there are fully selected column positions.protected booleanhandleMultiColumnHideCommand(MultiColumnHideCommand command)Previous to processing the givenMultiColumnHideCommanddown the layer stack, the fully selected column positions selection state will be cleared.protected booleanhandleMultiRowHideCommand(MultiRowHideCommand command)Previous 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 booleanhandleRowPositionHideCommand(RowPositionHideCommand command)First 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.booleanhasColumnSelection()booleanhasRowSelection()booleanisCellPositionSelected(int columnPosition, int rowPosition)booleanisColumnPositionFullySelected(int columnPosition)booleanisColumnPositionSelected(int columnPosition)booleanisRowPositionFullySelected(int rowPosition)booleanisRowPositionSelected(int rowPosition)voidmarkFillHandleCell()Marks the bottom right cell in a contiguous selection within theSelectionLayer.voidmoveSelectionAnchor(int startColumnPositionInRegion, int startRowPosition)protected voidregisterCommandHandlers()Layers should use this method to register their command handlers and call it from their constructor.voidselectAll()voidselectCell(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, underlyingToLocalRowPositions
-
Methods 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, 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, fireLayerEvent, getBoundsByPosition, getClientAreaProvider, hasLayerListener, registerCommandHandler, registerPersistable, removeLayerListener, unregisterCommandHandler, unregisterPersistable
-
Methods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayerListener
handleLayerEvent
-
-
-
-
Field Detail
-
MOVE_ALL
public static final int MOVE_ALL
- See Also:
- Constant Field Values
-
NO_SELECTION
public static final int NO_SELECTION
- See Also:
- Constant Field Values
-
selectionModel
protected ISelectionModel selectionModel
-
underlyingLayer
protected IUniqueIndexLayer underlyingLayer
-
lastSelectedCell
protected final PositionCoordinate lastSelectedCell
-
selectionAnchor
protected final PositionCoordinate selectionAnchor
-
lastSelectedRegion
protected org.eclipse.swt.graphics.Rectangle lastSelectedRegion
-
fillHandleRegion
protected org.eclipse.swt.graphics.Rectangle fillHandleRegion
The region selected via fill handle to extend the current selection for triggering a fill action. Can benull.- Since:
- 1.4
-
bottomRightInSelection
protected PositionCoordinate 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
protected SelectRowCommandHandler selectRowCommandHandler
-
selectCellCommandHandler
protected SelectCellCommandHandler selectCellCommandHandler
-
selectColumnCommandHandler
protected SelectColumnCommandHandler selectColumnCommandHandler
-
-
Constructor Detail
-
SelectionLayer
public SelectionLayer(IUniqueIndexLayer underlyingLayer)
-
SelectionLayer
public SelectionLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration)
-
SelectionLayer
public SelectionLayer(IUniqueIndexLayer underlyingLayer, ISelectionModel selectionModel, boolean useDefaultConfiguration)
-
-
Method Detail
-
getSelectionModel
public ISelectionModel getSelectionModel()
-
setSelectionModel
public void setSelectionModel(ISelectionModel selectionModel)
-
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
public PositionCoordinate[] getSelectedCellPositions()
-
getSelectedCells
public Collection<ILayerCell> 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
public PositionCoordinate getSelectionAnchor()
-
moveSelectionAnchor
public void moveSelectionAnchor(int startColumnPositionInRegion, int startRowPosition)
-
getLastSelectedCellPosition
public PositionCoordinate 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()
-
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
public DisplayMode getDisplayModeByPosition(int columnPosition, int rowPosition)
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
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition)
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
public boolean doCommand(ILayerCommand command)
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
protected boolean handleColumnHideCommand(ColumnHideCommand command)
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
protected boolean handleMultiColumnHideCommand(MultiColumnHideCommand command)
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
protected boolean handleRowHideCommand(RowHideCommand command)
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
protected boolean handleMultiRowHideCommand(MultiRowHideCommand command)
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
protected boolean handleRowPositionHideCommand(RowPositionHideCommand command)
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
protected boolean handleColumnResizeCommand(ColumnResizeCommand command)
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
protected boolean handleRowResizeCommand(RowResizeCommand command)
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:
FillHandleDragMode,FillHandleLayerPainter
-
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
public Collection<String> getProvidedLabels()
- Specified by:
getProvidedLabelsin interfaceILayer- Overrides:
getProvidedLabelsin classAbstractLayer- Returns:
- The collection of labels that are provided by this layer.
- Since:
- 1.4
-
-