net.xoetrope.optional.data.collection
Class XCollectionTableModel

java.lang.Object
  extended by net.xoetrope.xui.data.XModel
      extended by net.xoetrope.xui.data.XBaseModel
          extended by net.xoetrope.xui.data.table.XTableModel
              extended by net.xoetrope.optional.data.collection.XCollectionTableModel
All Implemented Interfaces:
java.lang.Cloneable, DumpWriter, XRowSelector

public class XCollectionTableModel
extends XTableModel
implements DumpWriter, XRowSelector

A wrapper for a database table allowing it to integrate with the XModel

The table model consists of a set of XRowModel objects and these in turn consist of DatabaseFieldModel nodes. These objects all act as wrappers for the DatabaseTable object and do not themselves maintain data.

Copyright: Copyright (c) 2003
License: see license.txt

$Revision: 2.12 $ License: see license.txt


Field Summary
protected  XProject currentProject
           
protected  java.lang.String modelId
           
 
Fields inherited from class net.xoetrope.xui.data.XBaseModel
addByDefault, appendByDefault, attributeNames, attributeValues, ID_ATTRIBUTE, NUM_FIXED_ATTRIBUTE, VALUE_ATTRIBUTE, values
 
Fields inherited from class net.xoetrope.xui.data.XModel
parentModel, tagName
 
Constructor Summary
XCollectionTableModel(XProject project, java.lang.String name, java.util.List fieldNames, java.util.List data)
          Create a new model node for a database table
 
Method Summary
 java.lang.Object append(java.lang.String id)
          This method does not nothing it is provided merely as an implementation of the XModel interface.
 void dump(java.io.Writer w)
          Write teh contents of this model node to a stream
 void first()
          Moves the table's cursor to the first row
 java.lang.Object get()
          gets the value attribute
 XModel get(int i)
          Get the XModel at element i
 java.lang.Object get(java.lang.String element)
          Get the value of the element located at the path in the element parameter If the attribName parameter is not null we get the value of the attributeValues
 java.lang.String getAttribName(int i)
          Gets the attribute name for field i.
 int getAttribute(java.lang.String attribName)
          returns the index of the attribiteNames array whose value is the same as the attribName
 java.lang.Object getAttribValue(int i)
          Get the value of an attribute (row)
 double getAttribValueAsDouble(int i)
          Get an attribute as a double value
 int getAttribValueAsInt(int i)
          Get an attribute as an int value
 java.lang.String getAttribValueAsString(int i)
          Get an attribute as a String object
 java.lang.String getFieldValue(int colIdx)
          Provides iterative access to the table values.
 java.lang.String getFieldValue(int rowIdx, int colIdx)
          Provides random access to the table values.
 java.lang.String getId()
          Gets the name attribute, by default the table name
 int getNumAttributes()
          Get the number of fields in this TableModel
 int getNumChildren()
          Gets the number of rows for this table
 int getSelectedRow()
          Get the row selection index
static XCollectionTableModel getTable(XProject currentProject, java.lang.String tableName)
          Look up a table by name in the overall model.
 java.lang.String getTagName()
          Gets the model element tag name, e.g.
 java.lang.String getValue()
          Provides iterative access to the table values.
 XModel getValue(int i)
          Get a child value/node (a XRowModel) at the specified index
 double getValueAsDouble(java.lang.String elementName)
          Gets the value attribute as a double value from the current record
 int getValueAsInt(java.lang.String elementName)
          Gets the value attribute of the specified node as an int.
 int hashCode()
          Get the hashcode for this model node
 boolean hasMoreRows()
          Has the table more records/rows?
 void last()
          Moves the table's cursor to the last row
 boolean next()
          Moves the table's cursor to the next row
 boolean previous()
          Moves the table's cursor to the previous row
 void retrieve()
          Get the table data.
 void set(java.lang.Object s)
          Sets the model value
 void set(java.lang.String attribName, java.lang.Object newObject)
          Set the value of the XModel located at the elementName
 void set(java.lang.String elementName, java.lang.String attribName, java.lang.Object newObject)
          Set the value of the attribute in the XModel located at the elementName
static void setAllowNull(boolean allow)
          Set a flag to determine how null values are treated.
 void setAttribValue(int i, java.lang.Object value)
          Sets the attribute value
 void setDirty(boolean isDirty)
          Ensures that the query is recalled.
 void setFieldValue(int rowIdx, int colIdx, java.lang.String newValue)
          Set a field value
 void setFieldValue(int colIdx, java.lang.String newValue)
          Set a field value
 void setName(java.lang.String newName)
          Sets the name attribute and constructs a new table of that name
 void setReadOnly(boolean b)
          Sets the read only flag indicating whether or not the underlying table is read-only
 void setSelectedRow(int sourceData)
          Set the row selection index
 void sync()
          Syncs the model with the service response is the xtable has been changed or if the node has timed out.
 
Methods inherited from class net.xoetrope.xui.data.XBaseModel
append, getAddByDefault, getAppendByDefault, getAttribFromPath, getAttribValueAsDouble, getBaseFromPath, getChildExists, getModel, getValueAsString, hasAutoId, hasAutoId, insertChildAt, remove, removeAttributes, removeChild, removeChild, removeChildren, setAddByDefault, setAppendByDefault, setAttribValue, setId, setNumAttributes, setNumChildren, swapNodes
 
Methods inherited from class net.xoetrope.xui.data.XModel
addModelListener, clear, fireModelUpdated, getParent, prefixOutputPath, reset, resetAttributes, setParent, setTagName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modelId

protected java.lang.String modelId

currentProject

protected XProject currentProject
Constructor Detail

XCollectionTableModel

public XCollectionTableModel(XProject project,
                             java.lang.String name,
                             java.util.List fieldNames,
                             java.util.List data)
Create a new model node for a database table

Parameters:
project - the owner project
name - the name of this model node
fieldNames - the name of the fields
data - the data
Method Detail

setAllowNull

public static void setAllowNull(boolean allow)
Set a flag to determine how null values are treated.

Parameters:
allow - if false then nulls are return as zero or an empty string, if true the null is returned for string types and Double.NaN for doubles and Integer.MIN_VALUE for int fields and so on

setDirty

public void setDirty(boolean isDirty)
Ensures that the query is recalled. This is important where PreparedStatements are used to retrieve the data. The query itself does not change but the parameters do.

Parameters:
isDirty - boolean to set the dirty flag

setName

public void setName(java.lang.String newName)
Sets the name attribute and constructs a new table of that name

Parameters:
newName - the new name

hashCode

public int hashCode()
Get the hashcode for this model node

Overrides:
hashCode in class XBaseModel
Returns:
the hashcode

setReadOnly

public void setReadOnly(boolean b)
Sets the read only flag indicating whether or not the underlying table is read-only

Parameters:
b - true for a read-only table.

get

public java.lang.Object get(java.lang.String element)
Get the value of the element located at the path in the element parameter If the attribName parameter is not null we get the value of the attributeValues

Overrides:
get in class XBaseModel
Parameters:
element - The path to the XModel we require
Returns:
The value of the XModel or the attribute

set

public void set(java.lang.String elementName,
                java.lang.String attribName,
                java.lang.Object newObject)
Set the value of the attribute in the XModel located at the elementName

Parameters:
elementName - The path to the XModel in the format 'base/foo
attribName - The name of the attribute whose value we require
newObject - The new value of the attribute

set

public void set(java.lang.String attribName,
                java.lang.Object newObject)
Set the value of the XModel located at the elementName

Overrides:
set in class XBaseModel
Parameters:
attribName - The path to the XModel in the format 'base/foo
newObject - The new value of the XModel

get

public XModel get(int i)
Get the XModel at element i

Overrides:
get in class XBaseModel
Parameters:
i - The index of the values array
Returns:
The XModel at location i

get

public java.lang.Object get()
gets the value attribute

Overrides:
get in class XBaseModel
Returns:
the value of the model

append

public java.lang.Object append(java.lang.String id)
This method does not nothing it is provided merely as an implementation of the XModel interface. A child or attribute can be logically appended to a table node.

Overrides:
append in class XBaseModel
Parameters:
id - the node id
Returns:
null as nothing is appended

set

public void set(java.lang.Object s)
Sets the model value

Overrides:
set in class XBaseModel
Parameters:
s - the new value

getAttribValue

public java.lang.Object getAttribValue(int i)
Get the value of an attribute (row)

Overrides:
getAttribValue in class XBaseModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribValueAsString

public java.lang.String getAttribValueAsString(int i)
Get an attribute as a String object

Specified by:
getAttribValueAsString in class XTableModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribValueAsDouble

public double getAttribValueAsDouble(int i)
Get an attribute as a double value

Overrides:
getAttribValueAsDouble in class XBaseModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribValueAsInt

public int getAttribValueAsInt(int i)
Get an attribute as an int value

Overrides:
getAttribValueAsInt in class XBaseModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribute

public int getAttribute(java.lang.String attribName)
returns the index of the attribiteNames array whose value is the same as the attribName

Overrides:
getAttribute in class XBaseModel
Parameters:
attribName - The name of the attribute we are trying to locate
Returns:
The index of the attributeNames array containg the name

sync

public void sync()
Description copied from class: XTableModel
Syncs the model with the service response is the xtable has been changed or if the node has timed out.

Specified by:
sync in class XTableModel

retrieve

public void retrieve()
Get the table data.

Specified by:
retrieve in class XTableModel

first

public void first()
Moves the table's cursor to the first row


last

public void last()
Moves the table's cursor to the last row


next

public boolean next()
Moves the table's cursor to the next row

Returns:
true if the operation succeeded

hasMoreRows

public boolean hasMoreRows()
Has the table more records/rows?

Returns:
true if the current row is not on the last row in the table

previous

public boolean previous()
Moves the table's cursor to the previous row

Returns:
true if the operation succeeded

getValue

public java.lang.String getValue()
Provides iterative access to the table values. The current row in the table is used to index the data. This method does not implicitly retrieve the data so you must call the retrieve method explicitly.

Returns:
the data

getValue

public XModel getValue(int i)
Get a child value/node (a XRowModel) at the specified index

Parameters:
i - The index into the values array
Returns:
The XModel at position i of the values array.

getFieldValue

public java.lang.String getFieldValue(int colIdx)
Provides iterative access to the table values. The current row in the table is used to index the data. This method does not implicitly retrieve the data so you must call the retrieve method explicitly.

Specified by:
getFieldValue in class XTableModel
Parameters:
colIdx - the column of field index
Returns:
the data

getFieldValue

public java.lang.String getFieldValue(int rowIdx,
                                      int colIdx)
Provides random access to the table values. This method does not implicitly retrieve the data so you must call the retrieve method explicitly.

Specified by:
getFieldValue in class XTableModel
Parameters:
rowIdx - the row index
colIdx - the column of field index
Returns:
the data

setFieldValue

public void setFieldValue(int colIdx,
                          java.lang.String newValue)
Set a field value

Specified by:
setFieldValue in class XTableModel
Parameters:
colIdx - the field index, zero based
newValue - the new field value

setFieldValue

public void setFieldValue(int rowIdx,
                          int colIdx,
                          java.lang.String newValue)
Set a field value

Specified by:
setFieldValue in class XTableModel
Parameters:
rowIdx - the row index, zero based
colIdx - the field index, zero based
newValue - the new field value

getValueAsDouble

public double getValueAsDouble(java.lang.String elementName)
Gets the value attribute as a double value from the current record

Overrides:
getValueAsDouble in class XBaseModel
Parameters:
elementName - the field/column name
Returns:
the field value

getValueAsInt

public int getValueAsInt(java.lang.String elementName)
Gets the value attribute of the specified node as an int.

Overrides:
getValueAsInt in class XBaseModel
Parameters:
elementName - the field name
Returns:
the field value

getAttribName

public java.lang.String getAttribName(int i)
Gets the attribute name for field i. For this node the table field name is returned.

Overrides:
getAttribName in class XBaseModel
Parameters:
i - The index of the attributeNames array whose value we want
Returns:
The string value of the attributeNames array at position i

getId

public java.lang.String getId()
Gets the name attribute, by default the table name

Overrides:
getId in class XBaseModel
Returns:
the model node's ID

setAttribValue

public void setAttribValue(int i,
                           java.lang.Object value)
Sets the attribute value

Overrides:
setAttribValue in class XBaseModel
Parameters:
i - The index of the attributeValues array whose value we want
value - the value object

getNumChildren

public int getNumChildren()
Gets the number of rows for this table

Overrides:
getNumChildren in class XBaseModel
Returns:
the number of rows

getNumAttributes

public int getNumAttributes()
Get the number of fields in this TableModel

Overrides:
getNumAttributes in class XBaseModel
Returns:
the number of fields

getTagName

public java.lang.String getTagName()
Gets the model element tag name, e.g. 'Component' from the XML fragment
Overrides:
getTagName in class XModel
Returns:
the model element name

getTable

public static XCollectionTableModel getTable(XProject currentProject,
                                             java.lang.String tableName)
Look up a table by name in the overall model.

Parameters:
tableName - the table name
Returns:
the table node

dump

public void dump(java.io.Writer w)
Write teh contents of this model node to a stream

Specified by:
dump in interface DumpWriter
Parameters:
w - the write/stream

setSelectedRow

public void setSelectedRow(int sourceData)
Set the row selection index

Specified by:
setSelectedRow in interface XRowSelector
Parameters:
sourceData - the new row selection index (zero based)

getSelectedRow

public int getSelectedRow()
Get the row selection index

Specified by:
getSelectedRow in interface XRowSelector
Returns:
the current row selection index (zero based)