org.formaria.swing.table
Class TableModelAdapter

java.lang.Object
  extended by org.formaria.swing.table.TableModelAdapter
All Implemented Interfaces:
javax.swing.table.TableModel, ModelAdapter, ModelAdapterConfigurable
Direct Known Subclasses:
DatabaseTableModelAdapter, TablePojoModelAdapter

public class TableModelAdapter
extends java.lang.Object
implements javax.swing.table.TableModel, ModelAdapter, ModelAdapterConfigurable

Adapts the DataModel nodes for use with Table components.

Copyright (c) Formaria Ltd., 2008
License: see license.txt


Field Summary
protected  Project currentProject
           
protected  boolean editable
           
protected  int headerRow
          1 - to display a header, 0 - otherwise
protected  java.util.Vector listeners
           
protected  DataModel model
          The data model
protected  ModelListener modelListener
           
protected  int outputFieldIdx
           
protected  DataModel rootModel
           
protected  java.lang.Object table
           
protected  boolean translateable
           
protected  Translator translator
           
protected  boolean usesDatabase
           
 
Constructor Summary
TableModelAdapter(Project project)
          Creates a new instance of TableModelAdapter
TableModelAdapter(Project project, java.lang.Object c, DataModel src)
          Creates a new instance of TableModelAdpater
 
Method Summary
 void addTableModelListener(javax.swing.event.TableModelListener l)
          Adds a listener to the list that is notified each time a change to the data model occurs.
 java.lang.Object clone()
          Create a copy of this adapter
 void configure(java.util.Hashtable bindingConfig, java.util.Hashtable instanceConfig)
          Sets the configuration.
 int find(java.lang.String key, int keyColumnIdx)
          Locate a key value in the underlying data source
 java.lang.Object get(int i)
          Gets the individual list item value
 java.lang.Object get(int i, int fieldIdx)
          Gets the individual list item value
 DataModel getAdaptedModel()
          Gets the encapsulated model node.
 java.lang.Class getColumnClass(int columnIndex)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Gets the number of columns that should be shown in a table.
 java.lang.String getColumnName(int columnIndex)
          Gets the name of the column at the specified position.
 DataModel getDataModel()
          Gets the encapsulated model node.
 java.lang.String getFieldName(int column, java.lang.String field)
          Get the displayable field name
 java.lang.Object getModelAt(int rowIndex)
          Get the model for the specified row
 java.lang.Object getModelAt(int rowIndex, int columnIndex)
          Deprecated.  
 int getNumChildren()
          Gets the number of children of the adapted model node.
 int getRowCount()
          Gets the number of rows that will appera in a Table component.
 java.lang.Object getSelected()
          Gets the value of the selected item from the node.
 java.lang.Object getSelected(int fieldIdx)
          Gets the specified field's value.
 boolean getTranslated()
          Gets the value of translateable fag
 boolean getUsesDatabase()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean hasHeaderRow()
          Indicates whether a header should be displayed
 void init(ModelListener listener)
           
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell at rowIndex and columnIndex is editable.
 void removeTableModelListener(javax.swing.event.TableModelListener l)
          Removes a listener from the list that is notified each time a change to the data model occurs.
 void set(java.lang.Object o)
          Sets the value of the adapted model node.
 void setCellEditable(boolean state)
          Set the editable state of the cell
 void setDataModel(DataModel src)
          Sets the new model node to be adapted.
 void setHasHeaderRow(boolean state)
          Sets whether a header should be displayed.
 void setModelListener(ModelListener listener)
           
 void setOutputField(int fieldIdx)
          Sets the index of the output field.
 void setTranslated(boolean tr)
          Sets the value of translateable flag.
 void setUsesDatabase(boolean state)
           
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 void sync()
          Force a sync/update of the table
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected DataModel model
The data model


headerRow

protected int headerRow
1 - to display a header, 0 - otherwise


usesDatabase

protected boolean usesDatabase

outputFieldIdx

protected int outputFieldIdx

listeners

protected java.util.Vector listeners

translateable

protected boolean translateable

translator

protected Translator translator

rootModel

protected DataModel rootModel

editable

protected boolean editable

currentProject

protected Project currentProject

modelListener

protected ModelListener modelListener

table

protected java.lang.Object table
Constructor Detail

TableModelAdapter

public TableModelAdapter(Project project)
Creates a new instance of TableModelAdapter

Parameters:
project - the current project

TableModelAdapter

public TableModelAdapter(Project project,
                         java.lang.Object c,
                         DataModel src)
Creates a new instance of TableModelAdpater

Parameters:
project - the current project
c - the table component
src - the model node to be adapted
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a copy of this adapter

Overrides:
clone in class java.lang.Object
Returns:
the copy
Throws:
java.lang.CloneNotSupportedException

setHasHeaderRow

public void setHasHeaderRow(boolean state)
Sets whether a header should be displayed.

Parameters:
state - true to display a header, false otherwise.

hasHeaderRow

public boolean hasHeaderRow()
Indicates whether a header should be displayed

Returns:
true to display a header, false otherwise.

getTranslated

public boolean getTranslated()
Gets the value of translateable fag


setTranslated

public void setTranslated(boolean tr)
Sets the value of translateable flag.


getUsesDatabase

public boolean getUsesDatabase()

setUsesDatabase

public void setUsesDatabase(boolean state)

getAdaptedModel

public DataModel getAdaptedModel()
Gets the encapsulated model node.

Returns:
the DataModel object.

getColumnCount

public int getColumnCount()
Gets the number of columns that should be shown in a table.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
the number of columns.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed
See Also:
getValueAt(int, int), isCellEditable(int, int)

getColumnName

public java.lang.String getColumnName(int columnIndex)
Gets the name of the column at the specified position.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column.
Returns:
the name of the column.

get

public java.lang.Object get(int i,
                            int fieldIdx)
Gets the individual list item value

Parameters:
i - The index of the listitem
fieldIdx - the field index
Returns:
The value of the listitem

get

public java.lang.Object get(int i)
Gets the individual list item value

Specified by:
get in interface ModelAdapter
Parameters:
i - The index of the list item
fieldIdx - the field index
Returns:
the value of the list item

getNumChildren

public int getNumChildren()
Gets the number of children of the adapted model node.

Specified by:
getNumChildren in interface ModelAdapter
Returns:
the number of children.

set

public void set(java.lang.Object o)
Sets the value of the adapted model node.

Specified by:
set in interface ModelAdapter
Parameters:
o - the value to be set.

getSelected

public java.lang.Object getSelected()
Gets the value of the selected item from the node.

Specified by:
getSelected in interface ModelAdapter
Returns:
the selected value.

getSelected

public java.lang.Object getSelected(int fieldIdx)
Gets the specified field's value.

Parameters:
fieldIdx - the index of the field
Returns:
the Object value.

setOutputField

public void setOutputField(int fieldIdx)
Sets the index of the output field.

Parameters:
fieldIdx - the new index

setDataModel

public void setDataModel(DataModel src)
Sets the new model node to be adapted.

Specified by:
setDataModel in interface ModelAdapter
Parameters:
src - the new model node.

getDataModel

public DataModel getDataModel()
Gets the encapsulated model node.

Specified by:
getDataModel in interface ModelAdapter
Returns:
the DataModel object.

find

public int find(java.lang.String key,
                int keyColumnIdx)
Locate a key value in the underlying data source

Parameters:
key - the key to locate
keyColumnIdx - the index of the key column
Returns:
the row/record index taht contains the first instance of the key, or -1 if the key is not found

sync

public void sync()
Force a sync/update of the table


getRowCount

public int getRowCount()
Gets the number of rows that will appera in a Table component.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number of rows.

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
columnIndex - the index of the column
Returns:
the common ancestor class of the object values in the model.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell. The cell is editable if its 'edit' attribute is 'true'

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Parameters:
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
Returns:
true if the cell is editable
See Also:
setValueAt(java.lang.Object, int, int)

addTableModelListener

public void addTableModelListener(javax.swing.event.TableModelListener l)
Adds a listener to the list that is notified each time a change to the data model occurs.

Specified by:
addTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

removeTableModelListener

public void removeTableModelListener(javax.swing.event.TableModelListener l)
Removes a listener from the list that is notified each time a change to the data model occurs.

Specified by:
removeTableModelListener in interface javax.swing.table.TableModel
Parameters:
l - the TableModelListener

configure

public void configure(java.util.Hashtable bindingConfig,
                      java.util.Hashtable instanceConfig)
Sets the configuration.

Specified by:
configure in interface ModelAdapterConfigurable
Parameters:
bindingConfig - the XML element which contains the binding configuration
instanceConfig - the XML element which contains the setup attributes of the binding instance

getModelAt

public java.lang.Object getModelAt(int rowIndex)
Get the model for the specified row

Parameters:
rowIndex - the row index
Returns:
the model value

getModelAt

public java.lang.Object getModelAt(int rowIndex,
                                   int columnIndex)
Deprecated. 

Get the model value

Parameters:
rowIndex - the row index
columnIndex - the column index

setModelListener

public void setModelListener(ModelListener listener)

init

public void init(ModelListener listener)

setCellEditable

public void setCellEditable(boolean state)
Set the editable state of the cell

Parameters:
state - the new editable state

getFieldName

public java.lang.String getFieldName(int column,
                                     java.lang.String field)
Get the displayable field name

Parameters:
column - the column index
field -
Returns: