Class NatTable

    • Field Detail

      • INITIAL_PAINT_COMPLETE_FLAG

        public static final String INITIAL_PAINT_COMPLETE_FLAG
        Key that is used for loading NatTable states. Is set to true in case the initial painting is not finished yet. In this case there is no need to call refresh commands on loading.
        See Also:
        Constant Field Values
      • eventListenerLock

        protected ReadWriteLock eventListenerLock
        ReadWriteLock that is used to ensure that no concurrent modifications happen on event handling
        Since:
        1.5
    • Constructor Detail

      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        boolean autoconfigure)
        Parameters:
        parent - a composite control which will be the parent of the new instance (cannot be null)
        autoconfigure - if set to false no auto configuration is done. Default settings are not loaded. Configuration(s) have to be manually added by invoking addConfiguration(IConfiguration). At the minimum the DefaultNatTableStyleConfiguration must be added for the table to render.
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        ILayer layer)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        ILayer layer,
                        boolean autoconfigure)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        int style)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        int style,
                        boolean autoconfigure)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        int style,
                        ILayer layer)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        int style,
                        ILayer layer,
                        boolean autoconfigure)
      • NatTable

        public NatTable​(org.eclipse.swt.widgets.Composite parent,
                        int style,
                        ILayer layer,
                        EventConflaterChain chain,
                        boolean autoconfigure)
        Only use this constructor to specify a custom EventConflaterChain with different refresh interval settings in case you are facing issues on rendering, e.g. low FPS (laggy) behavior on scrolling (refresh interval too high) or flickering UI (refresh interval too low).
        Parameters:
        parent - a composite control which will be the parent of the new instance (cannot be null)
        style - the style of control to construct DEFAULT_STYLE_OPTIONS
        layer - the ILayer that should be rendered by this NatTable
        chain - the EventConflaterChain used to conflate events that trigger for example repainting. By default an EventConflaterChain is registered with a refresh interval specified via EventConflaterChain.DEFAULT_REFRESH_INTERVAL.
        autoconfigure - if set to false no auto configuration is done. Default settings are not loaded. Configuration(s) have to be manually added by invoking addConfiguration(IConfiguration). At the minimum the DefaultNatTableStyleConfiguration must be added for the table to render.
        Since:
        1.5
    • Method Detail

      • getVisualChangeEventConflater

        protected IEventConflater getVisualChangeEventConflater()
      • getLayer

        public ILayer getLayer()
      • setLayer

        public void setLayer​(ILayer layer)
      • addConfiguration

        public void addConfiguration​(IConfiguration configuration)
        Adds a configuration to the table.

        Configurations are processed when the configure() method is invoked. Each configuration object then has a chance to configure the

        1. ILayer
        2. ConfigRegistry
        3. UiBindingRegistry
        Parameters:
        configuration - The IConfiguration to add.
      • setConfigRegistry

        public void setConfigRegistry​(IConfigRegistry configRegistry)
        Sets the IConfigRegistry that should be used to hold the configurations. Can only be used if autoconfigure is turned off at NatTable creation. Should only be used in cases where an IConfigRegistry is needed for ILayer creation BEFORE the NatTable can be created.
        Parameters:
        configRegistry - The IConfigRegistry that should be used to hold the configurations.
      • configureScaling

        protected void configureScaling​(IDpiConverter horizontalConverter,
                                        IDpiConverter verticalConverter)
        Add the given IDpiConverter to the IConfigRegistry so they can be used by painters and set the system properties to use the configured scaling for images.
        Parameters:
        horizontalConverter - The IDpiConverter for horizontal scaling.
        verticalConverter - The IDpiConverter for vertical scaling.
        Since:
        2.0
      • getUiBindingRegistry

        public UiBindingRegistry getUiBindingRegistry()
        Returns:
        Registry holding all the UIBindings contributed by the underlying layers
      • setUiBindingRegistry

        public void setUiBindingRegistry​(UiBindingRegistry uiBindingRegistry)
      • getID

        public String getID()
      • checkSubclass

        protected void checkSubclass()
        Overrides:
        checkSubclass in class org.eclipse.swt.widgets.Composite
      • initInternalListener

        protected void initInternalListener()
      • addOverlayPainter

        public void addOverlayPainter​(IOverlayPainter overlayPainter)
      • removeOverlayPainter

        public void removeOverlayPainter​(IOverlayPainter overlayPainter)
      • paintControl

        public void paintControl​(org.eclipse.swt.events.PaintEvent event)
        Specified by:
        paintControl in interface org.eclipse.swt.events.PaintListener
      • setLayerPainter

        public void setLayerPainter​(ILayerPainter layerPainter)
      • repaintColumn

        public void repaintColumn​(int columnPosition)
        Repaint only a specific column in the grid. This method is optimized so that only the specific column is repainted and nothing else.
        Parameters:
        columnPosition - column of the grid to repaint
      • repaintRow

        public void repaintRow​(int rowPosition)
        Repaint only a specific row in the grid. This method is optimized so that only the specific row is repainted and nothing else.
        Parameters:
        rowPosition - row of the grid to repaint
      • repaintCell

        public void repaintCell​(int columnPosition,
                                int rowPosition)
        Repaint only a specific cell in the grid. This method is optimized so that only the specific cell is repainted and nothing else.
        Parameters:
        columnPosition - column position of the cell to repaint
        rowPosition - row position of the cell to repaint
      • repaintHorizontalLeftOver

        public void repaintHorizontalLeftOver()
        Repaint the area to the right of the last column in case there is more space available than columns to paint.
      • repaintVerticalLeftOver

        public void repaintVerticalLeftOver()
        Repaint the area to the bottom of the last row in case there is more space available than rows to paint.
      • updateResize

        public void updateResize()
      • refresh

        public void refresh()
        Refreshes the entire NatTable as every layer will be refreshed. Used to update on structural changes.
      • refresh

        public void refresh​(boolean structuralChange)
        Refreshes the entire NatTable as every layer will be refreshed.
        Parameters:
        structuralChange - true if a structural refresh should be performed (same as calling refresh()), false if only a visual refresh should be performed, e.g. if configuration values have changed.
        Since:
        1.4
      • configure

        public void configure​(IConfigRegistry configRegistry,
                              UiBindingRegistry uiBindingRegistry)
        Description copied from interface: ILayer
        Configure this layer, e.g. add any key/mouse bindings and other general configuration.

        This method is triggered by configure() and executed down the layer stack.

        Specified by:
        configure in interface ILayer
        Parameters:
        configRegistry - The IConfigRegistry instance owned by the NatTable this layer is attached to.
        uiBindingRegistry - The UiBindingRegistry instance owned by NatTable this layer is attached to.
      • configure

        public void configure()
        Processes all the registered IConfiguration (s). All the underlying layers are walked and given a chance to configure. Note: all desired configuration tweaks must be done before this method is invoked.
      • saveState

        public void saveState​(String prefix,
                              Properties properties)
        Save the state of the table to the properties object. IPersistable.saveState(String, Properties) is invoked on all the underlying layers. This properties object will be populated with the settings of all underlying layers and any IPersistable registered with those layers.
        Specified by:
        saveState in interface IPersistable
        Parameters:
        prefix - The prefix to use for the state keys. Is also used as the state configuration name.
        properties - The Properties instance to save the state to.
      • loadState

        public void loadState​(String prefix,
                              Properties properties)
        Restore the state of the underlying layers from the values in the properties object.
        Specified by:
        loadState in interface IPersistable
        Parameters:
        prefix - The prefix to use for the state keys. Is also used as the state configuration name.
        properties - The Properties instance to load the state from.
        See Also:
        saveState(String, Properties)
      • doCommand

        public boolean doCommand​(ILayerCommand command)
        Description copied from interface: ILayer
        Opportunity to respond to a command as it flows down the stack. If the layer is not interested in the command it should allow the command to keep traveling down the stack.

        Note: Before the layer can process a command it must convert the command to its local coordinates using ILayerCommand.convertToTargetLayer(ILayer)

        Specified by:
        doCommand in interface ILayer
        Parameters:
        command - The command to execute.
        Returns:
        true if the command has been handled and was therefore consumed, false otherwise.
      • fireLayerEvent

        public void fireLayerEvent​(ILayerEvent event)
        Description copied from interface: ILayer
        Events can be fired to notify other components of the grid. Events travel up the layer stack and may cause a repaint.

        Example: When the contents of the grid change IVisualChangeEvent can be fired to notify other layers to refresh their caches etc.

        Specified by:
        fireLayerEvent in interface ILayer
        Parameters:
        event - the event to fire
      • hasLayerListener

        public boolean hasLayerListener​(Class<? extends ILayerListener> layerListenerClass)
        Description copied from interface: ILayer
        Check if an ILayerListener of the given type is registered on this layer or not.
        Specified by:
        hasLayerListener in interface ILayer
        Parameters:
        layerListenerClass - The type of ILayerListener to check for.
        Returns:
        true if this ILayer has a ILayerListener of the specified type registered, false if there is no such listener registered.
      • getColumnCount

        public int getColumnCount()
        Specified by:
        getColumnCount in interface ILayer
        Returns:
        The number of columns in this layer.
      • getColumnIndexByPosition

        public int getColumnIndexByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Gets the underlying non-transformed column index for the given column position on this layer.
        Specified by:
        getColumnIndexByPosition in interface ILayer
        Parameters:
        columnPosition - The column position relative to this layer.
        Returns:
        An underlying non-transformed column index, or -1 if the given column position does not exist within this coordinate system.
      • localToUnderlyingColumnPosition

        public int localToUnderlyingColumnPosition​(int localColumnPosition)
        Description copied from interface: ILayer
        Convert a column position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.
        Specified by:
        localToUnderlyingColumnPosition in interface ILayer
        Parameters:
        localColumnPosition - column position in local (the layer's own) coordinates
        Returns:
        column position in the underlying layer's coordinates
      • underlyingToLocalColumnPosition

        public int underlyingToLocalColumnPosition​(ILayer sourceUnderlyingLayer,
                                                   int underlyingColumnPosition)
        Description copied from interface: ILayer
        Transforms the column position relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPosition in interface ILayer
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column position matches.
        underlyingColumnPosition - The column position in the given underlying layer that should be converted to a local column position.
        Returns:
        The given column position transformed to be local to this layer.
      • underlyingToLocalColumnPositions

        public Collection<Range> underlyingToLocalColumnPositions​(ILayer sourceUnderlyingLayer,
                                                                  Collection<Range> underlyingColumnPositionRanges)
        Description copied from interface: ILayer
        Transforms the column position ranges relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalColumnPositions in interface ILayer
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given column positions match.
        underlyingColumnPositionRanges - The column position ranges relative to the given underlying layer that should be converted to local column positions.
        Returns:
        The given column position ranges transformed to this layer.
      • getWidth

        public int getWidth()
        Description copied from interface: ILayer
        Returns the total width in pixels of this layer.
        Specified by:
        getWidth in interface ILayer
        Returns:
        The total width in pixels of this layer.
      • getColumnWidthByPosition

        public int getColumnWidthByPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the width in pixels of the given column. The width of invisible and non-existing columns is 0.
        Specified by:
        getColumnWidthByPosition in interface ILayer
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The width of the column.
      • isColumnPositionResizable

        public boolean isColumnPositionResizable​(int columnPosition)
        Description copied from interface: ILayer
        Check if the column at the given position is resizable.
        Specified by:
        isColumnPositionResizable in interface ILayer
        Parameters:
        columnPosition - The column position to check.
        Returns:
        true if the column is resizable, false if not.
      • getColumnPositionByX

        public int getColumnPositionByX​(int x)
        Description copied from interface: ILayer
        Returns the column position that contains the given x coordinate.
        Specified by:
        getColumnPositionByX in interface ILayer
        Parameters:
        x - A horizontal pixel location relative to the pixel boundary of this layer.
        Returns:
        A column position relative to the associated coordinate system, or -1 if there is no column that contains x.
      • getStartXOfColumnPosition

        public int getStartXOfColumnPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the x offset in pixels of the given column.
        Specified by:
        getStartXOfColumnPosition in interface ILayer
        Parameters:
        columnPosition - The column position in this layer.
        Returns:
        The x offset of the column, or -1.
      • getUnderlyingLayersByColumnPosition

        public Collection<ILayer> getUnderlyingLayersByColumnPosition​(int columnPosition)
        Description copied from interface: ILayer
        Returns the layers that are directly below this layer for the given column position. For simple layers this collection will typically only have one entry. Layer compositions might return multiple values, e.g. in a default grid there will be 2 layers in the collection as there are two layers involved in a column.
        Specified by:
        getUnderlyingLayersByColumnPosition in interface ILayer
        Parameters:
        columnPosition - The column position for which the underlying layers are requested.
        Returns:
        The layers that are directly below this layer for the given column position or null if this layer has no underlying layers.
      • getRowCount

        public int getRowCount()
        Specified by:
        getRowCount in interface ILayer
        Returns:
        The number of rows in this layer.
      • getRowIndexByPosition

        public int getRowIndexByPosition​(int rowPosition)
        Description copied from interface: ILayer
        Gets the underlying non-transformed row index for the given row position on this layer.
        Specified by:
        getRowIndexByPosition in interface ILayer
        Parameters:
        rowPosition - The row position relative to this layer.
        Returns:
        An underlying non-transformed row index, or -1 if the given row position does not exist within this coordinate system.
      • localToUnderlyingRowPosition

        public int localToUnderlyingRowPosition​(int localRowPosition)
        Description copied from interface: ILayer
        Convert a row position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.
        Specified by:
        localToUnderlyingRowPosition in interface ILayer
        Parameters:
        localRowPosition - row position in local (the layer's own) coordinates
        Returns:
        row position in the underlying layer's coordinates
      • underlyingToLocalRowPosition

        public int underlyingToLocalRowPosition​(ILayer sourceUnderlyingLayer,
                                                int underlyingRowPosition)
        Description copied from interface: ILayer
        Transforms the row position relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalRowPosition in interface ILayer
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given row position matches.
        underlyingRowPosition - The row position in the given underlying layer that should be converted to a local row position.
        Returns:
        The given row position transformed to be local to this layer.
      • underlyingToLocalRowPositions

        public Collection<Range> underlyingToLocalRowPositions​(ILayer sourceUnderlyingLayer,
                                                               Collection<Range> underlyingRowPositionRanges)
        Description copied from interface: ILayer
        Transforms the row position ranges relative to the given underlying layer to this layer coordinates.
        Specified by:
        underlyingToLocalRowPositions in interface ILayer
        Parameters:
        sourceUnderlyingLayer - The underlying layer to which the given row positions match.
        underlyingRowPositionRanges - The row position ranges relative to the given underlying layer that should be converted to local row positions.
        Returns:
        The given row position ranges transformed to this layer.
      • getHeight

        public int getHeight()
        Description copied from interface: ILayer
        Returns the total height in pixels of this layer.
        Specified by:
        getHeight in interface ILayer
        Returns:
        The total height in pixels of this layer.
      • getRowHeightByPosition

        public int getRowHeightByPosition​(int rowPosition)
        Description copied from interface: ILayer
        Returns the height in pixels of the given row. The height of invisible and non-existing rows is 0.
        Specified by:
        getRowHeightByPosition in interface ILayer
        Parameters:
        rowPosition - The row position in this layer.
        Returns:
        The height of the row.
      • isRowPositionResizable

        public boolean isRowPositionResizable​(int rowPosition)
        Description copied from interface: ILayer
        Check if the row at the given position is resizable.
        Specified by:
        isRowPositionResizable in interface ILayer
        Parameters:
        rowPosition - The row position to check.
        Returns:
        true if the row is resizable, false if not.
      • getRowPositionByY

        public int getRowPositionByY​(int y)
        Description copied from interface: ILayer
        Returns the row position that contains the given y coordinate.
        Specified by:
        getRowPositionByY in interface ILayer
        Parameters:
        y - a vertical pixel location relative to the pixel boundary of this layer
        Returns:
        a row position relative to the associated coordinate system, or -1 if there is no row that contains y
      • getStartYOfRowPosition

        public int getStartYOfRowPosition​(int rowPosition)
        Description copied from interface: ILayer
        Returns the y offset in pixels of the given row.
        Specified by:
        getStartYOfRowPosition in interface ILayer
        Parameters:
        rowPosition - the row position in this layer
        Returns:
        the y offset of the row, or -1
      • getUnderlyingLayersByRowPosition

        public Collection<ILayer> getUnderlyingLayersByRowPosition​(int rowPosition)
        Description copied from interface: ILayer
        Returns the layers that are directly below this layer for the given row position. For simple layers this collection will typically only have one entry. Layer compositions might return multiple values, e.g. in a default grid there will be 2 layers in the collection as there are two layers involved in a row.
        Specified by:
        getUnderlyingLayersByRowPosition in interface ILayer
        Parameters:
        rowPosition - The row position for which the underlying layers are requested.
        Returns:
        The layers that are directly below this layer for the given row position or null if this layer has no underlying layers.
      • getCellByPosition

        public ILayerCell getCellByPosition​(int columnPosition,
                                            int rowPosition)
        Description copied from interface: ILayer
        Returns the cell for the given coordinates on this layer.
        Specified by:
        getCellByPosition in interface ILayer
        Parameters:
        columnPosition - The column position of the requested cell.
        rowPosition - The row position of the requested cell.
        Returns:
        The ILayerCell for the given coordinates in this layer or null if the coordinates are invalid on this layer.
      • getBoundsByPosition

        public org.eclipse.swt.graphics.Rectangle getBoundsByPosition​(int columnPosition,
                                                                      int rowPosition)
        Description copied from interface: ILayer
        Calculates the bounds in pixel for the given cell position.
        Specified by:
        getBoundsByPosition in interface ILayer
        Parameters:
        columnPosition - the column position of the cell
        rowPosition - the row position of the cell
        Returns:
        the bounds, or null if there are no valid bounds
      • getDisplayModeByPosition

        public DisplayMode getDisplayModeByPosition​(int columnPosition,
                                                    int rowPosition)
        Description copied from interface: ILayer
        Returns the active DisplayMode for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of the IConfigRegistry. The default value is DisplayMode.NORMAL. The SelectionLayer for example overrides this to return DisplayMode.SELECT for cells that are currently selected.
        Specified by:
        getDisplayModeByPosition in interface ILayer
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        DisplayMode for the cell at the given coordinates.
      • getConfigLabelsByPosition

        public LabelStack getConfigLabelsByPosition​(int columnPosition,
                                                    int rowPosition)
        Description copied from interface: ILayer
        Returns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of the IConfigRegistry.
        Specified by:
        getConfigLabelsByPosition in interface ILayer
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        The LabelStack with the config labels for the cell at the given coordinates.
      • getDataValueByPosition

        public Object getDataValueByPosition​(int columnPosition,
                                             int rowPosition)
        Description copied from interface: ILayer
        Returns the data value for the cell at the given coordinates.
        Specified by:
        getDataValueByPosition in interface ILayer
        Parameters:
        columnPosition - The column position of the cell.
        rowPosition - The row position of the cell.
        Returns:
        The data value for the cell at the given coordinates.
      • getRegionLabelsByXY

        public LabelStack getRegionLabelsByXY​(int x,
                                              int y)
        Description copied from interface: ILayer
        Return the LabelStack containing the region labels for the cell at the given pixel position.
        Specified by:
        getRegionLabelsByXY in interface ILayer
        Parameters:
        x - the x pixel coordinate
        y - the y pixel coordinate
        Returns:
        LabelStack containing the region labels for the cell at the given pixel position.
      • getUnderlyingLayerByPosition

        public ILayer getUnderlyingLayerByPosition​(int columnPosition,
                                                   int rowPosition)
        Description copied from interface: ILayer
        Returns the layer that is directly below this layer for the given cell coordinate.
        Specified by:
        getUnderlyingLayerByPosition in interface ILayer
        Parameters:
        columnPosition - The column position for which the underlying layer is requested.
        rowPosition - The row position for which the underlying layer is requested.
        Returns:
        The layer that is directly below this layer for the given cell coordinates or null if this layer has no underlying layers.
      • addDragSupport

        public void addDragSupport​(int operations,
                                   org.eclipse.swt.dnd.Transfer[] transferTypes,
                                   org.eclipse.swt.dnd.DragSourceListener listener)
        Adds support for dragging items out of this control via a user drag-and-drop operation.
        Parameters:
        operations - a bitwise OR of the supported drag and drop operation types ( DROP_COPY,DROP_LINK, and DROP_MOVE)
        transferTypes - the transfer types that are supported by the drag operation
        listener - the callback that will be invoked to set the drag data and to cleanup after the drag and drop operation finishes
        See Also:
        DND
      • addDropSupport

        public void addDropSupport​(int operations,
                                   org.eclipse.swt.dnd.Transfer[] transferTypes,
                                   org.eclipse.swt.dnd.DropTargetListener listener)
        Adds support for dropping items into this control via a user drag-and-drop operation.
        Parameters:
        operations - a bitwise OR of the supported drag and drop operation types ( DROP_COPY,DROP_LINK, and DROP_MOVE)
        transferTypes - the transfer types that are supported by the drop operation
        listener - the callback that will be invoked after the drag and drop operation finishes
        See Also:
        DND
      • setTheme

        public void setTheme​(ThemeConfiguration themeConfiguration)
        Will unregister the style configurations that were applied before by another ThemeConfiguration and register the style configurations of the given ThemeConfiguration.
        Parameters:
        themeConfiguration - The ThemeConfiguration that contains the style configurations to apply.
      • getActiveCellEditor

        public ICellEditor getActiveCellEditor()
        Returns the active cell editor that is currently open or null if there is no editor active.
        Returns:
        the active editor or null
      • commitAndCloseActiveCellEditor

        public boolean commitAndCloseActiveCellEditor()
        Checks if there is an active cell editor registered. If there is one, it is tried to commit the value that is currently entered there.
        Returns:
        false if there is an open editor that can not be committed because of conversion/validation errors, true if there is no active open editor or it could be closed after committing the value.
      • getProvidedLabels

        public Collection<String> getProvidedLabels()
        Returns the labels that are used within this NatTable for conditional styling.
        Specified by:
        getProvidedLabels in interface ILayer
        Returns:
        The labels that are used within this NatTable for conditional styling.
        Since:
        1.4