org.formaria.swing.table
Class TablePojoModelAdapter

java.lang.Object
  extended by org.formaria.swing.table.TableModelAdapter
      extended by org.formaria.swing.table.TablePojoModelAdapter
All Implemented Interfaces:
java.lang.Cloneable, javax.swing.table.TableModel, ModelAdapter, ModelAdapterConfigurable, ViewProvider

public class TablePojoModelAdapter
extends TableModelAdapter
implements java.lang.Cloneable, ViewProvider

Adapts the PojoModel nodes for user with Table components.

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


Field Summary
protected  java.lang.String[] columns
           
protected  java.util.Hashtable<java.lang.String,java.lang.String> displayField
           
protected  boolean enabledByDefault
           
protected  java.util.Hashtable<java.lang.String,java.lang.String> excludes
           
protected  java.lang.String[] exclusions
           
protected  java.lang.String[] fieldOrder
           
protected  java.util.ArrayList<java.beans.PropertyDescriptor> fields
           
protected  java.util.ArrayList<java.lang.String> paths
           
protected  java.beans.PropertyDescriptor[] properties
           
protected  java.util.Hashtable<java.lang.String,XmlElement> viewFields
           
protected  XmlElement viewModel
           
protected  java.util.ArrayList<java.lang.String> viewOrder
           
protected  java.lang.String viewPath
           
 
Fields inherited from class org.formaria.swing.table.TableModelAdapter
currentProject, editable, headerRow, listeners, model, modelListener, outputFieldIdx, rootModel, table, translateable, translator, usesDatabase
 
Constructor Summary
TablePojoModelAdapter(Project project)
          Creates a new instance of XTablePojoModelAdapter
TablePojoModelAdapter(Project project, java.lang.Object c, DataModel src)
          Creates a new instance of XPojoModelAdapter
 
Method Summary
 java.lang.Object clone()
          Create a copy of this adapter
 void configure(java.util.Hashtable bindingConfig, java.util.Hashtable instanceConfig)
          Retrieves the fieldOrder attribute's value from the binding configuration specifying the underlying POJO's properties that should be displayed in the bound XTable component.
 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 idx)
          Gets the name of the column at the specified position.
 java.lang.String[] getColumns()
          Returns the column names that are to be shown in the XTable component.
protected  void getCompoundProperty(java.beans.PropertyDescriptor[] pp, java.lang.String target, java.lang.String fieldName)
          Get the property descriptor corresponding to a compound path using '.' separators.
protected  void getCompoundProperty(java.beans.PropertyDescriptor properties, java.lang.String target, java.lang.String fieldName)
           
 java.lang.Object getCompoundValueAt(int rowIndex, java.lang.String target)
          Gets the value at the specified table's cell.
protected  java.lang.String getDisplayName(int column, java.lang.String fieldName, java.lang.String defaultName)
          Try to get the display name
 java.lang.String getFieldName(int column, java.lang.String field)
          Get the displayable field name
 int getNumChildren()
          Gets the number of children of the encapsulated POJO model node.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Gets the value at the specified table's cell.
 java.lang.String getViewAttrib(int column, java.lang.String fieldName, java.lang.String attribName)
          Get the view field attribute
 boolean isCellEditable(int rowIndex, int columnIndex)
          Indicates whether the specified cell is editable.
protected  boolean isFieldEnabled(java.lang.String fieldName)
           
protected  boolean isFieldExcluded(java.lang.String name)
          Is the field excluded from the form?
protected  boolean isFieldVisible(java.lang.String fieldName)
           
 void loadDefaultViewFile(java.lang.Class objectClass)
          Attempt to load the default view file.
protected  void retrieveColumnNames()
          Retrieves column names that should be shown in a table.
 void set(java.lang.Object o)
          Sets the value of the adapted model node.
 void setDataModel(DataModel src)
          Sets the new model node to be adapted.
 void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
          Sets the value at the specified table's cell.
 void setViewFile(java.lang.String resName)
          Read the view file
 void setViewPath(java.lang.String path)
          Read the view file
 
Methods inherited from class org.formaria.swing.table.TableModelAdapter
addTableModelListener, find, get, get, getAdaptedModel, getDataModel, getModelAt, getModelAt, getRowCount, getSelected, getSelected, getTranslated, getUsesDatabase, hasHeaderRow, init, removeTableModelListener, setCellEditable, setHasHeaderRow, setModelListener, setOutputField, setTranslated, setUsesDatabase, sync
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldOrder

protected java.lang.String[] fieldOrder

exclusions

protected java.lang.String[] exclusions

columns

protected java.lang.String[] columns

viewOrder

protected java.util.ArrayList<java.lang.String> viewOrder

displayField

protected java.util.Hashtable<java.lang.String,java.lang.String> displayField

excludes

protected java.util.Hashtable<java.lang.String,java.lang.String> excludes

viewFields

protected java.util.Hashtable<java.lang.String,XmlElement> viewFields

viewModel

protected XmlElement viewModel

viewPath

protected java.lang.String viewPath

fields

protected java.util.ArrayList<java.beans.PropertyDescriptor> fields

paths

protected java.util.ArrayList<java.lang.String> paths

enabledByDefault

protected boolean enabledByDefault

properties

protected java.beans.PropertyDescriptor[] properties
Constructor Detail

TablePojoModelAdapter

public TablePojoModelAdapter(Project project)
Creates a new instance of XTablePojoModelAdapter

Parameters:
project - the current project.

TablePojoModelAdapter

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

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 TableModelAdapter
Returns:
the copy
Throws:
java.lang.CloneNotSupportedException

getColumns

public java.lang.String[] getColumns()
Returns the column names that are to be shown in the XTable component.

Returns:
table containing column names.

getNumChildren

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

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

getColumnName

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

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

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
Overrides:
getColumnCount in class TableModelAdapter
Returns:
the number of columns.

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
Overrides:
getColumnClass in class TableModelAdapter
Parameters:
columnIndex - the index of the column
Returns:
the common ancestor class of the object values in the model.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Gets the value at the specified table's cell.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class TableModelAdapter
Parameters:
rowIndex - the row of the cell
columnIndex - the column of the cell
Returns:
the value at the specified cell.

getCompoundValueAt

public java.lang.Object getCompoundValueAt(int rowIndex,
                                           java.lang.String target)
Gets the value at the specified table's cell.

Parameters:
rowIndex - the row of the cell
columnIndex - the column of the cell
Returns:
the value at the specified cell.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Indicates whether the specified cell is editable.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class TableModelAdapter
Parameters:
rowIndex - cell's row
columnIndex - cell's column
Returns:
true if the cell is editable, false otherwise.
See Also:
TableModelAdapter.setValueAt(java.lang.Object, int, int)

setValueAt

public void setValueAt(java.lang.Object value,
                       int rowIndex,
                       int columnIndex)
Sets the value at the specified table's cell.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class TableModelAdapter
Parameters:
value - the value to be set.
rowIndex - the row of the cell.
columnIndex - the column of the cell
See Also:
TableModelAdapter.getValueAt(int, int), TableModelAdapter.isCellEditable(int, int)

configure

public void configure(java.util.Hashtable bindingConfig,
                      java.util.Hashtable instanceConfig)
Retrieves the fieldOrder attribute's value from the binding configuration specifying the underlying POJO's properties that should be displayed in the bound XTable component.

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

set

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

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

setDataModel

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

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

loadDefaultViewFile

public void loadDefaultViewFile(java.lang.Class objectClass)
Attempt to load the default view file. The file name is taken from the data model path and it is assumed that the view files is in the pages/views folder. The method is called as part of the population of the panel with input fields.


setViewFile

public void setViewFile(java.lang.String resName)
Read the view file

Parameters:
resName -

setViewPath

public void setViewPath(java.lang.String path)
Read the view file

Parameters:
path - the name of the model path containing the view

retrieveColumnNames

protected void retrieveColumnNames()
Retrieves column names that should be shown in a table. The columns are retrieve according to the values underlying POJO's type and fieldOrder and exclusions arrays.


isFieldExcluded

protected boolean isFieldExcluded(java.lang.String name)
Is the field excluded from the form?

Parameters:
name - the field/property name
Returns:
true if the field is to be excluded

isFieldEnabled

protected boolean isFieldEnabled(java.lang.String fieldName)

isFieldVisible

protected boolean isFieldVisible(java.lang.String fieldName)

getViewAttrib

public java.lang.String getViewAttrib(int column,
                                      java.lang.String fieldName,
                                      java.lang.String attribName)
Get the view field attribute

Specified by:
getViewAttrib in interface ViewProvider
Parameters:
column - the column index
fieldName - the field/property name
attribName - the name of the attribute
Returns:
the value of the named attribute

getDisplayName

protected java.lang.String getDisplayName(int column,
                                          java.lang.String fieldName,
                                          java.lang.String defaultName)
Try to get the display name

Parameters:
column - the column index
fieldName -
defaultName -
Returns:

getFieldName

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

Overrides:
getFieldName in class TableModelAdapter
Parameters:
column - the column index
field -
Returns:

getCompoundProperty

protected void getCompoundProperty(java.beans.PropertyDescriptor[] pp,
                                   java.lang.String target,
                                   java.lang.String fieldName)
                            throws java.beans.IntrospectionException
Get the property descriptor corresponding to a compound path using '.' separators.

Parameters:
pp -
target -
Throws:
java.beans.IntrospectionException

getCompoundProperty

protected void getCompoundProperty(java.beans.PropertyDescriptor properties,
                                   java.lang.String target,
                                   java.lang.String fieldName)
                            throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException