GridTableBase is an advanced way of supplying data to the cells in a
Grid. It is particularly useful for working with very large
grids, and for closely connecting the Grid display with an underlying
data source such as a SQL database. It can make for more efficient and
cleaner code.
In a standard Grid, the size of the grid is specified using
Grid#create_table, and then the contents of
each cell specified using
Grid#set_value. Whilst this is this is
straightforward for smaller grids, with very large grids it may become
inefficient and slow to set all the values when only a small proportion
are actually shown to the user at any one time. If the data source is,
for example, a SQL database, the GUI event handling code in the grid,
and the code to fetch and set rows in the database can become mixed up
in the Grid class.
GridTableBase is a class which can supply, on
demand, cell values and visual appearance attributes as particular cells
are displayed in a Grid.
To use this class, you must derive your own Ruby class from it, and
implement at set of methods to return the grid’s size, cell values, and
visual attributes. Then, instead of calling “Grid#create_table” on the
grid to set its size, call “Grid#set_table” and pass in an instance of
your GridTableBase subclass.
The number of methods that have to be defined in a subclass of
GridTableBase will depend on the interactions that are permitted by the
Grid class it will be associated with. The minimal set of
methods that must be implemented in a read-only grid is:
In addition, you may wish to override:
In order to use custom GridCellRenderers or
GridCellEditors for particular cells, you will
need first to define the grid’s data types using
Grid#register_data_type. This will
link appropriate cell renderers and editors to particular named data
types. Then, your GridTableBase class should override the following
method to return the type name for each cell in the table:
Note that you must not try to provide custom editors or renderers to
specific cells by associating them with the GridCellAttr returned by the
get_attr method of your Table class.
In order for a user to be able to edit values within the grid, you must
also override:
This will be called when the user finishes editing a cell’s value; it is
up to your class to decide how to respond (for example, storing the
value back in a database). Further methods will need to be provided if
the user is permitted to add or delete columns and rows.
Creates a new GridTable. If you define your own initialize
function in
your subclass of GridTableBase, you must ensure you call super
within
that constructor.
Should return the total number of rows in the grid. You must override these
functions in a derived table class.
Should return the total number of columns in the grid. You must override
this functions in a derived table class.
Should return true if a cell is empty. You must override this function
in a derived table class.
Should return the content of the specified cell as a Ruby string. You
must override this function in a derived table class.
Called when the value of a cell is updated by the user.
This method should return the name of the data type in the given
cell. This is useful to enable different custom cell renderers and
editors to be used for different cells in the grid.The name should match
one that has previously been set in the grid using
Grid#register_data_type.
For user defined types
Overriding these is optional
Handle setting the column label.
Change row/col number in attribute if needed
Should return a grid cell attribute that should be
applied to the cell specified by row and column_. This can set the
cell’s text and background colour. However, it should not associate an
editor or renderer with a cell; instead use
get_type_namegettypename to link data types to
specific presentations.
Note that this method must return a new GridCellAttr for each call; do
not attempt to share the same GridCellAttr between cells. If you wish
to use the same style across a whole grid, create the attribute as a
class variable or constant, then call its
clone method to return a copy for
each call to get_attr.
Set the attribute for a cell.
[This page automatically generated from the Textile source at 2023-06-13 21:31:36 +0000]