QJCC homepage

biz.chitec.quarterback.swing
Class MapListTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bybiz.chitec.quarterback.swing.MapListTableModel
All Implemented Interfaces:
DefaultLocaleChangeReceiver, java.io.Serializable, javax.swing.table.TableModel

public class MapListTableModel
extends javax.swing.table.AbstractTableModel
implements DefaultLocaleChangeReceiver

Model object for JTable to represent List of Maps. All Maps have the same keys which values are taken as table content. Columns can be set either explicitly or implicitly. In the first case the table only shows the Maps' elements with the given keys, in the second case the table computes the column names as union over all Maps.

The real column names can be either directly the Map keys or some content of a ResourceBundle object.

Version:
$Id: 643b6002a8410cd6cbe60e1f9985c052cef024ee $
Author:
chitec/Dirk Hillbrecht 2002 Distributed under the terms of the GNU LGPL.
See Also:
MapListModelHelper, Serialized Form

Field Summary
private  java.util.Comparator comparator
           
private  boolean doautosortonenable
           
private  boolean isautosorting
           
private  MapListModelHelper mlmh
           
private  int rownum
           
private  java.util.List thedata
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MapListTableModel()
          Standard empty constructor.
MapListTableModel(java.util.ResourceBundle rbx)
          Set ResourceBundle to find column title strings and classes
MapListTableModel(java.util.ResourceBundle rbx, java.lang.String prefix)
          Set ResourceBundle and the prefix to access the resource entries
MapListTableModel(java.util.ResourceBundle rbx, java.lang.String[] hdr)
          Set ResourceBundle and title columns Using this constructor, it is possible to minimize the overhead while data insertion.
MapListTableModel(java.util.ResourceBundle rbx, java.lang.String prefix, java.lang.String[] hdr)
          Set ResourceBundle, use prefix and set the title columns.
MapListTableModel(java.lang.String[] hdr)
          Set title columns explicitly
 
Method Summary
 void add(int row, java.util.Map data)
          Insert one element of data explicitly at a certain position.
 void add(java.util.List dtx)
          Add data.
 void add(java.util.Map dt)
          Add one new element of data.
 void addData(java.util.List dtx)
          Deprecated. Use add(List) instead.
 void addDataElement(java.util.Map dt)
          Deprecated. Use add(Map) instead.
 void clear()
          Remove all data.
 void defaultLocaleChanged()
          Called if any locale changes.
protected  void finishInsertion(int oldrownum, int rownum, boolean updated)
          Called after every insertion.
 java.lang.Class getColumnClass(int col)
          From TableModel: Return column class.
 int getColumnCount()
          From TableModel: returns number of data columns.
 java.lang.String getColumnEditorClassName(int column)
          Returns the column editor class for a certain column.
 int getColumnIndex(java.lang.String name)
          Return index of column with given name.
 int getColumnIndexBySortReplace(java.lang.String sortkey)
          Get a column index by the sortreplace key value.
 java.lang.String getColumnKey(int index)
          Return key of colunm with given index.
 java.lang.String getColumnName(int column)
          From TableModel: Return column name.
 java.lang.String getColumnRendererClassName(int column)
          Returns the column renderer class for a certain column.
 java.util.Comparator getConstrainingComparator()
          Returns the current constraining comparator
 java.util.List getData()
          Returns all stored data.
 MapListModelHelper getMapListModelHelper()
          Return my model helper.
 java.util.ResourceBundle getResourceBundle()
          Returns the ResourceBundle used by the ModelHelper
 java.lang.String getResourcePrefix()
          Returns the keys' prefix used for all resources read from the ResourceBundle
 int getRowCount()
          From TableModel: returns number of data rows.
 java.lang.String getSortReplaceKey(int index)
          Return maps' key for sort replace value of given row index.
 java.lang.Object getValueAt(int row, int column)
          From TableModel: Return a certain value.
 void init(java.util.List dtx)
          Sets data.
 void insertDataAt(java.util.Map data, int row)
          Deprecated. Use add(int,Map) instead
 boolean isCellEditable(int row, int column)
          From TableModel: Return whether cell is editable.
 boolean isHeaderSet()
          Returns whether the header has been set.
 java.util.Map remove(int row)
          Remove one element of data.
 void removeData()
          Deprecated. Use clear() instead
 void removeData(int row)
          Deprecated. Use remove(int) instead
 void removeHeader()
          Remove columns.
 void saveAsFile(java.lang.String filename)
           
 void set(int row, java.util.Map data)
          Change data at given row.
 void set(int row, java.lang.Object key, java.lang.Object value)
          Change the content of a given key in a given row to the given value Rownum must be valid.
 void setAutoSorting(boolean b)
          Temporarily dis- and reenable autosorting with the given constraint comparator.
 void setConstrainingComparator(java.util.Comparator comparatorx)
          Add sorting constraint handler.
 void setData(java.util.List dtx)
          Deprecated. Use init(List) instead
 void setHeader(java.lang.String[] hdr)
          Set header.
 void setMapListModelHelper(MapListModelHelper mlmhx)
          Sets the model helper explicitly.
 void setResourceBundle(java.util.ResourceBundle rbx)
          Sets ResourceBundle from which column titles are acquired without changing the prefix.
 void setResourceBundle(java.util.ResourceBundle rbx, java.lang.String prefix)
          Sets ResourceBundle from which column titles are acquired and adds or changes a prefix.
 void setValueAt(java.lang.Object value, int row, int column)
          From TableModel: Set a certain value.
 void sortData()
          Sort data by constraining comparator if existing.
 void sortData(int index)
          Sort data by index
 void sortData(java.lang.String key)
          Sort data by key
 void updateDataAt(java.util.Map data, int row)
          Deprecated. Use set(int,Map) instead.
 
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

thedata

private java.util.List thedata

rownum

private int rownum

mlmh

private MapListModelHelper mlmh

comparator

private java.util.Comparator comparator

isautosorting

private boolean isautosorting

doautosortonenable

private boolean doautosortonenable
Constructor Detail

MapListTableModel

public MapListTableModel()
Standard empty constructor. No data. No bundle. No titles.


MapListTableModel

public MapListTableModel(java.util.ResourceBundle rbx)
Set ResourceBundle to find column title strings and classes


MapListTableModel

public MapListTableModel(java.lang.String[] hdr)
Set title columns explicitly


MapListTableModel

public MapListTableModel(java.util.ResourceBundle rbx,
                         java.lang.String[] hdr)
Set ResourceBundle and title columns Using this constructor, it is possible to minimize the overhead while data insertion. Therefore, not only column title, but also column classes must be preset in the ResourceBundle.


MapListTableModel

public MapListTableModel(java.util.ResourceBundle rbx,
                         java.lang.String prefix)
Set ResourceBundle and the prefix to access the resource entries


MapListTableModel

public MapListTableModel(java.util.ResourceBundle rbx,
                         java.lang.String prefix,
                         java.lang.String[] hdr)
Set ResourceBundle, use prefix and set the title columns. Using this constructor, it is possible to minimize the overhead while data insertion. Therefore, not only column title, but also column classes must be preset in the ResourceBundle.

Method Detail

setResourceBundle

public void setResourceBundle(java.util.ResourceBundle rbx,
                              java.lang.String prefix)
Sets ResourceBundle from which column titles are acquired and adds or changes a prefix.


setResourceBundle

public void setResourceBundle(java.util.ResourceBundle rbx)
Sets ResourceBundle from which column titles are acquired without changing the prefix.


getResourceBundle

public java.util.ResourceBundle getResourceBundle()
Returns the ResourceBundle used by the ModelHelper


getResourcePrefix

public java.lang.String getResourcePrefix()
Returns the keys' prefix used for all resources read from the ResourceBundle


setHeader

public void setHeader(java.lang.String[] hdr)
Set header. These headers are used to obtain the correct field from the hashtable. For customized header representation on screen, use ResourceBundle.


getMapListModelHelper

public MapListModelHelper getMapListModelHelper()
Return my model helper. Returns MapListModelHelper of this object so that it can be used by other models, also. Main reason is usage within conversed table models out of tree table models.


setMapListModelHelper

public void setMapListModelHelper(MapListModelHelper mlmhx)
Sets the model helper explicitly. Using this method, the model can share the model helper with another table oder tree table model. Main reason is usage within conversed table models out of tree table models.


finishInsertion

protected void finishInsertion(int oldrownum,
                               int rownum,
                               boolean updated)
Called after every insertion. Performs sorting if wanted and fires change event.


setData

public void setData(java.util.List dtx)
Deprecated. Use init(List) instead

Sets data. If no headers are given explicitly, take union of key sets of Maps. Obtain column classes. Inform listeners.


init

public void init(java.util.List dtx)
Sets data. If no headers are given explicitly, take union of key sets of Maps. Obtain column classes. Inform listeners.


addData

public void addData(java.util.List dtx)
Deprecated. Use add(List) instead.

Add data. New data is appended to already available data. Computations are repeated as if new data had been set.


add

public void add(java.util.List dtx)
Add data. New data is appended to already available data. Computations are repeated as if new data had been set.


addDataElement

public void addDataElement(java.util.Map dt)
Deprecated. Use add(Map) instead.

Add one new element of data. New data is appended to already available data. Computations are repeated as if new data had been set.


add

public void add(java.util.Map dt)
Add one new element of data. New data is appended to already available data. Computations are repeated as if new data had been set.


removeData

public void removeData()
Deprecated. Use clear() instead

Remove all data. Headers are not changed. Column titles stay.


clear

public void clear()
Remove all data. Headers are not changed. Column titles stay.


removeData

public void removeData(int row)
Deprecated. Use remove(int) instead

Remove one element of data.


remove

public java.util.Map remove(int row)
Remove one element of data.


insertDataAt

public void insertDataAt(java.util.Map data,
                         int row)
Deprecated. Use add(int,Map) instead

Insert one element of data explicitly at a certain position.


add

public void add(int row,
                java.util.Map data)
Insert one element of data explicitly at a certain position.


updateDataAt

public void updateDataAt(java.util.Map data,
                         int row)
Deprecated. Use set(int,Map) instead.

Change data at given row.


set

public void set(int row,
                java.util.Map data)
Change data at given row.


set

public void set(int row,
                java.lang.Object key,
                java.lang.Object value)
Change the content of a given key in a given row to the given value Rownum must be valid. Key should be one of the shown keys. Value should be of compatible type. After insertion, the table is properly updated.

Parameters:
row - Row to change data in
key - Name of the entry to change
value - New value to be put into the table

removeHeader

public void removeHeader()
Remove columns. Removes all data implicitly.


isHeaderSet

public boolean isHeaderSet()
Returns whether the header has been set.


getData

public java.util.List getData()
Returns all stored data. The data is given in its original List of Map form. If no data is available, null is returned. Note that you SHOULD NOT CHANGE the received data!


getColumnIndex

public int getColumnIndex(java.lang.String name)
Return index of column with given name.


getColumnKey

public java.lang.String getColumnKey(int index)
Return key of colunm with given index.


getSortReplaceKey

public java.lang.String getSortReplaceKey(int index)
Return maps' key for sort replace value of given row index.


getColumnIndexBySortReplace

public int getColumnIndexBySortReplace(java.lang.String sortkey)
Get a column index by the sortreplace key value.


sortData

public void sortData(int index)
Sort data by index


sortData

public void sortData(java.lang.String key)
Sort data by key


sortData

public void sortData()
Sort data by constraining comparator if existing. Throws NPE if no constraining comparator has been set


setConstrainingComparator

public void setConstrainingComparator(java.util.Comparator comparatorx)
Add sorting constraint handler. Sorting constraints are obeyed after every programmatically driven insertion or change of the model.


getConstrainingComparator

public java.util.Comparator getConstrainingComparator()
Returns the current constraining comparator


setAutoSorting

public void setAutoSorting(boolean b)
Temporarily dis- and reenable autosorting with the given constraint comparator.

Must only be used for short breaks in sorting, i.e. if multiple elements are changed within the same event but with distinct calls and in a way that the order must not be changed in between. Update events are not fired as long as sorting is disabled this way.

If you need longer pauses in automated sorting or want to disable it completely, set the constraining comparator to null.

Parameters:
b - Indicator whether sorting should be disabled or enabled.

getRowCount

public int getRowCount()
From TableModel: returns number of data rows.

Specified by:
getRowCount in interface javax.swing.table.TableModel

getColumnCount

public int getColumnCount()
From TableModel: returns number of data columns.

Specified by:
getColumnCount in interface javax.swing.table.TableModel

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
From TableModel: Return a certain value.

Specified by:
getValueAt in interface javax.swing.table.TableModel

setValueAt

public void setValueAt(java.lang.Object value,
                       int row,
                       int column)
From TableModel: Set a certain value.

Specified by:
setValueAt in interface javax.swing.table.TableModel

getColumnName

public java.lang.String getColumnName(int column)
From TableModel: Return column name.

Specified by:
getColumnName in interface javax.swing.table.TableModel

getColumnClass

public java.lang.Class getColumnClass(int col)
From TableModel: Return column class.

Specified by:
getColumnClass in interface javax.swing.table.TableModel

isCellEditable

public boolean isCellEditable(int row,
                              int column)
From TableModel: Return whether cell is editable. For Lists of Maps, this method decides only on column base. The row number is not taken into consideration.

Specified by:
isCellEditable in interface javax.swing.table.TableModel

getColumnRendererClassName

public java.lang.String getColumnRendererClassName(int column)
Returns the column renderer class for a certain column. If no explicit column renderer has been set for the column, null is returned.

Parameters:
column - Index of the column in question
Returns:
Name of the renderer class.

getColumnEditorClassName

public java.lang.String getColumnEditorClassName(int column)
Returns the column editor class for a certain column. If no explicit column editor has been set for the column, null is returned.

Parameters:
column - Index of the column in question
Returns:
Name of the editor class.

saveAsFile

public void saveAsFile(java.lang.String filename)
                throws java.io.FileNotFoundException,
                       java.io.IOException
Throws:
java.io.FileNotFoundException
java.io.IOException

defaultLocaleChanged

public void defaultLocaleChanged()
Description copied from interface: DefaultLocaleChangeReceiver
Called if any locale changes.

Specified by:
defaultLocaleChanged in interface DefaultLocaleChangeReceiver

QJCC homepage