Class CopyDataCommandHandler
java.lang.Object
org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler<CopyDataToClipboardCommand>
org.eclipse.nebula.widgets.nattable.copy.command.CopyDataCommandHandler
- All Implemented Interfaces:
ILayerCommandHandler<CopyDataToClipboardCommand>
- Direct Known Subclasses:
InternalCopyDataCommandHandler
,RowSpanningCopyDataCommandHandler
Handler class for copying selected data within the
SelectionLayer
to
the clipboard. This handler is registered by default with the
SelectionLayer
, without references to the header regions. You can
override the copy data behaviour by registering an instance of this handler
to a layer above the SelectionLayer
. This way the registered custom
instance will consume a CopyDataToClipboardCommand
and the registered
default handler won't be called.-
Field Summary
Modifier and TypeFieldDescriptionprotected final SelectionLayer
TheSelectionLayer
needed to retrieve the selected data to copy to the clipboard. -
Constructor Summary
ConstructorDescriptionCopyDataCommandHandler
(SelectionLayer selectionLayer) Creates an instance that only checks theSelectionLayer
for data to add to the clipboard.CopyDataCommandHandler
(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer) Creates an instance that checks theSelectionLayer
and the header layers if they are given. -
Method Summary
Modifier and TypeMethodDescriptionprotected ILayerCell[]
assembleBody
(int currentRowPosition) Collects and assembles the selected data per row position that should be copied to the clipboard.protected ILayerCell[][]
Creates the two dimensional array whose dimensions are calculated based on the selection within theSelectionLayer
and the configured column and row headers.protected ILayerCell[][]
Collects and assembles the selected data that should be copied to the clipboard.boolean
doCommand
(CopyDataToClipboardCommand command) protected int[]
Returns the array of visible selected column positions.protected void
internalDoCommand
(CopyDataToClipboardCommand command, ILayerCell[][] assembledCopiedDataStructure) Internal implementation of the command handling that additionally takes the assembled data structure to copy as parameter to avoid multiple assemble operations.protected boolean
isCopyAllowed
(ILayerCell cellToCopy) Checks if the given cell can be copied.protected boolean
isEmpty
(ILayerCell[] layerCells) Checks if the given array contains a value or if it only containsnull
values.void
setCopyFormattedText
(boolean copyFormattedText) Specify which serializer to use for copying.void
setCopyLayer
(IUniqueIndexLayer copyLayer) Methods inherited from class org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler
doCommand
-
Field Details
-
selectionLayer
TheSelectionLayer
needed to retrieve the selected data to copy to the clipboard.- Since:
- 1.4
-
-
Constructor Details
-
CopyDataCommandHandler
Creates an instance that only checks theSelectionLayer
for data to add to the clipboard.- Parameters:
selectionLayer
- TheSelectionLayer
within the NatTable. Can not benull
.
-
CopyDataCommandHandler
public CopyDataCommandHandler(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer) Creates an instance that checks theSelectionLayer
and the header layers if they are given.- Parameters:
selectionLayer
- TheSelectionLayer
within the NatTable. Can not benull
.columnHeaderLayer
- The column header layer within the NatTable grid. Can benull
.rowHeaderLayer
- The row header layer within the NatTable grid. Can benull
.
-
-
Method Details
-
setCopyLayer
- Parameters:
copyLayer
- The layer in the body region that should be used to copy. Only necessary in case there are layers on top of theSelectionLayer
that introduce additional information, e.g. the TreeLayer for the tree column. Setting this tonull
will lead to using theSelectionLayer
for retrieving the cells to copy.
-
setCopyFormattedText
public void setCopyFormattedText(boolean copyFormattedText) Specify which serializer to use for copying.- Parameters:
copyFormattedText
-false
will use the CopyDataToClipboardSerializer which simply callstoString()
to serialize the data to copy,true
will use the CopyFormattedTextToClipboardSerializer which will use the configured IDisplayConverter to get the String representation of the value to copy
-
doCommand
- Specified by:
doCommand
in classAbstractLayerCommandHandler<CopyDataToClipboardCommand>
-
internalDoCommand
protected void internalDoCommand(CopyDataToClipboardCommand command, ILayerCell[][] assembledCopiedDataStructure) Internal implementation of the command handling that additionally takes the assembled data structure to copy as parameter to avoid multiple assemble operations.- Parameters:
command
- TheCopyDataToClipboardCommand
to handle.assembledCopiedDataStructure
- The assembled data structure to copy.- Since:
- 1.6
-
getCommandClass
-
assembleCopiedDataStructure
Collects and assembles the selected data that should be copied to the clipboard.- Returns:
- A two dimensional array containing the selected cells to copy to the clipboard. The first level of this array represent the row positions of the cells, while the second level contains the cells itself based on the column position.
-
assembleColumnHeaders
Creates the two dimensional array whose dimensions are calculated based on the selection within theSelectionLayer
and the configured column and row headers. If there is a column header configured for this handler, the column header information will be added to the resulting array in here. If there is no column header configured an empty array with the matching dimensions will be returned.- Returns:
- A two dimensional array with the dimensions to store the selected data to copy to the clipboard. Will also contain the column header information for the copy operation if there is one configured.
-
assembleBody
Collects and assembles the selected data per row position that should be copied to the clipboard. If there is a row header layer configured for this handler, the row header cells of the selected row position are also added to the resulting array.- Parameters:
currentRowPosition
- The row position of which the selected cells should be collected.- Returns:
- An array containing the selected cells that should be copied to the clipboard.
-
getSelectedColumnPositions
protected int[] getSelectedColumnPositions()Returns the array of visible selected column positions. For this it gets all selected column positions, inspects the column width per position and only consider positions whose width is greater than 0.- Returns:
- Array of visible selected column positions.
- Since:
- 1.6
-
getColumnHeaderLayer
- Returns:
- The column header layer of the grid, needed to also copy the column header data.
- Since:
- 1.6
-
getRowHeaderLayer
- Returns:
- The row header layer of the grid, needed to also copy the row header data.
- Since:
- 1.6
-
getCopyLayer
- Returns:
- The layer in the body region that should be used to copy. Only
necessary in case there are layers on top of the
SelectionLayer
that introduce additional information, e.g. the TreeLayer for the tree column. - Since:
- 1.6
-
isCopyAllowed
Checks if the given cell can be copied.- Parameters:
cellToCopy
- TheILayerCell
that should be copied.- Returns:
true
if the cell can be copied,false
if a copy operation for that cell should be avoided.- Since:
- 1.6
-
isEmpty
Checks if the given array contains a value or if it only containsnull
values. If all array positions point tonull
it is considered to be empty.- Parameters:
layerCells
- The array to check.- Returns:
true
if all values in the array arenull
,false
if at least one real value is contained.- Since:
- 1.6
-