Holger's
Java API

com.antelmann.util.table
Class AbstractObjectTableModel<T>

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.antelmann.util.table.AbstractObjectTableModel<T>
All Implemented Interfaces:
ListRetriever<T>, Refreshable, ObjectTableModel<T>, Serializable, Iterable<T>, TableModel
Direct Known Subclasses:
LicenseTableModel, MethodTableModel, PatternTableModel, PropertyEntryTableModel

public abstract class AbstractObjectTableModel<T>
extends AbstractTableModel
implements ObjectTableModel<T>, ListRetriever<T>, Iterable<T>

implements commonly applicable concepts of an ObjectTableModel based on a simple list. Note that altering the contents of the embedded list externally must be both synchronized on this instance and propagated with a TableModelEvent

Since:
22.12.2008, 14:48:56
Author:
Holger Antelmann
See Also:
Serialized Form

Field Summary
protected  HashMap<Integer,String> columnNames
          allows to conveniently customize column names for subclasses
protected  HashMap<Integer,Class<?>> columnTypes
          allows to conveniently customize column types for subclasses
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
AbstractObjectTableModel()
           
AbstractObjectTableModel(Iterable<T> i)
          if the given iterable is in fact a list, it will be used directly as the backing data structure
 
Method Summary
 boolean add(int row, T element)
           
 boolean add(T element)
           
 void clear()
           
 boolean contains(T element)
           
 Class<?> getColumnClass(int column)
           
 String getColumnName(int column)
           
 List<T> getList()
          returns an unmodifiable view of the embedded list.
 List<T> getRelevantList()
          returns the currently relevant list of the denotes objects
 String getRelevantListDescription()
           
 int getRowCount()
           
 int getRowFor(T entry)
          locates the row where the given entry can be found in this model
 T getRowValue(int row)
          retrieves the value that is represented by the given row in this model.
 Iterator<T> iterator()
           
 boolean moveDown(int row)
          moves the given row element down by one.
 boolean moveUp(int row)
          moves the given row element up by one.
 void refreshContent()
          refreshes the embedded content
 T remove(int index)
           
 boolean remove(T element)
           
 String setColumnName(int column, String displayName)
           
 void setColumnNames(String... newColumnNames)
           
 Class<?> setColumnType(int column, Class<?> type)
           
 void setColumnTypes(Class<?>... types)
           
 void setRowValues(Iterable<? extends T> updatedList)
          allows to change the underlying table data based on the given collection.
 boolean swap(int row1, int row2)
           
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 

Field Detail

columnNames

protected final HashMap<Integer,String> columnNames
allows to conveniently customize column names for subclasses


columnTypes

protected final HashMap<Integer,Class<?>> columnTypes
allows to conveniently customize column types for subclasses

Constructor Detail

AbstractObjectTableModel

public AbstractObjectTableModel()

AbstractObjectTableModel

public AbstractObjectTableModel(Iterable<T> i)
if the given iterable is in fact a list, it will be used directly as the backing data structure

Method Detail

refreshContent

public void refreshContent()
                    throws IOException
Description copied from interface: Refreshable
refreshes the embedded content

Specified by:
refreshContent in interface Refreshable
Throws:
IOException - if the refresh failed

setColumnNames

public void setColumnNames(String... newColumnNames)

setColumnName

public String setColumnName(int column,
                            String displayName)

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

setColumnTypes

public void setColumnTypes(Class<?>... types)

setColumnType

public Class<?> setColumnType(int column,
                              Class<?> type)

getColumnClass

public Class<?> getColumnClass(int column)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getRowFor

public int getRowFor(T entry)
Description copied from interface: ObjectTableModel
locates the row where the given entry can be found in this model

Specified by:
getRowFor in interface ObjectTableModel<T>
Returns:
the row where the entry is found in the model or -1 if the entry doesn't exist in this model

getRowValue

public T getRowValue(int row)
Description copied from interface: ObjectTableModel
retrieves the value that is represented by the given row in this model. If the given row does not exist in the model, various RuntimeExceptions may occur.

Specified by:
getRowValue in interface ObjectTableModel<T>
Returns:
the Object value representing the given row

clear

public void clear()

setRowValues

public void setRowValues(Iterable<? extends T> updatedList)
Description copied from interface: ObjectTableModel
allows to change the underlying table data based on the given collection. Unless specified otherwise, the given collection remains untouched and the elements are copied into the internal data structure of the model.

Specified by:
setRowValues in interface ObjectTableModel<T>

contains

public boolean contains(T element)

add

public boolean add(T element)

add

public boolean add(int row,
                   T element)

remove

public boolean remove(T element)

remove

public T remove(int index)

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel

getList

public List<T> getList()
returns an unmodifiable view of the embedded list.


iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

getRelevantList

public List<T> getRelevantList()
                        throws IOException
Description copied from interface: ListRetriever
returns the currently relevant list of the denotes objects

Specified by:
getRelevantList in interface ListRetriever<T>
Throws:
IOException

getRelevantListDescription

public String getRelevantListDescription()
Specified by:
getRelevantListDescription in interface ListRetriever<T>

moveDown

public boolean moveDown(int row)
moves the given row element down by one. The call has no effect if the row is out of range or if the given row is the last.


moveUp

public boolean moveUp(int row)
moves the given row element up by one. The call has no effect if the row is out of range or if the given row is the first.


swap

public boolean swap(int row1,
                    int row2)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads