Holger's
Java API

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

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.antelmann.util.table.SelectableObjectsTableModel<T>
All Implemented Interfaces:
Refreshable, ObjectTableModel<T>, Serializable, TableModel

public class SelectableObjectsTableModel<T>
extends AbstractTableModel
implements ObjectTableModel<T>

a special table model that wraps an existing ObjectTableModel by adding a column with an editable Boolean. This model can then be used to have several objects be selected through a gui that can be retrieved via this API.

Since:
7. Januar 2007, 17:00
Author:
Holger Antelmann
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SelectableObjectsTableModel(Class<T> type, ObjectTableModel<T> model, Collection<? extends T> selectedItems)
           
SelectableObjectsTableModel(Class<T> type, ObjectTableModel<T> model, T... selectedItems)
           
SelectableObjectsTableModel(Class<T> type, String columnTitle, Collection<? extends T> items)
          creates a special table model that uses 2 columns, where the second column is made from the toStrring() method of the given items.
SelectableObjectsTableModel(Class<T> type, String columnTitle, T... items)
          creates a special table model that uses 2 columns, where the second column is made from the toString() method of the given items.
 
Method Summary
 void addSelectedObject(T element)
           
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 String getColumnName(int column)
           
 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.
 Set<T> getSelectedItems()
          returns an immutable view of the currently selected items
 Class<T> getType()
           
 Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 void refreshContent()
          refreshes the embedded content
 void removeSelectedObject(T element)
           
 void selectAll()
           
 void setRowSelection(int row, boolean flag)
           
 void setRowValues(Iterable<? extends T> updatedList)
          maintains those items as selected that were previously selected
 void setSelectedObjects(Collection<? extends T> toSelect)
           
 void setSelectedObjects(T... toSelect)
          objects that are not selectable in this model are ignored
 void setValueAt(Object value, int row, int column)
           
 void unselectAll()
           
 
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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

SelectableObjectsTableModel

public SelectableObjectsTableModel(Class<T> type,
                                   String columnTitle,
                                   Collection<? extends T> items)
creates a special table model that uses 2 columns, where the second column is made from the toStrring() method of the given items.


SelectableObjectsTableModel

public SelectableObjectsTableModel(Class<T> type,
                                   String columnTitle,
                                   T... items)
creates a special table model that uses 2 columns, where the second column is made from the toString() method of the given items.


SelectableObjectsTableModel

public SelectableObjectsTableModel(Class<T> type,
                                   ObjectTableModel<T> model,
                                   T... selectedItems)

SelectableObjectsTableModel

public SelectableObjectsTableModel(Class<T> type,
                                   ObjectTableModel<T> model,
                                   Collection<? extends T> selectedItems)
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

getType

public Class<T> getType()

getRowCount

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

getColumnCount

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

unselectAll

public void unselectAll()

selectAll

public void selectAll()

setSelectedObjects

public void setSelectedObjects(Collection<? extends T> toSelect)

setSelectedObjects

public void setSelectedObjects(T... toSelect)
objects that are not selectable in this model are ignored


addSelectedObject

public void addSelectedObject(T element)

removeSelectedObject

public void removeSelectedObject(T element)

setRowSelection

public void setRowSelection(int row,
                            boolean flag)

getSelectedItems

public Set<T> getSelectedItems()
returns an immutable view of the currently selected items


getValueAt

public Object getValueAt(int row,
                         int column)
Specified by:
getValueAt in interface TableModel

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

getColumnName

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

getColumnClass

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

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

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

setRowValues

public void setRowValues(Iterable<? extends T> updatedList)
                  throws UnsupportedOperationException
maintains those items as selected that were previously selected

Specified by:
setRowValues in interface ObjectTableModel<T>
Throws:
UnsupportedOperationException - if this model doesn't allow such changes


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