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
public class CopyDataCommandHandler extends AbstractLayerCommandHandler<CopyDataToClipboardCommand>
Handler class for copying selected data within theSelectionLayer
to the clipboard. This handler is registered by default with theSelectionLayer
, without references to the header regions. You can override the copy data behaviour by registering an instance of this handler to a layer above theSelectionLayer
. This way the registered custom instance will consume aCopyDataToClipboardCommand
and the registered default handler won't be called.
-
-
Field Summary
Fields Modifier and Type Field Description protected SelectionLayer
selectionLayer
TheSelectionLayer
needed to retrieve the selected data to copy to the clipboard.
-
Constructor Summary
Constructors Constructor Description CopyDataCommandHandler(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ILayerCell[]
assembleBody(int currentRowPosition)
Collects and assembles the selected data per row position that should be copied to the clipboard.protected ILayerCell[][]
assembleColumnHeaders()
Creates the two dimensional array whose dimensions are calculated based on the selection within theSelectionLayer
and the configured column and row headers.protected ILayerCell[][]
assembleCopiedDataStructure()
Collects and assembles the selected data that should be copied to the clipboard.boolean
doCommand(CopyDataToClipboardCommand command)
ILayer
getColumnHeaderLayer()
Class<CopyDataToClipboardCommand>
getCommandClass()
IUniqueIndexLayer
getCopyLayer()
ILayer
getRowHeaderLayer()
protected int[]
getSelectedColumnPositions()
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 Detail
-
selectionLayer
protected final SelectionLayer selectionLayer
TheSelectionLayer
needed to retrieve the selected data to copy to the clipboard.- Since:
- 1.4
-
-
Constructor Detail
-
CopyDataCommandHandler
public CopyDataCommandHandler(SelectionLayer selectionLayer)
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 Detail
-
setCopyLayer
public void setCopyLayer(IUniqueIndexLayer copyLayer)
- 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
public boolean doCommand(CopyDataToClipboardCommand command)
- 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
public Class<CopyDataToClipboardCommand> getCommandClass()
-
assembleCopiedDataStructure
protected ILayerCell[][] 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
protected ILayerCell[][] 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
protected ILayerCell[] assembleBody(int currentRowPosition)
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
public ILayer getColumnHeaderLayer()
- Returns:
- The column header layer of the grid, needed to also copy the column header data.
- Since:
- 1.6
-
getRowHeaderLayer
public ILayer getRowHeaderLayer()
- Returns:
- The row header layer of the grid, needed to also copy the row header data.
- Since:
- 1.6
-
getCopyLayer
public IUniqueIndexLayer 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
protected boolean isCopyAllowed(ILayerCell cellToCopy)
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
protected boolean isEmpty(ILayerCell[] layerCells)
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
-
-