com.webmethods.caf.faces.data.object
Class ListTableContentProvider

java.lang.Object
  extended by com.webmethods.caf.faces.bean.PageFlowScopeAdapter
      extended by com.webmethods.caf.faces.data.object.ListTableContentProvider
All Implemented Interfaces:
IPageFlowScopeAdapter, IAddressableTableContentProvider, IContentProvider, IReorderableTableContentProvider, ISortableTableContentProvider, ITableContentProvider, IUpdateableContentProvider, IUpdateableTableContentProvider, Serializable
Direct Known Subclasses:
FilterableListTableContentProvider, SelectableListTableContentProvider, TaskAuditContentProvider

public class ListTableContentProvider
extends PageFlowScopeAdapter
implements Serializable, IUpdateableTableContentProvider, ISortableTableContentProvider, IReorderableTableContentProvider

Adapts List and array objects to the IUpdateableContentProvider and ISortableTableContentProvider enabling their use with table and tree table UI controls. The properties of the element of the list or array are available as properties on this provider. For example:

 class Item {
                public int getId();
                public String getName(); 
 };
 
 Item[] items = new Items[] {....};
 IUpdateableContentProvider provider = new ListTableContentProvider(items);
 
 for (int i = 0; i < provider.getRowCount(); i++) {
                provider.setRowIndex(i);
                if (provider.isRowAvailable()) {
                        Integer itemId = (Integer)provider.getValue("id"); // returns item id
                        String itemName = (String)provider.getValue("name"); // returns item name
 
                        provider.setValue("name", "item name" + i); // updates item name
                }
 };
 

ListTableContentProvider.setList(List) or ListTableContentProvider.setArray(Object[]) property must be set before use.

ListTableContentProvider.setRowIdBinding(ValueBinding) must be set to use this implementation as an IAddressableTableContentProvider. Even so, this implementation is not optimized for addressing rows by id; SelectableListTableContentProvider is better optimized for this purpose.

See Also:
Serialized Form

Field Summary
protected  Object[] m_array
          Original array backing the list backing this table.
protected  boolean m_canTemplateRow
          True if table can be used in template mode; true by default.
protected  int m_index
          Current row index.
protected  List m_list
          List backing this table.
protected  MethodBinding m_onCreateRow
           
protected  MethodBinding m_onDeleteRow
           
protected  ValueBinding m_rowId
          Value binding used to calculate row id.
protected  Class m_rowType
          Row object class.
protected  ISortInfo m_sort
          Current sort state.
protected  Object m_templateRow
          Current template row object.
protected  String m_var
          Row variable name.
 
Fields inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
fExpireWithPageFlow
 
Constructor Summary
ListTableContentProvider()
          Default constructor.
ListTableContentProvider(List list)
          Initializes provider with the given list
ListTableContentProvider(Object[] array)
          Initializes provider with the given array of objects
 
Method Summary
protected  String calculateRowId(int index, Object data)
          Calculates row id from the row data object using ListTableContentProvider.getRowIdBinding() expression.
protected  String calculateRowId(Object data)
          Deprecated. use ListTableContentProvider.calculateRowId(int,Object) Calculates row id from the row data object using ListTableContentProvider.getRowIdBinding() expression.
 void createRow()
          Creates new row and adds it to the list.
 void deleteRow()
          Deletes current row from the list.
 Object[] getArray()
          Returns (a copy of the) array previously set as the source
 boolean getCanTemplateRow()
          True if provider can be put into template row state.
 Object getCurrentRow()
          Returns current row.
 List getList()
          Returns wrapped list object
 MethodBinding getOnCreateRow()
           
 MethodBinding getOnDeleteRow()
           
 Object[] getPropertyKeys()
          Returns property keys for the current row object which is an element of the wrapped array or the list by ListTableContentProvider.getRowIndex() index.
 int getRowCount()
          Return the number of rows of data objects represented by this DataModel.
 String getRowId()
          Returns unique identifier for the current row.
 ValueBinding getRowIdBinding()
          Returns row id binding
 int getRowIndex()
          Return the zero-relative index of the currently selected row.
 Class getRowType()
          Returns row object class which is used for creation of a new row.
 String getRowVariable()
           Returns row variable name.
 ISortInfo getSort()
          Returns current sort info.
 Class getType(Object propertyKey)
          Returns java type of the given property
 Object getValue(Object propertyKey)
          Returns value of the given property
 boolean hasProperty(Object propertyKey)
          Checks if the given property is supported by this content provider
 boolean isAddressable()
          Checks if this content provider truly is addressable.
 boolean isReadOnly(Object propertyKey)
          Returns true if the given property is readonly.
 boolean isReorderable()
          True if the rows in this table are re-orderable.
 boolean isRowAvailable()
          Return a flag indicating whether there is rowData available at the current rowIndex.
 boolean isTemplateRow()
          Is provider in state where it returns properties for template pseudo-row.
 void moveTo(int index)
          Moves the current row to the specified index.
protected  Object newRow()
          Creates a new, blank row object to be insterted into the list.
 void setArray(Object[] array)
          Creates a list object out of source array and sets it as the source
 void setCanTemplateRow(boolean value)
          True if provider can be put into template row state.
 void setCurrentRow(Object row)
          Sets new current row object
 void setList(List list)
          Sets source list object.
 void setOnCreateRow(MethodBinding onNewRow)
          Sets custom handler for ListTableContentProvider.createRow() method
 void setOnDeleteRow(MethodBinding deleteRow)
          Sets custom handler for ListTableContentProvider.deleteRow() method
 void setRowById(String id)
          Selects current row by its id.
 void setRowId(String id)
          JavaBean property setter for ListTableContentProvider.setRowById(String)
 void setRowIdBinding(ValueBinding binding)
          Sets new row id binding expression.
 void setRowIndex(int rowIndex)
          Set the zero-relative index of the currently selected row, or -1 to indicate that we are not positioned on a row.
 void setRowType(Class rowType)
          Sets row object class to use for new row creation.
 void setRowVariable(String var)
           Sets row variable name to use for accessing row specific data.
 void setSort(ISortInfo sort)
          Sets new sort info, re-sorting the table (if necessary).
 void setTemplateRow()
          Sets provider to state where it returns properties for template pseudo-row.
 void setValue(Object propertyKey, Object value)
          Sets new value of the given property
protected  void sort()
          (Re-)sorts list according to sort info.
 String toString()
          Returns string representation of content.
 
Methods inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
getExpireWithPageFlow, setExpireWithPageFlow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_list

protected List m_list
List backing this table.


m_array

protected Object[] m_array
Original array backing the list backing this table.


m_index

protected int m_index
Current row index.


m_templateRow

protected Object m_templateRow
Current template row object. Null if not in template mode.


m_var

protected String m_var
Row variable name.


m_sort

protected ISortInfo m_sort
Current sort state. Never null.


m_rowId

protected ValueBinding m_rowId
Value binding used to calculate row id. May be null if table not addressable.


m_rowType

protected Class m_rowType
Row object class.


m_canTemplateRow

protected boolean m_canTemplateRow
True if table can be used in template mode; true by default.


m_onCreateRow

protected MethodBinding m_onCreateRow

m_onDeleteRow

protected MethodBinding m_onDeleteRow
Constructor Detail

ListTableContentProvider

public ListTableContentProvider()

Default constructor.

ListTableContentProvider.setList(List) or ListTableContentProvider.setArray(Object[]) property must be set before use.


ListTableContentProvider

public ListTableContentProvider(List list)
Initializes provider with the given list

Parameters:
list - list of objects

ListTableContentProvider

public ListTableContentProvider(Object[] array)
Initializes provider with the given array of objects

Parameters:
array - array of objects
Method Detail

toString

public String toString()
Description copied from interface: IContentProvider
Returns string representation of content.

Specified by:
toString in interface IContentProvider
Overrides:
toString in class Object
Returns:
String representation of the wrapped content

getPropertyKeys

public Object[] getPropertyKeys()
Returns property keys for the current row object which is an element of the wrapped array or the list by ListTableContentProvider.getRowIndex() index.

Specified by:
getPropertyKeys in interface IContentProvider
Returns:
array of String or Integer property keys

getType

public Class getType(Object propertyKey)
              throws PropertyNotFoundException
Description copied from interface: IContentProvider
Returns java type of the given property

Specified by:
getType in interface IContentProvider
Parameters:
propertyKey - the property key of type String or Integer
Returns:
property java Class
Throws:
PropertyNotFoundException - if property is not supported

getValue

public Object getValue(Object propertyKey)
                throws EvaluationException,
                       PropertyNotFoundException
Description copied from interface: IContentProvider
Returns value of the given property

Specified by:
getValue in interface IContentProvider
Parameters:
propertyKey - the property key of type String or Integer
Returns:
value of the property, can be null
Throws:
EvaluationException - if error during property evaluation
PropertyNotFoundException - if property is not supported

hasProperty

public boolean hasProperty(Object propertyKey)
Description copied from interface: IContentProvider
Checks if the given property is supported by this content provider

Specified by:
hasProperty in interface IContentProvider
Parameters:
propertyKey - property key of type String or Integer
Returns:
true if property is supported

isReadOnly

public boolean isReadOnly(Object propertyKey)
                   throws EvaluationException,
                          PropertyNotFoundException
Description copied from interface: IUpdateableContentProvider

Returns true if the given property is readonly. If it is readonly, IUpdateableContentProvider.setValue(Object, Object) will definitely fail.

Specified by:
isReadOnly in interface IUpdateableContentProvider
Parameters:
propertyKey - property key of type String or Integer
Returns:
true if the property is readonly
Throws:
EvaluationException
PropertyNotFoundException

setValue

public void setValue(Object propertyKey,
                     Object value)
              throws EvaluationException,
                     PropertyNotFoundException
Description copied from interface: IUpdateableContentProvider

Sets new value of the given property

Specified by:
setValue in interface IUpdateableContentProvider
Parameters:
propertyKey - property key of type String or Integer
value - new property value
Throws:
EvaluationException - if error happens during property assigment
PropertyNotFoundException - if property is not found

getRowCount

public int getRowCount()
Description copied from interface: ITableContentProvider
Return the number of rows of data objects represented by this DataModel.

Return -1, if the number of rows is unknown, or no wrappedData is available.

Specified by:
getRowCount in interface ITableContentProvider
See Also:
DataModel

getRowIndex

public int getRowIndex()
Description copied from interface: ITableContentProvider
Return the zero-relative index of the currently selected row.

If we are not currently positioned on a row, or no wrappedData is available, return -1.

Specified by:
getRowIndex in interface ITableContentProvider
See Also:
DataModel

isRowAvailable

public boolean isRowAvailable()
Description copied from interface: ITableContentProvider
Return a flag indicating whether there is rowData available at the current rowIndex. If no wrappedData is available, return false.

Specified by:
isRowAvailable in interface ITableContentProvider
See Also:
DataModel

setRowIndex

public void setRowIndex(int rowIndex)
Description copied from interface: ITableContentProvider
Set the zero-relative index of the currently selected row, or -1 to indicate that we are not positioned on a row.

Specified by:
setRowIndex in interface ITableContentProvider
See Also:
DataModel

getRowVariable

public String getRowVariable()
Description copied from interface: ITableContentProvider

Returns row variable name.

If specified row variable can be used to access current row data for the provider internal needs, like sorting or addressing.

Specified by:
getRowVariable in interface ITableContentProvider
Returns:
row variable name or null if not specified
See Also:
ITableContentProvider.setRowVariable(String)

setRowVariable

public void setRowVariable(String var)
Description copied from interface: ITableContentProvider

Sets row variable name to use for accessing row specific data. For example, if the provider wrapps an array of a data objects with id property and the variable name is item, then the provider implementation can access id property of each record as item.id.

This property should set only once at the provider initialization time

Specified by:
setRowVariable in interface ITableContentProvider

isAddressable

public boolean isAddressable()
Description copied from interface: IAddressableTableContentProvider
Checks if this content provider truly is addressable.

Specified by:
isAddressable in interface IAddressableTableContentProvider
Returns:
true if addressable.

getRowId

public String getRowId()
Description copied from interface: IAddressableTableContentProvider
Returns unique identifier for the current row. If no current row is avaiable, returns null.

Specified by:
getRowId in interface IAddressableTableContentProvider
Returns:
current row id or null

setRowById

public void setRowById(String id)
Description copied from interface: IAddressableTableContentProvider
Selects current row by its id. If id doesn't identify a row, makes no row current (equivalent to setRowIndex(-1)).

Specified by:
setRowById in interface IAddressableTableContentProvider
Parameters:
id - row id to find and make current

setRowId

public void setRowId(String id)
JavaBean property setter for ListTableContentProvider.setRowById(String)

Parameters:
id -

getCanTemplateRow

public boolean getCanTemplateRow()
Description copied from interface: IUpdateableTableContentProvider
True if provider can be put into template row state.

Specified by:
getCanTemplateRow in interface IUpdateableTableContentProvider
See Also:
#setTemplateRow()}

setCanTemplateRow

public void setCanTemplateRow(boolean value)
Description copied from interface: IUpdateableTableContentProvider
True if provider can be put into template row state. Default: true

Specified by:
setCanTemplateRow in interface IUpdateableTableContentProvider

isTemplateRow

public boolean isTemplateRow()
Description copied from interface: IUpdateableTableContentProvider
Is provider in state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null; ITableContentProvider.isRowAvailable() returns false. Setting the row index or id to any value removes provider from this state.

Specified by:
isTemplateRow in interface IUpdateableTableContentProvider

setTemplateRow

public void setTemplateRow()
Description copied from interface: IUpdateableTableContentProvider
Sets provider to state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null; ITableContentProvider.isRowAvailable() returns false. Setting the row index or id to any value removes provider from this state.

Specified by:
setTemplateRow in interface IUpdateableTableContentProvider

createRow

public void createRow()
Creates new row and adds it to the list. Calls ListTableContentProvider.newRow() method to instantiate an instance of the row object and inserts it before the current row, or at the end of the list if no current row.

Specified by:
createRow in interface IUpdateableTableContentProvider

deleteRow

public void deleteRow()
Deletes current row from the list.

Specified by:
deleteRow in interface IUpdateableTableContentProvider
See Also:
ITableContentProvider.getRowIndex()

isReorderable

public boolean isReorderable()
Description copied from interface: IReorderableTableContentProvider
True if the rows in this table are re-orderable.

Specified by:
isReorderable in interface IReorderableTableContentProvider

moveTo

public void moveTo(int index)
Description copied from interface: IReorderableTableContentProvider
Moves the current row to the specified index. Note that following the successful completion of this operation, the current row index should be set to the specified index.

Specified by:
moveTo in interface IReorderableTableContentProvider
Parameters:
index - (Zero-based) new row index.

getSort

public ISortInfo getSort()
Description copied from interface: ISortableTableContentProvider
Returns current sort info. Never null.

Specified by:
getSort in interface ISortableTableContentProvider
Returns:
currenly set sort info

setSort

public void setSort(ISortInfo sort)
Description copied from interface: ISortableTableContentProvider
Sets new sort info, re-sorting the table (if necessary). This does not change the model's rowIndex property, even though it will probably now point to a different row.

Specified by:
setSort in interface ISortableTableContentProvider
Parameters:
sort - Sort info, must not be null.

getCurrentRow

public Object getCurrentRow()
Returns current row. If no row is current, returns first row. If doesn't have first row, returns null.

Specified by:
getCurrentRow in interface ITableContentProvider
Returns:
current row object or null
See Also:
ITableContentProvider.isRowAvailable()

setCurrentRow

public void setCurrentRow(Object row)
Description copied from interface: IUpdateableTableContentProvider
Sets new current row object

Specified by:
setCurrentRow in interface IUpdateableTableContentProvider
Parameters:
row - new row object to replace object returned by ITableContentProvider.getCurrentRow()

sort

protected void sort()
(Re-)sorts list according to sort info.

See Also:
ListTableContentProvider.setSort(ISortInfo)

calculateRowId

protected String calculateRowId(Object data)
Deprecated. use ListTableContentProvider.calculateRowId(int,Object) Calculates row id from the row data object using ListTableContentProvider.getRowIdBinding() expression.

Parameters:
data - row data object
Returns:
row id

calculateRowId

protected String calculateRowId(int index,
                                Object data)
Calculates row id from the row data object using ListTableContentProvider.getRowIdBinding() expression.

Parameters:
index - row index
data - row data object
Returns:
row id

newRow

protected Object newRow()
Creates a new, blank row object to be insterted into the list. By default returns new row created by #templateRow().

Returns:
New row object
Throws:
IllegalStateException - if row object type cannot be determined

getList

public List getList()
Returns wrapped list object

Returns:
null if not set

setList

public void setList(List list)
Sets source list object. Reset row index to -1.

Parameters:
list - the list

setArray

public void setArray(Object[] array)
Creates a list object out of source array and sets it as the source

Parameters:
array - the array of objects

getArray

public Object[] getArray()
Returns (a copy of the) array previously set as the source

Returns:
null if array was not set

getRowType

public Class getRowType()
Returns row object class which is used for creation of a new row.

Returns:
row object type or null if not known

setRowType

public void setRowType(Class rowType)
Sets row object class to use for new row creation.

Parameters:
rowType - the row type

getRowIdBinding

public ValueBinding getRowIdBinding()
Returns row id binding

Returns:
null if not set

setRowIdBinding

public void setRowIdBinding(ValueBinding binding)
Sets new row id binding expression. Must use ListTableContentProvider.getRowVariable() to access data on the row object.

Parameters:
binding - value binding expression to evaluate row id

getOnCreateRow

public MethodBinding getOnCreateRow()
See Also:
ListTableContentProvider.setOnCreateRow(MethodBinding)

setOnCreateRow

public void setOnCreateRow(MethodBinding onNewRow)
Sets custom handler for ListTableContentProvider.createRow() method

Parameters:
onNewRow - method binding expression for a method that is called from ListTableContentProvider.createRow()

getOnDeleteRow

public MethodBinding getOnDeleteRow()
See Also:
ListTableContentProvider.setOnDeleteRow(MethodBinding)

setOnDeleteRow

public void setOnDeleteRow(MethodBinding deleteRow)
Sets custom handler for ListTableContentProvider.deleteRow() method

Parameters:
onNewRow - method binding expression for a method that is called from ListTableContentProvider.deleteRow()