Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.table
Interface ListTableModel

All Superinterfaces:
TableModel
All Known Implementing Classes:
CachedListTableModel, DefaultListTableModel, FilterTableModel, ListTableMap, ListTableModelWrapper, ObjectTableModel, SortTableModel, ThreadedListTableModel, TreeTableModel

public interface ListTableModel
extends TableModel

The ListTableModel interface defines methods for manipulating the data of a tabular data model. It also defines methods for generating TableModelEvents and dispatching them to the listeners.

The seven fire methods inherit their names from the fire methods of AbstractTableModel abstract class. The names of these methods were chosen this way to make ListTableModel backward compatible with AbstractTableModel and DefaultTableModel.

ListTableModel assumes that the data are kept in a List structure, e.g. Vector, ArrayList etc., as is the case with DefaultTableModel. This list structure is returned with ListTableModel.getRows(). The elements in the list represent the actual row data, which can be any java object and not just List objects. To get a reference to a specific column of a row data, we use ListTableModel.getCellValue(Object row, int index).
e.g. for a DefaultTableModel this would be implemented as return ((Vector) row).get(index);

Furthermore, five additional methods manipulate the data. These are ListTableModel.addRow(java.lang.Object), ListTableModel.addRows(java.util.List), ListTableModel.clear(), ListTableModel.removeRow(int) and ListTableModel.removeRows(int[]).

The tablemodels in this library (SortTableModel, FilterTableModel and TreeTableModel) all require a ListTableModel in their constructor. Therefore, if you want to continue to use your custom tablemodel in conjunction with these classes, your tablemodel should implement the ListTableModel interface. This can be done very easily.

E.g. assuming your custom TableModel extends DefaultTableModel, you need to provide an implementation of the following methods:

 public void addRow(Object row);
 public void addRows(List rowData);
 public void clear();
 public List getRows();
 public Object getCellValue(Object o, int index);
 public void removeRow(int row);
 public void removeRows(int[] deletedRows);
 
, in which you most definitely would somehow manipulate the dataVector field of DefaultTableModel.


Method Summary
 void addRow(Object row)
          Adds a row to the end of the model.
 void addRows(List addedRows)
          Adds a list of rows to the end of the model.
 void clear()
          Clears the model of any data.
 void fireTableCellUpdated(int row, int column)
          Notify all listeners that the value of the cell at (row, column) has been updated.
 void fireTableChanged(TableModelEvent e)
          Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 void fireTableDataChanged()
          Notify all listeners that all cell values in the table's rows may have changed.
 void fireTableRowsDeleted(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted.
 void fireTableRowsInserted(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted.
 void fireTableRowsUpdated(int firstRow, int lastRow)
          Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated.
 void fireTableStructureChanged()
          Notify all listeners that the table's structure has changed.
 Object getCellValue(Object row, int index)
          Returns the Object found at index of row passed as a parameter.
 List getRows()
          Returns the data of this tablemodel
 void removeRow(int row)
          Removes a row from the data model
 void removeRows(int[] deletedRows)
          Removes a few rows from the data model
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 

Method Detail

addRow

void addRow(Object row)
Adds a row to the end of the model.

Parameters:
row - the row being added

addRows

void addRows(List addedRows)
Adds a list of rows to the end of the model.

addedRows contains objects representing the actual rows being added. e.g. Vector, for DefaultTableModel.

Parameters:
addedRows - the rows being added.

clear

void clear()
Clears the model of any data.


fireTableCellUpdated

void fireTableCellUpdated(int row,
                          int column)
Notify all listeners that the value of the cell at (row, column) has been updated.


fireTableChanged

void fireTableChanged(TableModelEvent e)
Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model.


fireTableDataChanged

void fireTableDataChanged()
Notify all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table, ie. the order of the columns is assumed to be the same.


fireTableRowsDeleted

void fireTableRowsDeleted(int firstRow,
                          int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted.


fireTableRowsInserted

void fireTableRowsInserted(int firstRow,
                           int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted.


fireTableRowsUpdated

void fireTableRowsUpdated(int firstRow,
                          int lastRow)
Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated.


fireTableStructureChanged

void fireTableStructureChanged()
Notify all listeners that the table's structure has changed. The number of columns in the table, and the names and types of the new columns may be different from the previous state. If the JTable recieves this event and its autoCreateColumnsFromModel flag is set it discards any TableColumns that it had and reallocates default ones in the order they appear in the model. This is the same as calling setModel(TableModel) on the JTable.


getCellValue

Object getCellValue(Object row,
                    int index)
Returns the Object found at index of row passed as a parameter.

Parameters:
row - the row data
index - an index
Returns:
the object found at column index of the row data row

getRows

List getRows()
Returns the data of this tablemodel

Returns:
the rows of the datamodel as a List

removeRow

void removeRow(int row)
Removes a row from the data model

Parameters:
row - the index of the row being removed

removeRows

void removeRows(int[] deletedRows)
Removes a few rows from the data model

Parameters:
deletedRows - an integer array that contains indexes of the rows being deleted

Copyright © 2011 Citra Technologies. All Rights Reserved.