Holger's
Java API

com.antelmann.util.table
Class TableModelView

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.antelmann.util.table.TableModelView
All Implemented Interfaces:
Wrapped<TableModel>, Serializable, EventListener, TableModelListener, TableModel
Direct Known Subclasses:
ObjectTableModelView

public class TableModelView
extends AbstractTableModel
implements Wrapped<TableModel>, TableModelListener

provides a view/projection of a given TableModel. Note that this implementation is not synchronized.

Author:
Holger Antelmann
See Also:
FilteredTableModel, Serialized Form

Field Summary
protected  HashMap<Integer,String> columnNames
          allows to conveniently customize column names for subclasses
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableModelView(TableModel model, int... visibleColumn)
           
 
Method Summary
 int findColumnInBackingModel(String columnName)
          returns either the associated column index or -1 if the column is not found
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 String getColumnName(int column)
           
 int getRowCount()
           
 Object getValueAt(int row, int column)
           
 List<Integer> getVisibleColums()
           
 boolean isCellEditable(int row, int column)
           
 boolean isColumnVisible(int c)
           
 boolean isColumnVisible(String columnName)
           
 String setColumnName(int column, String displayName)
           
 void setColumnNames(String... newColumnNames)
           
 void setColumnVisible(int column, boolean flag)
          sets a single column to visible/non-visible; the order of columns will be reset and every column only appears once hereafter.
 void setColumnVisible(String columnName, boolean flag)
          sets a single column to visible/non-visible; the order of columns will be reset.
 void setValueAt(Object value, int row, int column)
           
 void setVisibleColumns(int... columns)
          allows to directly set all the visible columns - including their given order.
 void tableChanged(TableModelEvent ev)
           
 TableModel unwrap()
          returns the embedded instance that this wrapper encloses
 
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
 

Field Detail

columnNames

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

Constructor Detail

TableModelView

public TableModelView(TableModel model,
                      int... visibleColumn)
               throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException
Method Detail

unwrap

public TableModel unwrap()
Description copied from interface: Wrapped
returns the embedded instance that this wrapper encloses

Specified by:
unwrap in interface Wrapped<TableModel>

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

findColumnInBackingModel

public int findColumnInBackingModel(String columnName)
returns either the associated column index or -1 if the column is not found


isColumnVisible

public boolean isColumnVisible(String columnName)

getVisibleColums

public List<Integer> getVisibleColums()

isColumnVisible

public boolean isColumnVisible(int c)

setVisibleColumns

public void setVisibleColumns(int... columns)
allows to directly set all the visible columns - including their given order. Note: listeners to the model will ONLY be notified if the backing model is an instance of an AbstractTableModel, otherwise NOT!


setColumnVisible

public void setColumnVisible(String columnName,
                             boolean flag)
sets a single column to visible/non-visible; the order of columns will be reset.


setColumnVisible

public void setColumnVisible(int column,
                             boolean flag)
                      throws ArrayIndexOutOfBoundsException
sets a single column to visible/non-visible; the order of columns will be reset and every column only appears once hereafter. Note: listeners to the model will ONLY be notified if the backing model is an instance of an AbstractTableModel, otherwise NOT!

Throws:
ArrayIndexOutOfBoundsException

getRowCount

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

getColumnCount

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

getColumnClass

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

isCellEditable

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

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

tableChanged

public void tableChanged(TableModelEvent ev)
Specified by:
tableChanged in interface TableModelListener


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