Extension SDK 10.1.2

oracle.ide.controls
Class DefaultListTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byoracle.ide.controls.DefaultListTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
InputTableModel

public class DefaultListTableModel
extends javax.swing.table.AbstractTableModel
implements java.io.Serializable

This is an implementation of TableModel that uses a List of Lists to store the cell value objects.

See Also:
TableModel, getDataList(), Serialized Form

Field Summary
protected  java.util.ArrayList columnIdentifiers
          The List of column identifiers.
protected  java.util.ArrayList dataList
          The List of Lists of Object values.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DefaultListTableModel()
          Constructs a default DefaultTableModel which is a table of zero columns and zero rows.
DefaultListTableModel(int numRows, int numColumns)
          Constructs a DefaultTableModel with numRows and numColumns of null object values.
DefaultListTableModel(java.util.List columnNames, int numRows)
          Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values.
DefaultListTableModel(java.util.List data, java.util.List columnNames)
          Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataList method.
DefaultListTableModel(java.lang.Object[][] data, java.lang.Object[] columnNames)
          Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataList method.
DefaultListTableModel(java.lang.Object[] columnNames, int numRows)
          Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values.
 
Method Summary
 void addColumn(java.lang.Object columnName)
          Adds a column to the model.
 void addColumn(java.lang.Object columnName, java.util.List columnData)
          Adds a column to the model.
 void addColumn(java.lang.Object columnName, java.lang.Object[] columnData)
          Adds a column to the model.
 void addRow(java.util.List rowData)
          Adds a row to the end of the model.
 void addRow(java.lang.Object[] rowData)
          Adds a row to the end of the model.
protected static java.util.List convertToList(java.lang.Object[] anArray)
          Returns a list that contains the same objects as the array.
protected static java.util.List convertToList(java.lang.Object[][] anArray)
          Returns a list of lists that contains the same objects as the array.
 int getColumnCount()
          Returns the number of columns in this data table.
 java.lang.String getColumnName(int column)
          Returns the column name.
 java.util.List getDataList()
          Returns the List of Lists that contains the table's data values.
 int getRowCount()
          Returns the number of rows in this data table.
 java.lang.Object getValueAt(int row, int column)
          Returns an attribute value for the cell at row and column.
 void insertRow(int row, java.util.List rowData)
          Inserts a row at row in the model.
 void insertRow(int row, java.lang.Object[] rowData)
          Inserts a row at row in the model.
 boolean isCellEditable(int row, int column)
          Returns true regardless of parameter values.
 boolean isEditable()
          Returns the editable state of the default table model
 void moveRow(int startIndex, int endIndex, int toIndex)
          Moves one or more rows starting at startIndex to endIndex in the model to the toIndex.
 void newDataAvailable(javax.swing.event.TableModelEvent event)
          Equivalent to fireTableChanged.
 void newRowsAdded(javax.swing.event.TableModelEvent event)
          Ensures that the new rows have the correct number of columns.
 void removeRow(int row)
          Removes the row at row from the model.
 void rowsRemoved(javax.swing.event.TableModelEvent event)
          Equivalent to fireTableChanged.
 void setColumnCount(int columnCount)
          Sets the number of columns in the model.
 void setColumnIdentifiers(java.util.List newIdentifiers)
          Replaces the column identifiers in the model.
 void setColumnIdentifiers(java.lang.Object[] newIdentifiers)
          Replaces the column identifiers in the model.
 void setDataList(java.util.List newData, java.util.List columnNames)
          Replaces the current dataList instance variable with the new List of rows, newData.
 void setDataList(java.lang.Object[][] newData, java.lang.Object[] columnNames)
          Replaces the value in the dataList instance variable with the values in the array newData.
 void setEditable(boolean isEditable)
          Sets the editable state of the default table model
 void setNumRows(int newSize)
          Obsolete as of Java 2 platform v1.3.
 void setRowCount(int rowCount)
          Sets the number of rows in the model.
 void setValueAt(java.lang.Object aValue, int row, int column)
          Sets the object value for the cell at column and row.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataList

protected java.util.ArrayList dataList
The List of Lists of Object values.


columnIdentifiers

protected java.util.ArrayList columnIdentifiers
The List of column identifiers.

Constructor Detail

DefaultListTableModel

public DefaultListTableModel()
Constructs a default DefaultTableModel which is a table of zero columns and zero rows.


DefaultListTableModel

public DefaultListTableModel(int numRows,
                             int numColumns)
Constructs a DefaultTableModel with numRows and numColumns of null object values.

Parameters:
numRows - the number of rows the table holds
numColumns - the number of columns the table holds
See Also:
setValueAt(java.lang.Object, int, int)

DefaultListTableModel

public DefaultListTableModel(java.util.List columnNames,
                             int numRows)
Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values. Each column's name will be taken from the columnNames list.

Parameters:
columnNames - list containing the names of the new columns. If this is null then the model has no columns
numRows - the number of rows the table holds
See Also:
setDataList(java.util.List, java.util.List), setValueAt(java.lang.Object, int, int)

DefaultListTableModel

public DefaultListTableModel(java.lang.Object[] columnNames,
                             int numRows)
Constructs a DefaultTableModel with as many columns as there are elements in columnNames and numRows of null object values. Each column's name will be taken from the columnNames array.

Parameters:
columnNames - array containing the names of the new columns. If this is null then the model has no columns
numRows - the number of rows the table holds
See Also:
setDataList(java.util.List, java.util.List), setValueAt(java.lang.Object, int, int)

DefaultListTableModel

public DefaultListTableModel(java.util.List data,
                             java.util.List columnNames)
Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataList method.

Parameters:
data - the data of the table
columnNames - list containing the names of the new columns
See Also:
getDataList(), setDataList(java.util.List, java.util.List)

DefaultListTableModel

public DefaultListTableModel(java.lang.Object[][] data,
                             java.lang.Object[] columnNames)
Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataList method. The first index in the Object[][] array is the row index and the second is the column index.

Parameters:
data - the data of the table
columnNames - the names of the columns
See Also:
getDataList(), setDataList(java.util.List, java.util.List)
Method Detail

getDataList

public java.util.List getDataList()
Returns the List of Lists that contains the table's data values. The lists contained in the outer list are each a single row of values. In other words, to get to the cell at row 1, column 5:

((List)getDataList().elementAt(1)).elementAt(5);

Returns:
the list of lists containing the tables data values
See Also:
newDataAvailable(javax.swing.event.TableModelEvent), newRowsAdded(javax.swing.event.TableModelEvent), setDataList(java.util.List, java.util.List)

setDataList

public void setDataList(java.util.List newData,
                        java.util.List columnNames)
Replaces the current dataList instance variable with the new List of rows, newData. columnNames are the names of the new columns. The first name in columnNames is mapped to column 0 in newData. Each row in newData is adjusted to match the number of columns in columnNames either by truncating the List if it is too long, or adding null values if it is too short.

Parameters:
newData - the new data list
columnNames - the names of the columns
See Also:
newDataAvailable(javax.swing.event.TableModelEvent), getDataList()

setDataList

public void setDataList(java.lang.Object[][] newData,
                        java.lang.Object[] columnNames)
Replaces the value in the dataList instance variable with the values in the array newData. The first index in the Object[][] array is the row index and the second is the column index. columnNames are the names of the new columns.

Parameters:
newData - the new data list
columnNames - the names of the columns
See Also:
setDataList(List, List)

newDataAvailable

public void newDataAvailable(javax.swing.event.TableModelEvent event)
Equivalent to fireTableChanged.

Parameters:
event - the change event

newRowsAdded

public void newRowsAdded(javax.swing.event.TableModelEvent event)
Ensures that the new rows have the correct number of columns. This is accomplished by using the setSize method in List which truncates lists which are too long, and appends nulls if they are too short. This method also sends out a tableChanged notification message to all the listeners.

Parameters:
event - this TableModelEvent describes where the rows were added. If null it assumes all the rows were newly added
See Also:
getDataList()

rowsRemoved

public void rowsRemoved(javax.swing.event.TableModelEvent event)
Equivalent to fireTableChanged.

Parameters:
event - the change event

setColumnIdentifiers

public void setColumnIdentifiers(java.util.List newIdentifiers)
Replaces the column identifiers in the model. If the number of newIdentifiers is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

Parameters:
newIdentifiers - list of column identifiers. If null, set the model to zero columns
See Also:
setNumRows(int)

setColumnIdentifiers

public void setColumnIdentifiers(java.lang.Object[] newIdentifiers)
Replaces the column identifiers in the model. If the number of newIdentifiers is greater than the current number of columns, new columns are added to the end of each row in the model. If the number of newIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.

Parameters:
newIdentifiers - array of column identifiers. If null, set the model to zero columns
See Also:
setNumRows(int)

setNumRows

public void setNumRows(int newSize)
Obsolete as of Java 2 platform v1.3. Please use setRowCount instead.


setRowCount

public void setRowCount(int rowCount)
Sets the number of rows in the model. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index rowCount and greater are discarded.

See Also:
setColumnCount(int)

setColumnCount

public void setColumnCount(int columnCount)
Sets the number of columns in the model. If the new size is greater than the current size, new columns are added to the end of the model with null cell values. If the new size is less than the current size, all columns at index columnCount and greater are discarded.

Parameters:
columnCount - the new number of columns in the model
See Also:
setColumnCount(int)

addColumn

public void addColumn(java.lang.Object columnName)
Adds a column to the model. The new column will have the identifier columnName. This method will send a tableChanged notification message to all the listeners. This method is a cover for addColumn(Object, List) which uses null as the data list.

Parameters:
columnName - the identifier of the column being added
Throws:
java.lang.IllegalArgumentException - if columnName is null

addColumn

public void addColumn(java.lang.Object columnName,
                      java.util.List columnData)
Adds a column to the model. The new column will have the identifier columnName. columnData is the optional list of data for the column. If it is null the column is filled with null values. Otherwise, the new data will be added to model starting with the first element going to row 0, etc. This method will send a tableChanged notification message to all the listeners.

Parameters:
columnName - the identifier of the column being added
columnData - optional data of the column being added
Throws:
java.lang.IllegalArgumentException - if columnName is null

addColumn

public void addColumn(java.lang.Object columnName,
                      java.lang.Object[] columnData)
Adds a column to the model. The new column will have the identifier columnName. columnData is the optional array of data for the column. If it is null the column is filled with null values. Otherwise, the new data will be added to model starting with the first element going to row 0, etc. This method will send a tableChanged notification message to all the listeners.

See Also:
addColumn(Object, List)

addRow

public void addRow(java.util.List rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

Parameters:
rowData - optional data of the row being added

addRow

public void addRow(java.lang.Object[] rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

Parameters:
rowData - optional data of the row being added

insertRow

public void insertRow(int row,
                      java.util.List rowData)
Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

Parameters:
row - the row index of the row to be inserted
rowData - optional data of the row being added
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the row was invalid

insertRow

public void insertRow(int row,
                      java.lang.Object[] rowData)
Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

Parameters:
row - the row index of the row to be inserted
rowData - optional data of the row being added
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the row was invalid

moveRow

public void moveRow(int startIndex,
                    int endIndex,
                    int toIndex)
Moves one or more rows starting at startIndex to endIndex in the model to the toIndex. This method will send a tableChanged 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|B|C|D|g|h|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

Parameters:
startIndex - the starting row index to be moved
endIndex - the ending row index to be moved
toIndex - the destination of the rows to be moved
Throws:
java.lang.ArrayIndexOutOfBoundsException - if any of the indices are out of range; or if endIndex is less than startIndex

removeRow

public void removeRow(int row)
Removes the row at row from the model. Notification of the row being removed will be sent to all the listeners.

Parameters:
row - the row index of the row to be removed
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the row was invalid

getRowCount

public int getRowCount()
Returns the number of rows in this data table.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number of rows in the model

getColumnCount

public int getColumnCount()
Returns the number of columns in this data table.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
the number of columns in the model

getColumnName

public java.lang.String getColumnName(int column)
Returns the column name.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Returns:
a name for this column using the string value of the appropriate member in columnIdentifiers. If columnIdentifiers is null or does not have an entry for this index, returns the default name provided by the superclass

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true regardless of parameter values.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
true
See Also:
setValueAt(java.lang.Object, int, int)

setEditable

public void setEditable(boolean isEditable)
Sets the editable state of the default table model


isEditable

public boolean isEditable()
Returns the editable state of the default table model


getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Returns an attribute value for the cell at row and column.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid row or column was given

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Sets the object value for the cell at column and row. aValue is the new value. This method will generate a tableChanged notification.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Parameters:
aValue - the new value; this can be null
row - the row whose value is to be changed
column - the column whose value is to be changed
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid row or column was given

convertToList

protected static java.util.List convertToList(java.lang.Object[] anArray)
Returns a list that contains the same objects as the array.

Parameters:
anArray - the array to be converted
Returns:
the new list; if anArray is null, returns null

convertToList

protected static java.util.List convertToList(java.lang.Object[][] anArray)
Returns a list of lists that contains the same objects as the array.

Parameters:
anArray - the double array to be converted
Returns:
the new list of lists; if anArray is null, returns null

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.