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 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 Details

    • selectionLayer

      protected final SelectionLayer selectionLayer
      The SelectionLayer needed to retrieve the selected data to copy to the clipboard.
      Since:
      1.4
  • Constructor Details

    • CopyDataCommandHandler

      public CopyDataCommandHandler(SelectionLayer selectionLayer)
      Creates an instance that only checks the SelectionLayer for data to add to the clipboard.
      Parameters:
      selectionLayer - The SelectionLayer within the NatTable. Can not be null.
    • CopyDataCommandHandler

      public CopyDataCommandHandler(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer)
      Creates an instance that checks the SelectionLayer and the header layers if they are given.
      Parameters:
      selectionLayer - The SelectionLayer within the NatTable. Can not be null.
      columnHeaderLayer - The column header layer within the NatTable grid. Can be null.
      rowHeaderLayer - The row header layer within the NatTable grid. Can be null.
  • Method Details

    • 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 the SelectionLayer that introduce additional information, e.g. the TreeLayer for the tree column. Setting this to null will lead to using the SelectionLayer 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 calls toString() 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 class AbstractLayerCommandHandler<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 - The CopyDataToClipboardCommand 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 the SelectionLayer 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 - The ILayerCell 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 contains null values. If all array positions point to nullit is considered to be empty.
      Parameters:
      layerCells - The array to check.
      Returns:
      true if all values in the array are null, false if at least one real value is contained.
      Since:
      1.6