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
FieldsModifier and TypeFieldDescriptionprotected final SelectionLayerTheSelectionLayerneeded to retrieve the selected data to copy to the clipboard. -
Constructor Summary
ConstructorsConstructorDescriptionCopyDataCommandHandler(SelectionLayer selectionLayer) Creates an instance that only checks theSelectionLayerfor data to add to the clipboard.CopyDataCommandHandler(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer) Creates an instance that checks theSelectionLayerand 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 theSelectionLayerand the configured column and row headers.protected ILayerCell[][]Collects and assembles the selected data that should be copied to the clipboard.booleandoCommand(CopyDataToClipboardCommand command) protected int[]Returns the array of visible selected column positions.protected voidinternalDoCommand(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 booleanisCopyAllowed(ILayerCell cellToCopy) Checks if the given cell can be copied.protected booleanisEmpty(ILayerCell[] layerCells) Checks if the given array contains a value or if it only containsnullvalues.voidsetCopyFormattedText(boolean copyFormattedText) Specify which serializer to use for copying.voidsetCopyLayer(IUniqueIndexLayer copyLayer) Methods inherited from class org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler
doCommand
-
Field Details
-
selectionLayer
TheSelectionLayerneeded to retrieve the selected data to copy to the clipboard.- Since:
- 1.4
-
-
Constructor Details
-
CopyDataCommandHandler
Creates an instance that only checks theSelectionLayerfor data to add to the clipboard.- Parameters:
selectionLayer- TheSelectionLayerwithin the NatTable. Can not benull.
-
CopyDataCommandHandler
public CopyDataCommandHandler(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer) Creates an instance that checks theSelectionLayerand the header layers if they are given.- Parameters:
selectionLayer- TheSelectionLayerwithin 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 theSelectionLayerthat introduce additional information, e.g. the TreeLayer for the tree column. Setting this tonullwill lead to using theSelectionLayerfor retrieving the cells to copy.
-
setCopyFormattedText
public void setCopyFormattedText(boolean copyFormattedText) Specify which serializer to use for copying.- Parameters:
copyFormattedText-falsewill use the CopyDataToClipboardSerializer which simply callstoString()to serialize the data to copy,truewill use the CopyFormattedTextToClipboardSerializer which will use the configured IDisplayConverter to get the String representation of the value to copy
-
doCommand
- Specified by:
doCommandin 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- TheCopyDataToClipboardCommandto 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 theSelectionLayerand 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
SelectionLayerthat 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- TheILayerCellthat should be copied.- Returns:
trueif the cell can be copied,falseif 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 containsnullvalues. If all array positions point tonullit is considered to be empty.- Parameters:
layerCells- The array to check.- Returns:
trueif all values in the array arenull,falseif at least one real value is contained.- Since:
- 1.6
-