Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

oracle.javatools.ui.table
Class SimpleTableModel<T>

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by oracle.javatools.ui.table.SimpleTableModel<T>
Type Parameters:
T - The type of object representing one row in the table
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, ReorderableTableModel

public final class SimpleTableModel<T>
extends javax.swing.table.AbstractTableModel
implements ReorderableTableModel

A TableModel for displaying java.util.Lists or arrays of data in a table where each row corresponds to an element in the collection.

Columns in the table are determined by a SimpleTableFormat object which maps each column to one aspect of the row object

The change the rows of the table retrieve a java.util.List from the asList() method and manipulate it like a normal list. Changes to the list will be reflected in the table.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SimpleTableModel(java.util.List<T> tableRows, SimpleTableFormat<T> format)
           
SimpleTableModel(SimpleTableFormat<T> format)
           
SimpleTableModel(T[] tableRows, SimpleTableFormat<T> format)
           
 
Method Summary
 java.util.List<T> asList()
          Returns a List implementation that is bound to this table model.
 java.lang.Class<?> getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 T getRow(int i)
          Get an element representing a row in the table by its index.
 int getRowCount()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 int indexOf(T element)
          Return the index of the given element
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 void moveRow(int start, int end, int to)
          Moves one or more rows from the inclusive range start to end to the to position in the model.
 void rowDataChanged(int index)
          The contents of a row have changed, update the ui to reflect the new values.
 void rowDataChanged(T row)
          The contents of a row have changed, update the ui to reflect the new values.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTableModel

public SimpleTableModel(SimpleTableFormat<T> format)

SimpleTableModel

public SimpleTableModel(java.util.List<T> tableRows,
                        SimpleTableFormat<T> format)

SimpleTableModel

public SimpleTableModel(T[] tableRows,
                        SimpleTableFormat<T> format)
Method Detail

asList

public java.util.List<T> asList()
Returns a List implementation that is bound to this table model.

The binding behavior means that you can safely call methods on the returned List that make changes to the list, and they will be reflected in the model, firing appropriate events.

Returns:
a List that you can use to manipulate the model, firing appropriate events. Will never return null.
Since:
11.0

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface javax.swing.table.TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface javax.swing.table.TableModel

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getColumnClass

public java.lang.Class<?> getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface javax.swing.table.TableModel

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

getRow

public T getRow(int i)
Get an element representing a row in the table by its index.

Parameters:
i - the index of an row in the model. Must be >= 0 and < this.getRowCount().
Returns:
the element for the row at the specified position in this list model.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).

indexOf

public int indexOf(T element)
Return the index of the given element

Parameters:
element -
Returns:
the index of the given element or -1 if the element isn't present

rowDataChanged

public void rowDataChanged(int index)
The contents of a row have changed, update the ui to reflect the new values.


rowDataChanged

public void rowDataChanged(T row)
The contents of a row have changed, update the ui to reflect the new values.


moveRow

public void moveRow(int start,
                    int end,
                    int to)
Description copied from interface: ReorderableTableModel
Moves one or more rows from the inclusive range 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 should also 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|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

Specified by:
moveRow in interface ReorderableTableModel
Parameters:
start - the starting row index to be moved
end - the ending row index to be moved
to - the destination of the rows to be moved

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

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