|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractTableModel
ListTableModel<E>
E - The type of elements in the list backing this table model.public abstract class ListTableModel<E>
A table model backed by a list. The
list is given to the constructor and retained by direct reference - it is not
cloned, because it may contain millions of elements, sometime through a custom List
implementation fetching the information on-the-fly from a database. Consequently if the content
of the list is modified externally, then a fireXXX method (inherited from
AbstractTableModel must be invoked explicitly. Note that those fireXXX methods
don't need to be invoked if the list is modified through the methods provided in this class.
Multi-threading
Unless otherwise specified, methods in this class must be invoked from the Swing thread.
Exceptions are the getElements method, which will be automatically executed in
the Swing thread no matter the invoker thread. This convenience does not
apply to methods inherited from the super-class, and may not apply to methods defined in
the sub-classes.
Serialization
This model is serialiable if the underlying list is serializable.
| display/geotk-widgets-swing (download) | View source code for this class |
| Field Summary | |
|---|---|
protected List<E> |
elements
The list of row elements. |
| Fields inherited from class AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
protected |
ListTableModel(Class<E> type)
Creates a new table model backed by an ArrayList. |
protected |
ListTableModel(Class<E> type,
List<E> elements)
Creates a new table model for the given list. |
| Method Summary | |
|---|---|
void |
add(Collection<? extends E> toAdd)
Adds all elements from the given collection. |
E[] |
getElements()
Returns a snapshot of every elements contained in this model. |
E[] |
getElements(int[] selection)
Returns a snapshot of selected elements. |
E[] |
getElements(int lower,
int upper)
Returns a snapshot of a range of elements contained in this model. |
int |
getRowCount()
Returns the number of rows in the table. |
void |
insert(int insertAt,
Collection<? extends E> toAdd)
Inserts at the given position all elements from the given collection. |
void |
remove(int[] indices)
Removes the given elements from the list. |
void |
remove(int lower,
int upper)
Removes a range of rows (or elements). |
int |
removeDuplicates()
Removes duplicated elements. |
void |
setElements(E... elts)
Sets the elements. |
boolean |
sort()
Sorts the elements in their natural order. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface TableModel |
|---|
getColumnCount, getValueAt |
| Field Detail |
|---|
protected final List<E> elements
fireXXX method must be invoked explicitly.
| Constructor Detail |
|---|
protected ListTableModel(Class<E> type)
ArrayList.
type - The type of elements in the list.
protected ListTableModel(Class<E> type,
List<E> elements)
fireXXX method inherited from AbstractTableModel
must be invoked explicitly.
type - The type of elements in the list.elements - The list of elements to display in a table.| Method Detail |
|---|
public int getRowCount()
public E[] getElements()
public E[] getElements(int lower,
int upper)
lower - Index of the first element to be returned.upper - Index after the last element to be returned.
public E[] getElements(int[] selection)
selection - The indices of selected elements, typically given by
JTable.getSelectedRows().
public void setElements(E... elts)
elts - The new elements.
public void add(Collection<? extends E> toAdd)
throws UnsupportedOperationException
List.addAll(Collection) and uses the change of list size
for computing the index to be given to the AbstractTableModel.fireTableRowsInserted(int,int) method.
Consequently the list implementation doesn't need to accept every elements. Note however
that the list must not change in a concurrent thread, otherwise the change event to be
fired may have an inacurate index range.
toAdd - The elements to add.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
public void insert(int insertAt,
Collection<? extends E> toAdd)
throws UnsupportedOperationException,
IndexOutOfBoundsException
The default implementation invokes List.addAll(int,Collection) and uses the
change of list size for computing the index to be given to the
AbstractTableModel.fireTableRowsInserted(int,int) method. Consequently the list implementation
doesn't need to accept every elements. Note however that the list must not change in
a concurrent thread, otherwise the change event to be fired may have an inacurate index
range.
insertAt - The insertion point. The first element will be inserted at that position.toAdd - The elements to add.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
IndexOutOfBoundsException - if the given index is out of range.
public void remove(int lower,
int upper)
throws UnsupportedOperationException
lower - Index of the first row to remove, inclusive.upper - Index of the last row to remove, inclusive.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
public void remove(int[] indices)
throws UnsupportedOperationException
remove(int,int). Consecutive indexes will be removed in a single call of the
above method.
indices - The index of elements to remove.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
public int removeDuplicates()
throws UnsupportedOperationException
Object.equals(Object) method, then the first one is removed from the
elements list. We keep the last element instead of the first one
on the assumption that the last element is the most recently added.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
public boolean sort()
throws UnsupportedOperationException,
ClassCastException
true if the row order changed as a result of this method call.
UnsupportedOperationException - if the underlying elements list
is not modifiable.
ClassCastException - if the list contains elements that are not
mutually comparable.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||