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 theISelectionModel
to track the selection state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SelectionLayer.MoveDirectionEnum
-
Field Summary
Fields Modifier and Type Field Description protected PositionCoordinate
bottomRightInSelection
The bottom right cell in a contiguous selection ornull
if there is no selection or the selection is not contiguous.protected org.eclipse.swt.graphics.Rectangle
fillHandleRegion
The region selected via fill handle to extend the current selection for triggering a fill action.protected PositionCoordinate
lastSelectedCell
protected org.eclipse.swt.graphics.Rectangle
lastSelectedRegion
static int
MOVE_ALL
static int
NO_SELECTION
protected SelectCellCommandHandler
selectCellCommandHandler
protected SelectColumnCommandHandler
selectColumnCommandHandler
protected PositionCoordinate
selectionAnchor
protected ISelectionModel
selectionModel
protected SelectRowCommandHandler
selectRowCommandHandler
protected IUniqueIndexLayer
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
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 void
addSelection(org.eclipse.swt.graphics.Rectangle selection)
boolean
allCellsSelectedInRegion(org.eclipse.swt.graphics.Rectangle region)
Test if all cells in a given region are selected.void
clear()
void
clear(boolean fireSelectionEvent)
void
clearSelection(int columnPosition, int rowPosition)
void
clearSelection(org.eclipse.swt.graphics.Rectangle selection)
boolean
doCommand(ILayerCommand command)
Opportunity to respond to a command as it flows down the stack.void
fireCellSelectionEvent(int columnPosition, int rowPosition, boolean forcingEntireCellIntoViewport, boolean withShiftMask, boolean withControlMask)
protected PositionCoordinate
getCellPositionToMoveFrom(boolean withShiftMask, boolean withControlMask)
When extending a selected area via modifier keys, we need to move from the last selected cell.LabelStack
getConfigLabelsByPosition(int columnPosition, int rowPosition)
Returns the config labels for the cell at the given coordinates.DisplayMode
getDisplayModeByPosition(int columnPosition, int rowPosition)
Returns the activeDisplayMode
for the cell at the given coordinates.org.eclipse.swt.graphics.Rectangle
getFillHandleRegion()
Returns the region that is currently selected via fill handle to extend the current active selection.int[]
getFullySelectedColumnPositions()
int[]
getFullySelectedRowPositions()
PositionCoordinate
getLastSelectedCellPosition()
org.eclipse.swt.graphics.Rectangle
getLastSelectedRegion()
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()
int
getSelectedRowCount()
Set<Range>
getSelectedRowPositions()
PositionCoordinate
getSelectionAnchor()
ISelectionModel
getSelectionModel()
protected boolean
handleColumnHideCommand(ColumnHideCommand command)
Will check if there are fully selected column positions.protected boolean
handleColumnResizeCommand(ColumnResizeCommand command)
Will check if there are fully selected column positions.protected boolean
handleMultiColumnHideCommand(MultiColumnHideCommand command)
Previous to processing the givenMultiColumnHideCommand
down the layer stack, the fully selected column positions selection state will be cleared.protected boolean
handleMultiRowHideCommand(MultiRowHideCommand command)
Previous to processing the givenMultiRowHideCommand
down the layer stack, the fully selected row positions selection state will be cleared.protected boolean
handleRowHideCommand(RowHideCommand command)
Will check if there are fully selected row positions.protected boolean
handleRowPositionHideCommand(RowPositionHideCommand command)
First inspects the cell at the position contained in theRowPositionHideCommand
and calculates all rows for that cell, taking the spanning into account.protected boolean
handleRowResizeCommand(RowResizeCommand command)
Will check if there are fully selected row positions.boolean
hasColumnSelection()
boolean
hasRowSelection()
boolean
isCellPositionSelected(int columnPosition, int rowPosition)
boolean
isColumnPositionFullySelected(int columnPosition)
boolean
isColumnPositionSelected(int columnPosition)
boolean
isRowPositionFullySelected(int rowPosition)
boolean
isRowPositionSelected(int rowPosition)
void
markFillHandleCell()
Marks the bottom right cell in a contiguous selection within theSelectionLayer
.void
moveSelectionAnchor(int startColumnPositionInRegion, int startRowPosition)
protected void
registerCommandHandlers()
Layers should use this method to register their command handlers and call it from their constructor.void
selectAll()
void
selectCell(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask)
Calculates the selected cells - taking into account Shift and Ctrl key presses.void
selectColumn(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask)
void
selectRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight)
void
selectRow(int columnPosition, int rowPosition, boolean withShiftMask, boolean withControlMask)
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.void
setLastSelectedCell(int columnPosition, int rowPosition)
protected void
setLastSelectedRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight)
protected void
setLastSelectedRegion(org.eclipse.swt.graphics.Rectangle region)
void
setSelectedCell(int columnPosition, int rowPosition)
void
setSelectionModel(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 ornull
if 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
-true
if the shift mask is active,false
if not.withControlMask
-true
if the shift mask is active,false
if 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:
true
if all cells in a region are selected,false
if 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:ILayer
Returns the activeDisplayMode
for 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.SELECT
for cells that are currently selected.- Specified by:
getDisplayModeByPosition
in interfaceILayer
- Overrides:
getDisplayModeByPosition
in classAbstractIndexLayerTransform
- Parameters:
columnPosition
- The column position of the cell.rowPosition
- The row position of the cell.- Returns:
DisplayMode
for the cell at the given coordinates.
-
getConfigLabelsByPosition
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayer
Returns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry
.- Specified by:
getConfigLabelsByPosition
in interfaceILayer
- Overrides:
getConfigLabelsByPosition
in classAbstractIndexLayerTransform
- Parameters:
columnPosition
- The column position of the cell.rowPosition
- The row position of the cell.- Returns:
- The
LabelStack
with the config labels for the cell at the given coordinates.
-
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
-
doCommand
public boolean doCommand(ILayerCommand command)
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 classAbstractIndexLayerTransform
- Parameters:
command
- The command to execute.- Returns:
true
if the command has been handled and was therefore consumed,false
otherwise.
-
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, theColumnHideCommand
will be consumed and aMultiColumnHideCommand
will 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 theColumnHideCommand
is 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
- TheColumnHideCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
handleMultiColumnHideCommand
protected boolean handleMultiColumnHideCommand(MultiColumnHideCommand command)
Previous to processing the givenMultiColumnHideCommand
down 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
- TheMultiColumnHideCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
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, theRowHideCommand
will be consumed and aMultiRowHideCommand
will 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 theRowHideCommand
is 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
- TheRowHideCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
handleMultiRowHideCommand
protected boolean handleMultiRowHideCommand(MultiRowHideCommand command)
Previous to processing the givenMultiRowHideCommand
down 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
- TheMultiRowHideCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
handleRowPositionHideCommand
protected boolean handleRowPositionHideCommand(RowPositionHideCommand command)
First inspects the cell at the position contained in theRowPositionHideCommand
and 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
- TheRowPositionHideCommand
to process.- Returns:
true
if the command has been handled,false
otherwise- 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, theColumnResizeCommand
will be consumed and aMultiColumnResizeCommand
will 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
- TheColumnResizeCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
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, theRowResizeCommand
will be consumed and aMultiRowResizeCommand
will 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
- TheRowResizeCommand
to process- Returns:
true
if the command has been handled,false
otherwise
-
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:
getProvidedLabels
in interfaceILayer
- Overrides:
getProvidedLabels
in classAbstractLayer
- Returns:
- The collection of labels that are provided by this layer.
- Since:
- 1.4
-
-