de.kupzog.ktable
Class KTableDefaultModel

java.lang.Object
  extended by de.kupzog.ktable.KTableDefaultModel
All Implemented Interfaces:
KTableModel
Direct Known Subclasses:
BooleanModelExample, KTableSortedModel, SpanModelExample, TextModelExample

public abstract class KTableDefaultModel
extends java.lang.Object
implements KTableModel

Default implementation that handles column widths and row height.

Provides a wrapper framework that allows subclasses to transparently change the location of cells in the displayed table, e.g. for sorting.

Author:
Lorenz Maierhofer

Constructor Summary
KTableDefaultModel()
           
 
Method Summary
 org.eclipse.swt.graphics.Point belongsToCell(int col, int row)
          Calls doBelongsToCell to get the cell span.
 org.eclipse.swt.graphics.Point doBelongsToCell(int col, int row)
          Return (0,0) if cell should stay in its own area, or return the cell that should overlap this cell.
abstract  KTableCellEditor doGetCellEditor(int col, int row)
          Returns the celleditor for the given table cell.
abstract  KTableCellRenderer doGetCellRenderer(int col, int row)
          Called to retrieve the cell renderer for a given cell.
abstract  int doGetColumnCount()
          This function tells the KTable how many columns have to be displayed.
abstract  java.lang.Object doGetContentAt(int col, int row)
          Returns the content at the given cell.
abstract  int doGetRowCount()
          This function tells the KTable how many rows have to be displayed.
 java.lang.String doGetTooltipAt(int col, int row)
          Returns the tooltip text for the given cell.
abstract  void doSetContentAt(int col, int row, java.lang.Object value)
          Called to change the cell value in the model.
 KTableCellEditor getCellEditor(int col, int row)
          Delegates the real editor retrieval to the method doGetCellEditor(int, int).
 KTableCellRenderer getCellRenderer(int col, int row)
          Calls the method doGetCellRenderer(int, int) to retrieve the cell renderer for a cell.
 int getColumnCount()
          This function tells the KTable how many columns have to be displayed.
 int getColumnWidth(int col)
          Each column can have its individual width.
 java.lang.Object getContentAt(int col, int row)
          Delegates the real content retrieval to the method doGetContentAt(int, int).
 int getFirstRowHeight()
          Deprecated. Use getRowHeight(0) instead.
 int getFixedColumnCount()
           
 int getFixedRowCount()
           
abstract  int getInitialColumnWidth(int column)
          Returns the initial column width for the column index given.
 int getInitialFirstRowHeight()
          Deprecated. Implement getInitialRowHeight(0) instead!
abstract  int getInitialRowHeight(int row)
           
 int getRowCount()
          This function tells the KTable how many rows have to be displayed.
 int getRowHeight(int row)
          All rows except the first row have the same height.
 java.lang.String getTooltipAt(int col, int row)
          Returns the tooltip for the given cell.
 void initialize()
          This method initializes the provided baseimplementation of the model properly.
 boolean isFixedCell(int col, int row)
          Returns wether a given cell is fixed.
 boolean isHeaderCell(int col, int row)
          Returns wether a given cell is a header cell (in the range of fixedHeader)
 int mapRowIndexToModel(int shownRow)
          Maps the given row index that references a visible row, to one that is internally used in the tablemodel.
 int mapRowIndexToTable(int modelRow)
          Maps the given row index from a model-internal to one that references visualized table rows.
 void setColumnWidth(int col, int value)
          Each column can have its individual width.
 void setContentAt(int col, int row, java.lang.Object value)
          Calls the method doSetContentAt(int, int, Object) to actually set the content of a table cell to the model.
 void setFirstRowHeight(int value)
          Deprecated. Use setRowHeight(0, value) instead.
 void setRowHeight(int row, int value)
          If the user resizes a row, the model has to keep track of these changes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.kupzog.ktable.KTableModel
getFixedHeaderColumnCount, getFixedHeaderRowCount, getFixedSelectableColumnCount, getFixedSelectableRowCount, getRowHeightMinimum, isColumnResizable, isRowResizable
 

Constructor Detail

KTableDefaultModel

public KTableDefaultModel()
Method Detail

initialize

public void initialize()
This method initializes the provided baseimplementation of the model properly.

This is not done in the constructor because there might be cases where some base data is set in the constructor and must be present for properly working model getter methods.

MUST BE CALLED BY ANY SUBCLASS!


getColumnWidth

public int getColumnWidth(int col)
Description copied from interface: KTableModel
Each column can have its individual width. The model has to manage these widths and return the values with this function.

Specified by:
getColumnWidth in interface KTableModel
Parameters:
col - The column index.
Returns:
return the current column width.

getInitialColumnWidth

public abstract int getInitialColumnWidth(int column)
Returns the initial column width for the column index given. Note that if resize is enabled, this value might not be the real width of a column. The value returned by getColumnWidth() corresponds to the real width used when painting the table!

Parameters:
column - The column index
Returns:
returns the initial width of the column.

getRowHeight

public int getRowHeight(int row)
Description copied from interface: KTableModel
All rows except the first row have the same height.

Specified by:
getRowHeight in interface KTableModel
Parameters:
row - The row index for the row height.
Returns:
Returns the current row height.

getInitialRowHeight

public abstract int getInitialRowHeight(int row)
Parameters:
row - The row index.
Returns:
Returns the initial row height that should be used on normal cells. If resize is enabled, the value returned by getRowHeight(int) might not always be this value!

getFirstRowHeight

public int getFirstRowHeight()
Deprecated. Use getRowHeight(0) instead.

Returns:
Returns the height of the first row. Adapts to the value returned by the method getInitialFirstRowHeight() as long as no value is set via setFirstRowHeight(int).
See Also:
setFirstRowHeight(int), getInitialFirstRowHeight()

getInitialFirstRowHeight

public int getInitialFirstRowHeight()
Deprecated. Implement getInitialRowHeight(0) instead!

Implement to specify the height of the first row. This value might be overwritten when setFirstRowHeight() is called.

Returns:
Should return the height of the first row in the table.
See Also:
setFirstRowHeight(int);

setColumnWidth

public void setColumnWidth(int col,
                           int value)
Description copied from interface: KTableModel
Each column can have its individual width. The model has to manage these widths. If the user resizes a column, the model has to keep track of these changes. The model is informed about such a resize by this method. (view updates are managed by the table)

Specified by:
setColumnWidth in interface KTableModel
Parameters:
col - the column index
value - The width in pixels to set for the given column.

setRowHeight

public void setRowHeight(int row,
                         int value)
Description copied from interface: KTableModel
If the user resizes a row, the model has to keep track of these changes. The model is informed about such a resize by this method. (view updates are managed by the table)

Specified by:
setRowHeight in interface KTableModel
Parameters:
row - The row index.
value - The height of all except the first row.

setFirstRowHeight

public void setFirstRowHeight(int value)
Deprecated. Use setRowHeight(0, value) instead.

Sets the row height for the first row.


getContentAt

public java.lang.Object getContentAt(int col,
                                     int row)
Delegates the real content retrieval to the method doGetContentAt(int, int).

Specified by:
getContentAt in interface KTableModel
See Also:
KTableModel.getContentAt(int, int)

doGetContentAt

public abstract java.lang.Object doGetContentAt(int col,
                                                int row)
Returns the content at the given cell.

Parameters:
col - The column index.
row - The row index.
Returns:
Returns the content of the cell thats string form is shown in the table cell.

getTooltipAt

public java.lang.String getTooltipAt(int col,
                                     int row)
Returns the tooltip for the given cell.

Simply calls the method doGetTooltipAt().

Specified by:
getTooltipAt in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns the text that should be displayed when the tooltip for the cell is shown to the user.
See Also:
KTableModel.getTooltipAt(int, int)

doGetTooltipAt

public java.lang.String doGetTooltipAt(int col,
                                       int row)
Returns the tooltip text for the given cell. Implement this method rather than getTooltipAt().

Parameters:
col - The column index.
row - The row index.
Returns:
Returns the tooltip text for the cell. Default: None.

getCellEditor

public KTableCellEditor getCellEditor(int col,
                                      int row)
Delegates the real editor retrieval to the method doGetCellEditor(int, int).

Specified by:
getCellEditor in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns an instance of KTableCellEditor that will be responsible of showing an editor control and writing back the changed value by calling setContentAt().
See Also:
KTableModel.getCellEditor(int, int)

doGetCellEditor

public abstract KTableCellEditor doGetCellEditor(int col,
                                                 int row)
Returns the celleditor for the given table cell.

Parameters:
col - The column index.
row - The row index.
Returns:
Returns the cell editor to use, or null if none.

setContentAt

public void setContentAt(int col,
                         int row,
                         java.lang.Object value)
Calls the method doSetContentAt(int, int, Object) to actually set the content of a table cell to the model.

Specified by:
setContentAt in interface KTableModel
Parameters:
col - The column index.
row - The row index.
See Also:
KTableModel.setContentAt(int, int, java.lang.Object)

doSetContentAt

public abstract void doSetContentAt(int col,
                                    int row,
                                    java.lang.Object value)
Called to change the cell value in the model.

Parameters:
col - The column index
row - The row index
value - The new value to set in the model.

getCellRenderer

public KTableCellRenderer getCellRenderer(int col,
                                          int row)
Calls the method doGetCellRenderer(int, int) to retrieve the cell renderer for a cell.

Specified by:
getCellRenderer in interface KTableModel
Parameters:
col - The column index
row - The row index
Returns:
Returns the cell renderer that is responsible for drawing the cell.
See Also:
KTableModel.getCellRenderer(int, int)

doGetCellRenderer

public abstract KTableCellRenderer doGetCellRenderer(int col,
                                                     int row)
Called to retrieve the cell renderer for a given cell.

Parameters:
col - the column index
row - The row index
Returns:
Returns a cellrenderer that renders the cell in the KTable.

isFixedCell

public boolean isFixedCell(int col,
                           int row)
Returns wether a given cell is fixed.

Parameters:
col - The column index
row - the row index
Returns:
returns true if the cell is fixed, false otherwise.

isHeaderCell

public boolean isHeaderCell(int col,
                            int row)
Returns wether a given cell is a header cell (in the range of fixedHeader)

Parameters:
col - the column index
row - the row index
Returns:
returns true if the cell is fixed AND a header cell, false otherwise.

getFixedRowCount

public int getFixedRowCount()
Returns:
Returns the total number of fixed rows in the table. This is nothing else than the sum of header rows and selectable fixed rows.
See Also:
KTableModel.getFixedHeaderRowCount(), KTableModel.getFixedSelectableRowCount()

getFixedColumnCount

public int getFixedColumnCount()
Returns:
Returns the total number of fixed columns in the table. This is nothing else than the sum of header columns and selectable fixed columns.
See Also:
KTableModel.getFixedHeaderColumnCount(), KTableModel.getFixedSelectableColumnCount()

getRowCount

public int getRowCount()
Description copied from interface: KTableModel
This function tells the KTable how many rows have to be displayed.

KTable counts header rows as normal rows, so the number of header rows has to be added to the number of data rows. The function must at least return the number of fixed (header + selectable) rows.

Specified by:
getRowCount in interface KTableModel
Returns:
The number of rows in the table, including the fixed rows. Calls the client method that should be implemented instead of this method.
See Also:
doGetRowCount()

doGetRowCount

public abstract int doGetRowCount()
This function tells the KTable how many rows have to be displayed.

KTable counts header rows as normal rows, so the number of header rows has to be added to the number of data rows. The function must at least return the number of fixed (header + selectable) rows.

Returns:
The number of rows in the table, including the fixed rows.

getColumnCount

public int getColumnCount()
Description copied from interface: KTableModel
This function tells the KTable how many columns have to be displayed.

It must at least return the number of fixed and fixed selectable Columns.

Specified by:
getColumnCount in interface KTableModel
Returns:
The number of columns in the table, including the fixed columns. Calls the client method that should be implemented instead of this method.
See Also:
doGetColumnCount()

doGetColumnCount

public abstract int doGetColumnCount()
This function tells the KTable how many columns have to be displayed.

It must at least return the number of fixed and fixed selectable Columns. So the easiest way is to return the number of normal columns and add the value of getFixedColumnCount().

Returns:
Returns the number of columns in the table, including all fixed columns.

belongsToCell

public org.eclipse.swt.graphics.Point belongsToCell(int col,
                                                    int row)
Calls doBelongsToCell to get the cell span. Never overwrite this method, but implement doBelongsToCell().

Specified by:
belongsToCell in interface KTableModel
Parameters:
col - the column index
row - the row index
Returns:
Return the given cell, or a cell the given cell should be merged with. Point.x corresponds to column index, Point.y corresponds to row index.
See Also:
KTableModel.belongsToCell(int, int)

doBelongsToCell

public org.eclipse.swt.graphics.Point doBelongsToCell(int col,
                                                      int row)
Return (0,0) if cell should stay in its own area, or return the cell that should overlap this cell.
Overwrite this rather than belongsToCell()!

Defaults to no spanning.

See Also:
KTableModel.belongsToCell(int, int).

mapRowIndexToModel

public int mapRowIndexToModel(int shownRow)
Maps the given row index that references a visible row, to one that is internally used in the tablemodel.
This allows different tablemodels (such as the sorted table model) to rearrange rows flexibly. This visual rearrangement leads to changed shown row indices, but using this method, the model-internal row indices stay the same.

Parameters:
shownRow - The row index as displayed by the KTable.
Returns:
Returns the row index as used in the model. This stays unchanged even if the visual arrangement is changed (e.g. when sorting the talbe).

mapRowIndexToTable

public int mapRowIndexToTable(int modelRow)
Maps the given row index from a model-internal to one that references visualized table rows. This is usually used to do something with the KTable from within the tablemodel.

Parameters:
modelRow - The row index as used in the model.
Returns:
Returns the row index as needed/used by the KTable to display the data.