|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
com.wordpress.tipsforjava.swing.table.RowTableModel
abstract class RowTableModel extends AbstractTableModel
A TableModel that better supports the processing of rows of data. That is, the data is treated more like a row than an individual cell. Hopefully this class can be used as a parent class instead of extending the AbstractTableModel when you need custom models that contain row related data. A few methods have also been added to make it easier to customize properties of the model, such as the column class and column editability. Any class that extends this class must make sure to invoke the setRowClass() and setDataAndColumnNames() methods either indirectly, by using the various constructors, or indirectly.
| Field Summary | |
|---|---|
protected Class[] |
columnClasses
|
protected List |
columnNames
|
protected Boolean[] |
isColumnEditable
|
private boolean |
isModelEditable
|
protected List |
modelData
|
private Class |
rowClass
|
| Constructor Summary | |
protected RowTableModel(Class rowClass)
Constructs a |
|
protected RowTableModel(List columnNames)
Constructs a |
|
protected RowTableModel(List modelData, List columnNames)
Constructs a |
|
protected RowTableModel(List modelData, List columnNames, Class rowClass)
Full Constructor for creating a |
|
| Method Summary | |
|---|---|
void
|
addRow(Object rowData)
Adds a row of data to the end of the model. |
static String
|
formatColumnName(String columnName)
|
Class
|
getColumnClass(int column)
Returns the Class of the queried |
int
|
getColumnCount()
Returns the number of columns in this table model. |
String
|
getColumnName(int column)
Returns the column name. |
Object
|
getRow(int row)
Returns the Object of the requested |
int
|
getRowCount()
Returns the number of rows in this table model. |
Object[]
|
getRowsAsArray(int... rows)
Returns an array of Objects for the requested |
List
|
getRowsAsList(int... rows)
Returns a List of Objects for the requested |
void
|
insertRow(int row, Object rowData)
Insert a row of data at the |
void
|
insertRows(int row, List rowList)
Insert multiple rows of data at the |
void
|
insertRows(int row, Object[] rowArray)
Insert multiple rows of data at the |
boolean
|
isCellEditable(int row, int column)
Returns true regardless of parameter values. |
void
|
moveRow(int start, int end, int to)
Moves one or more rows from the inlcusive range |
void
|
removeRowRange(int start, int end)
Remove the specified rows from the model. |
void
|
removeRows(int... rows)
Remove the specified rows from the model. |
void
|
replaceRow(int row, Object rowData)
Replace a row of data at the |
void
|
setColumnClass(int column, Class columnClass)
Sets the Class for the specified column. |
void
|
setColumnEditable(int column, boolean isEditable)
Sets the editability for the specified column. |
protected void
|
setDataAndColumnNames(List modelData, List columnNames)
Reset the data and column names of the model. |
void
|
setModelEditable(boolean isModelEditable)
Set the ability to edit cell data for the entire table |
protected void
|
setRowClass(Class rowClass)
The class of the Row being stored in the TableModel |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
protected Class[] columnClasses
protected List columnNames
protected Boolean[] isColumnEditable
private boolean isModelEditable
protected List modelData
private Class rowClass
| Constructor Detail |
|---|
protected RowTableModel(Class rowClass)
RowTableModel with the row class.
This value is used by the getRowsAsArray() method.
Sub classes creating a model using this constructor must make sure
to invoke the setDataAndColumnNames() method.
rowClass - the class of row data to be added to the model
protected RowTableModel(List columnNames)
RowTableModel with column names.
Each column's name will be taken from the columnNames
List and the number of colums is determined by thenumber of items
in the columnNames List.
Sub classes creating a model using this constructor must make sure
to invoke the setRowClass() method.
columnNames - List containing the names
of the new columns
protected RowTableModel(List modelData, List columnNames)
RowTableModel with initial data and
customized column names.
Each item in the modelData List must also be a List Object
containing items for each column of the row.
Each column's name will be taken from the columnNames
List and the number of colums is determined by thenumber of items
in the columnNames List.
Sub classes creating a model using this constructor must make sure
to invoke the setRowClass() method.
modelData - the data of the tablecolumnNames - List containing the names
of the new columns
protected RowTableModel(List modelData, List columnNames, Class rowClass)
RowTableModel.
Each item in the modelData List must also be a List Object
containing items for each column of the row.
Each column's name will be taken from the columnNames
List and the number of colums is determined by thenumber of items
in the columnNames List.
modelData the - data of the tablecolumnNames List - containing the names
of the new columnsrowClass - the class of row data to be added to the model
| Method Detail |
|---|
public void addRow(Object rowData)
rowData - data of the row being added
public static String formatColumnName(String columnName)
public Class getColumnClass(int column)
column.
First it will check to see if a Class has been specified for the
column by using the setColumnClass method.
If not, then the superclass value is returned.
column - the column being queried
public int getColumnCount()
public String getColumnName(int column)
columnNames. If
columnNames does not have an entry for this index
then the default name provided by the superclass is returned
public Object getRow(int row)
row.
public int getRowCount()
ssWarnings("unchecked")
public
public Object[] getRowsAsArray(int... rows)
rows.
public List getRowsAsList(int... rows)
rows.
public void insertRow(int row, Object rowData)
row location in the model.
Notification of the row being added will be generated.
row - row in the model where the data will be insertedrowData - data of the row being added
public void insertRows(int row, List rowList)
row location in the model.
Notification of the row being added will be generated.
row - row in the model where the data will be insertedrowList - each item in the list is a separate row of data
public void insertRows(int row, Object[] rowArray)
row location in the model.
Notification of the row being added will be generated.
row - row in the model where the data will be insertedrowArray - each item in the Array is a separate row of data
public boolean isCellEditable(int row, int column)
row - the row whose value is to be queriedcolumn the - column whose value is to be queried
public void moveRow(int start, int end, int to)
start to
end to the to position in the model.
After the move, the row that was at index start
will be at index to.
This method will send a tableRowsUpdated notification
message to all the listeners.
Examples of moves:1. moveRow(1,3,5); a|B|C|D|e|f|g|h|i|j|k - before a|e|f|g|h|B|C|D|i|j|k - after
2. moveRow(6,7,1); a|b|c|d|e|f|G|H|i|j|k - before a|G|H|b|c|d|e|f|i|j|k - after
start - the starting row index to be movedend - the ending row index to be movedto - the destination of the rows to be moved
public void removeRowRange(int start, int end)
start - starting row indexend - ending row index
public void removeRows(int... rows)
rows - array containing indexes of rows to be removed
public void replaceRow(int row, Object rowData)
row location in the model.
Notification of the row being replaced will be generated.
row - row in the model where the data will be replacedrowData - data of the row to replace the existing data
public void setColumnClass(int column, Class columnClass)
column - the column whose Class is being changedcolumnClass - the new Class of the column
public void setColumnEditable(int column, boolean isEditable)
column - the column whose Class is being changedisEditable - indicates if the column is editable or not
protected void setDataAndColumnNames(List modelData, List columnNames)
modelData - the data of the tablecolumnNames - List containing the names
of the new columns
public void setModelEditable(boolean isModelEditable)
isModelEditable - true/false
protected void setRowClass(Class rowClass)
rowClas - the class of the row
Groovy Documentation