Class CopyDataCommandHandler

    • Field Detail

      • selectionLayer

        protected final SelectionLayer selectionLayer
        The SelectionLayer 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 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 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 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
      • 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
      • 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