org.eclipse.nebula.widgets.nattable.layer
Class DataLayer

java.lang.Object
  extended by org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
      extended by org.eclipse.nebula.widgets.nattable.layer.DataLayer
All Implemented Interfaces:
ILayer, ILayerListener, IUniqueIndexLayer, IPersistable
Direct Known Subclasses:
BaseDataLayerFixture, DefaultColumnHeaderDataLayer, DefaultRowHeaderDataLayer, FilterRowDataLayer, GroupByDataLayer, SpanningDataLayer

public class DataLayer
extends AbstractLayer
implements IUniqueIndexLayer

Wraps the IDataProvider, and serves as the data source for all other layers. Also, tracks the size of the columns and the rows using SizeConfig objects. Since this layer sits directly on top of the data source, at this layer index == position.


Field Summary
protected  SizeConfig columnWidthConfig
           
protected  IDataProvider dataProvider
           
static int DEFAULT_COLUMN_WIDTH
           
static int DEFAULT_ROW_HEIGHT
           
static String PERSISTENCE_KEY_COLUMN_WIDTH
           
static String PERSISTENCE_KEY_ROW_HEIGHT
           
protected  SizeConfig rowHeightConfig
           
 
Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
commandHandlers, eventHandlers, layerPainter
 
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
 
Constructor Summary
protected DataLayer()
           
  DataLayer(IDataProvider dataProvider)
           
  DataLayer(IDataProvider dataProvider, int defaultColumnWidth, int defaultRowHeight)
           
protected DataLayer(int defaultColumnWidth, int defaultRowHeight)
           
 
Method Summary
 boolean doCommand(ILayerCommand command)
          Opportunity to respond to a command as it flows down the stack.
 int getColumnCount()
           
 int getColumnIndexByPosition(int columnPosition)
          This is the root coordinate system, so the column index is always equal to the column position.
 int getColumnPositionByIndex(int columnIndex)
          This is the root coordinate system, so the column position is always equal to the column index.
 int getColumnPositionByX(int x)
          Returns the column position that contains the given x coordinate.
 int getColumnWidthByPosition(int columnPosition)
          Returns the width in pixels of the given column.
 IDataProvider getDataProvider()
           
 Object getDataValue(int columnIndex, int rowIndex)
          Gets the value at the given column and row index.
 Object getDataValueByPosition(int columnPosition, int rowPosition)
           
 int getDefaultColumnWidth()
           
 int getDefaultRowHeight()
           
 int getHeight()
          Returns the total height in pixels of this layer.
 int getPreferredColumnCount()
           
 int getPreferredHeight()
           
 int getPreferredRowCount()
           
 int getPreferredWidth()
           
 int getRowCount()
           
 int getRowHeightByPosition(int rowPosition)
          Returns the height in pixels of the given row.
 int getRowIndexByPosition(int rowPosition)
          This is the root coordinate system, so the row index is always equal to the row position.
 int getRowPositionByIndex(int rowIndex)
          This is the root coordinate system, so the row position is always equal to the row index.
 int getRowPositionByY(int y)
          Returns the row position that contains the given y coordinate.
 int getStartXOfColumnPosition(int columnPosition)
          Returns the x offset in pixels of the given column.
 int getStartYOfRowPosition(int rowPosition)
          Returns the y offset in pixels of the given row.
 ILayer getUnderlyingLayerByPosition(int columnPosition, int rowPosition)
           
 Collection<ILayer> getUnderlyingLayersByColumnPosition(int columnPosition)
           
 Collection<ILayer> getUnderlyingLayersByRowPosition(int rowPosition)
           
 int getWidth()
          Returns the total width in pixels of this layer.
 boolean isColumnPercentageSizing()
           
 boolean isColumnPercentageSizing(int position)
           
 boolean isColumnPositionResizable(int columnPosition)
           
 boolean isRowPercentageSizing()
           
 boolean isRowPercentageSizing(int position)
           
 boolean isRowPositionResizable(int rowPosition)
           
 void loadState(String prefix, Properties properties)
          Restore the state out of the given Properties identified by the specified prefix.
 int localToUnderlyingColumnPosition(int localColumnPosition)
          Convert a column position to the coordinates of the underlying layer.
 int localToUnderlyingRowPosition(int localRowPosition)
           
protected  void registerCommandHandlers()
          Layers should use this method to register their command handlers and call it from their constructor.
 void saveState(String prefix, Properties properties)
          Saves the state to the given Properties using the specified prefix.
 void setColumnPercentageSizing(boolean percentageSizing)
          Configures how the column sizing of this DataLayer is handled.
 void setColumnPercentageSizing(int position, boolean percentageSizing)
          Configures how the column sizing of this DataLayer is handled.
 void setColumnPositionResizable(int columnPosition, boolean resizable)
           
 void setColumnsResizableByDefault(boolean resizableByDefault)
           
 void setColumnWidthByPosition(int columnPosition, int width)
           
 void setColumnWidthByPosition(int columnPosition, int width, boolean fireEvent)
           
 void setColumnWidthPercentageByPosition(int columnPosition, int width)
           
protected  void setDataProvider(IDataProvider dataProvider)
           
 void setDataValue(int columnIndex, int rowIndex, Object newValue)
          Sets the value at the given column and row index.
 void setDataValueByPosition(int columnPosition, int rowPosition, Object newValue)
           
 void setDefaultColumnWidth(int width)
           
 void setDefaultColumnWidthByPosition(int columnPosition, int width)
           
 void setDefaultRowHeight(int height)
           
 void setDefaultRowHeightByPosition(int rowPosition, int height)
           
 void setRowHeightByPosition(int rowPosition, int height)
           
 void setRowHeightByPosition(int rowPosition, int height, boolean fireEvent)
           
 void setRowHeightPercentageByPosition(int rowPosition, int height)
           
 void setRowPercentageSizing(boolean percentageSizing)
          Configures how the row sizing of this DataLayer is handled.
 void setRowPercentageSizing(int position, boolean percentageSizing)
          Configures how the row sizing of this DataLayer is handled.
 void setRowPositionResizable(int rowPosition, boolean resizable)
           
 void setRowsResizableByDefault(boolean resizableByDefault)
           
 int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition)
           
 Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges)
           
 int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition)
           
 Collection<Range> underlyingToLocalRowPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingRowPositionRanges)
           
 
Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
addConfiguration, addLayerListener, clearConfiguration, configure, dispose, fireLayerEvent, getBoundsByPosition, getCellByPosition, getCellPainter, getClientAreaProvider, getConfigLabelAccumulator, getConfigLabelsByPosition, getDisplayModeByPosition, getLayerPainter, getRegionLabelsByXY, getRegionName, handleLayerEvent, hasLayerListener, registerCommandHandler, registerEventHandler, registerPersistable, removeLayerListener, setClientAreaProvider, setConfigLabelAccumulator, setLayerPainter, setRegionName, toString, unregisterCommandHandler, unregisterEventHandler, unregisterPersistable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayer
addLayerListener, configure, dispose, fireLayerEvent, getBoundsByPosition, getCellByPosition, getCellPainter, getClientAreaProvider, getConfigLabelsByPosition, getDisplayModeByPosition, getLayerPainter, getRegionLabelsByXY, hasLayerListener, registerCommandHandler, registerPersistable, removeLayerListener, setClientAreaProvider, unregisterCommandHandler, unregisterPersistable
 
Methods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayerListener
handleLayerEvent
 

Field Detail

PERSISTENCE_KEY_ROW_HEIGHT

public static final String PERSISTENCE_KEY_ROW_HEIGHT
See Also:
Constant Field Values

PERSISTENCE_KEY_COLUMN_WIDTH

public static final String PERSISTENCE_KEY_COLUMN_WIDTH
See Also:
Constant Field Values

DEFAULT_COLUMN_WIDTH

public static final int DEFAULT_COLUMN_WIDTH
See Also:
Constant Field Values

DEFAULT_ROW_HEIGHT

public static final int DEFAULT_ROW_HEIGHT
See Also:
Constant Field Values

dataProvider

protected IDataProvider dataProvider

columnWidthConfig

protected SizeConfig columnWidthConfig

rowHeightConfig

protected SizeConfig rowHeightConfig
Constructor Detail

DataLayer

public DataLayer(IDataProvider dataProvider)

DataLayer

public DataLayer(IDataProvider dataProvider,
                 int defaultColumnWidth,
                 int defaultRowHeight)

DataLayer

protected DataLayer()

DataLayer

protected DataLayer(int defaultColumnWidth,
                    int defaultRowHeight)
Method Detail

saveState

public void saveState(String prefix,
                      Properties properties)
Description copied from interface: IPersistable
Saves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.

Specified by:
saveState in interface IPersistable
Overrides:
saveState in class AbstractLayer
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)
Description copied from interface: IPersistable
Restore the state out of the given Properties identified by the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.

Specified by:
loadState in interface IPersistable
Overrides:
loadState in class AbstractLayer
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.

registerCommandHandlers

protected void registerCommandHandlers()
Description copied from class: AbstractLayer
Layers should use this method to register their command handlers and call it from their constructor. This allows easy overriding if required of command handlers

Overrides:
registerCommandHandlers in class AbstractLayer

getDataProvider

public IDataProvider getDataProvider()

setDataProvider

protected void setDataProvider(IDataProvider dataProvider)

getDataValue

public Object getDataValue(int columnIndex,
                           int rowIndex)
Gets the value at the given column and row index.

Parameters:
columnIndex -
rowIndex -
Returns:
the data value associated with the specified cell

setDataValue

public void setDataValue(int columnIndex,
                         int rowIndex,
                         Object newValue)
Sets the value at the given column and row index. Optional operation. Should throw UnsupportedOperationException if this operation is not supported.

Parameters:
columnIndex -
rowIndex -
newValue -

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface ILayer
Returns:
the number of columns in this coordinate model

getPreferredColumnCount

public int getPreferredColumnCount()
Specified by:
getPreferredColumnCount in interface ILayer

getColumnIndexByPosition

public int getColumnIndexByPosition(int columnPosition)
This is the root coordinate system, so the column index is always equal to the column position.

Specified by:
getColumnIndexByPosition in interface ILayer
Parameters:
columnPosition - a column position relative to this coordinate model
Returns:
an underlying non-transformed column index, or -1 if the given column position does not exist within this coordinate system

getColumnPositionByIndex

public int getColumnPositionByIndex(int columnIndex)
This is the root coordinate system, so the column position is always equal to the column index.

Specified by:
getColumnPositionByIndex in interface IUniqueIndexLayer

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)
Specified by:
underlyingToLocalColumnPosition in interface ILayer

underlyingToLocalColumnPositions

public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer,
                                                          Collection<Range> underlyingColumnPositionRanges)
Specified by:
underlyingToLocalColumnPositions in interface ILayer

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 width of this layer

getPreferredWidth

public int getPreferredWidth()
Specified by:
getPreferredWidth in interface ILayer

getDefaultColumnWidth

public int getDefaultColumnWidth()
Returns:
The default column width that is used if no specialized width is configured for a column.

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

setColumnWidthByPosition

public void setColumnWidthByPosition(int columnPosition,
                                     int width)

setColumnWidthByPosition

public void setColumnWidthByPosition(int columnPosition,
                                     int width,
                                     boolean fireEvent)

setColumnWidthPercentageByPosition

public void setColumnWidthPercentageByPosition(int columnPosition,
                                               int width)

setDefaultColumnWidth

public void setDefaultColumnWidth(int width)

setDefaultColumnWidthByPosition

public void setDefaultColumnWidthByPosition(int columnPosition,
                                            int width)

isColumnPositionResizable

public boolean isColumnPositionResizable(int columnPosition)
Specified by:
isColumnPositionResizable in interface ILayer

setColumnPositionResizable

public void setColumnPositionResizable(int columnPosition,
                                       boolean resizable)

setColumnsResizableByDefault

public void setColumnsResizableByDefault(boolean resizableByDefault)

getUnderlyingLayersByColumnPosition

public Collection<ILayer> getUnderlyingLayersByColumnPosition(int columnPosition)
Specified by:
getUnderlyingLayersByColumnPosition in interface ILayer

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface ILayer
Returns:
the number of rows in this coordinate model

getPreferredRowCount

public int getPreferredRowCount()
Specified by:
getPreferredRowCount in interface ILayer

getRowIndexByPosition

public int getRowIndexByPosition(int rowPosition)
This is the root coordinate system, so the row index is always equal to the row position.

Specified by:
getRowIndexByPosition in interface ILayer
Parameters:
rowPosition - a row position relative to this coordinate model
Returns:
an underlying non-transformed row index, or -1 if the given row position does not exist within this coordinate system

getRowPositionByIndex

public int getRowPositionByIndex(int rowIndex)
This is the root coordinate system, so the row position is always equal to the row index.

Specified by:
getRowPositionByIndex in interface IUniqueIndexLayer

localToUnderlyingRowPosition

public int localToUnderlyingRowPosition(int localRowPosition)
Specified by:
localToUnderlyingRowPosition in interface ILayer

underlyingToLocalRowPosition

public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer,
                                        int underlyingRowPosition)
Specified by:
underlyingToLocalRowPosition in interface ILayer

underlyingToLocalRowPositions

public Collection<Range> underlyingToLocalRowPositions(ILayer sourceUnderlyingLayer,
                                                       Collection<Range> underlyingRowPositionRanges)
Specified by:
underlyingToLocalRowPositions in interface ILayer

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 height of this layer

getPreferredHeight

public int getPreferredHeight()
Specified by:
getPreferredHeight in interface ILayer

getDefaultRowHeight

public int getDefaultRowHeight()
Returns:
The default row height that is used if no specialized height is configured for a row.

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

setRowHeightByPosition

public void setRowHeightByPosition(int rowPosition,
                                   int height)

setRowHeightByPosition

public void setRowHeightByPosition(int rowPosition,
                                   int height,
                                   boolean fireEvent)

setRowHeightPercentageByPosition

public void setRowHeightPercentageByPosition(int rowPosition,
                                             int height)

setDefaultRowHeight

public void setDefaultRowHeight(int height)

setDefaultRowHeightByPosition

public void setDefaultRowHeightByPosition(int rowPosition,
                                          int height)

isRowPositionResizable

public boolean isRowPositionResizable(int rowPosition)
Specified by:
isRowPositionResizable in interface ILayer

setRowPositionResizable

public void setRowPositionResizable(int rowPosition,
                                    boolean resizable)

setRowsResizableByDefault

public void setRowsResizableByDefault(boolean resizableByDefault)

getUnderlyingLayersByRowPosition

public Collection<ILayer> getUnderlyingLayersByRowPosition(int rowPosition)
Specified by:
getUnderlyingLayersByRowPosition in interface ILayer

getDataValueByPosition

public Object getDataValueByPosition(int columnPosition,
                                     int rowPosition)
Specified by:
getDataValueByPosition in interface ILayer

setDataValueByPosition

public void setDataValueByPosition(int columnPosition,
                                   int rowPosition,
                                   Object newValue)

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

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

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

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

getUnderlyingLayerByPosition

public ILayer getUnderlyingLayerByPosition(int columnPosition,
                                           int rowPosition)
Specified by:
getUnderlyingLayerByPosition in interface ILayer

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 co-ordinates using ILayerCommand.convertToTargetLayer(ILayer)

Specified by:
doCommand in interface ILayer
Overrides:
doCommand in class AbstractLayer
Parameters:
command - the command to perform
Returns:
true if the command has been handled, false otherwise

isColumnPercentageSizing

public boolean isColumnPercentageSizing()
Returns:
true if the column sizing is done by percentage calculation, false if the column sizing is done by pixel (default)

setColumnPercentageSizing

public void setColumnPercentageSizing(boolean percentageSizing)
Configures how the column sizing of this DataLayer is handled. Default is pixel sizing. If percentage sizing should be used you have to ensure that the size value for every column is set explicitly and that the sum of the column sizes doesn't exceed 100.

Parameters:
percentageSizing - true if the column sizing should be done by percentage calculation, false if the column sizing should be done by pixel (default)

isColumnPercentageSizing

public boolean isColumnPercentageSizing(int position)
Parameters:
position - The position which is asked for the percentage sizing configuration.
Returns:
true if the column sizing for the given position is done by percentage calculation, false if the column sizing is done by pixel (default)

setColumnPercentageSizing

public void setColumnPercentageSizing(int position,
                                      boolean percentageSizing)
Configures how the column sizing of this DataLayer is handled. Default is pixel sizing. If percentage sizing should be used you have to ensure that the size value for every column is set explicitly and that the sum of the column sizes doesn't exceed 100.

Parameters:
position - The position for which the sizing configuration should be set.
percentageSizing - true if the column sizing should be done by percentage calculation, false if the column sizing should be done by pixel (default)

isRowPercentageSizing

public boolean isRowPercentageSizing()
Returns:
true if the row sizing is done by percentage calculation, false if the row sizing is done by pixel (default)

setRowPercentageSizing

public void setRowPercentageSizing(boolean percentageSizing)
Configures how the row sizing of this DataLayer is handled. Default is pixel sizing. If percentage sizing should be used you have to ensure that the size value for every row is set explicitly and that the sum of the row sizes doesn't exceed 100.

Parameters:
percentageSizing - true if the row sizing should be done by percentage calculation, false if the row sizing should be done by pixel (default)

isRowPercentageSizing

public boolean isRowPercentageSizing(int position)
Parameters:
position - The position which is asked for the percentage sizing configuration.
Returns:
true if the row sizing for the given position is done by percentage calculation, false if the row sizing is done by pixel (default)

setRowPercentageSizing

public void setRowPercentageSizing(int position,
                                   boolean percentageSizing)
Configures how the row sizing of this DataLayer is handled. Default is pixel sizing. If percentage sizing should be used you have to ensure that the size value for every row is set explicitly and that the sum of the row sizes doesn't exceed 100.

Parameters:
position - The row position for which the sizing configuration should be set.
percentageSizing - true if the row sizing should be done by percentage calculation, false if the row sizing should be done by pixel (default)


Copyright © 2015. All rights reserved.