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

java.lang.Object
  extended by com.webmethods.caf.faces.bean.PageFlowScopeAdapter
      extended by com.webmethods.caf.faces.data.object.ListTableContentProvider
          extended by com.webmethods.caf.faces.data.object.SelectableListTableContentProvider
All Implemented Interfaces:
IPageFlowScopeAdapter, IAddressableTableContentProvider, IContentProvider, IRefreshable, IRefreshableContentProvider, IReorderableTableContentProvider, ISelectableTableContentProvider, ISortableTableContentProvider, ITableContentProvider, IUpdateableContentProvider, IUpdateableTableContentProvider, Serializable
Direct Known Subclasses:
BaseTaskSearchContentProvider, DirectorySearchProvider, FilterableSelectableListTableContentProvider, PageableTableContentProvider, PeopleSearchProvider, ProcessSearchProvider, TaskSearchContentProvider, XMLTableContentProvider

public class SelectableListTableContentProvider
extends ListTableContentProvider
implements ISelectableTableContentProvider, IRefreshableContentProvider

Extends ListTableContentProvider with select rows capabilities. Each row must have an ID calculated using ListTableContentProvider.setRowIdBinding(ValueBinding) property.

                 class Item {
                        public int getId() {};
                        public String getName() {}; 
                 };
                         
                 Item[] items = new Item[] {};
                 ISelectableTableContentProvider provider = new SelectableListTableContentProvider(items, "varitem.id", "varitem");
                         
                 for (int i = 0; i < provider.getRowCount(); i++) {
                                provider.setRowIndex(i);
                                if (provider.isRowAvailable()) {
                                        Integer itemId = (Integer)provider.getValue("id");
                                        String itemName = (String)provider.getValue("name");
                 
                                provider.setRowSelected((i / 2 == 1)); // select every other row
                                }
                 };
                         
                 Collection selectedIds = provider.getRowSelectedIds(); // get all selected rows "id" properties
                 
                 for (java.util.Iterator it = selectedIds.iterator(); it.hasNext(); ) {
                         provider.setRowById(it.next().toString()); // set row by its id
                         provider.getValue("name"); // returns item's name
                 }

       Collection selectedRows = provider.getSelectedRows(); // returns all selected rows as collection of Item's
       for (Object row: selectedRows) {
        Item item = (Item)row;
        item.getName();
       }
 

This implementation is optimized for addressing rows by id.

See Also:
Serialized Form

Nested Class Summary
protected static class SelectableListTableContentProvider.Row
          Addressable row wrapper.
protected static class SelectableListTableContentProvider.RowComparator
          Compares two rows using column sorting info.
 
Field Summary
protected static int m_autoIdCounter
           
protected  Map m_map
          Map of String row ids to SelectableListTableContentProvider.Row instances.
protected  List m_originalList
          m_list contains SelectableListTableContentProvider.Row instances; m_originalList contains original objects.
protected  SelectableTableContentProviderHelper m_selectableHelper
          Holds selection state.
 
Fields inherited from class com.webmethods.caf.faces.data.object.ListTableContentProvider
m_array, m_canTemplateRow, m_index, m_list, m_onCreateRow, m_onDeleteRow, m_rowId, m_rowType, m_sort, m_templateRow, m_var
 
Fields inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
fExpireWithPageFlow
 
Constructor Summary
SelectableListTableContentProvider()
          Default constructor.
SelectableListTableContentProvider(List list)
          Constructor.
SelectableListTableContentProvider(List list, String rowIdBinding)
          Constructor.
SelectableListTableContentProvider(List list, String rowIdBinding, String rowVariable)
          Fully initialized constructor.
SelectableListTableContentProvider(List list, ValueBinding rowIdBinding)
          Default constructor.
SelectableListTableContentProvider(Object[] array)
          Constructor.
SelectableListTableContentProvider(Object[] array, String rowIdBinding)
          Constructor.
SelectableListTableContentProvider(Object[] array, String rowIdBinding, String rowVariable)
          Fully initialized constructor.
SelectableListTableContentProvider(Object[] array, ValueBinding rowIdBinding)
          Default constructor.
 
Method Summary
 void createRow()
          Creates new row and adds it to the list.
 void deleteRow()
          Deletes current row from the list.
 Object getCurrentRow()
          Returns current row.
 List getList()
          Returns wrapped list object
 boolean getNeedRefresh()
          Returns true when IRefreshable.isAutoRefresh() is on and the result properties need to be refreshed from the data source by executing IRefreshable.refresh() method.
 String getRowId()
          Returns unique identifier for the current row.
 int getRowSelectedCount()
          Returns number of selected rows.
 Collection getRowSelectedIds()
          Returns collection of String ids of the selected rows.
 Collection getRowUnselectedIds()
          Returns collection of String ids of the un-selected rows (all other rows are selected implicitly) May be empty or contain non-existent ids; never null, never contains null.
 List getSelectedRows()
          Returns collection of selected row objects (not IDs) from the ISelectableTableContentProvider.
 boolean getUseUnselectedModel()
          Returns true if it's more effecient to use unselected model (ie ISelectableTableContentProvider.getRowUnselectedIds() rather than ISelectableTableContentProvider.getRowSelectedIds()).
 boolean isAddressable()
          Checks if this content provider truly is addressable.
 boolean isAutoRefresh()
          Returns false
 boolean isRowSelected()
          Returns true if current row is selected.
 void moveTo(int index)
          Moves the current row to the specified index.
 void refresh()
          Should be called by the clients when the wrapped list objects gets changed outside this provider.
 void setAutoRefresh(boolean autorefresh)
          Sets auto refresh mode on.
 void setCurrentRow(Object data)
          Sets new current row object
 void setList(List list)
          Sets a list to wrap
 void setNeedRefresh(boolean needRefresh)
          Tells the provider that the input parameters have changed and the output results need to be refreshed the next time any output property is requested via IContentProvider.getValue(Object).
 void setRowById(String id)
          Selects current row by its id.
 void setRowSelected(boolean selected)
          Sets the selection status for the current row.
 void setRowSelectedIds(Collection ids)
          Sets new selection using a collection of String ids of the rows to select.
 void setRowUnselectedIds(Collection ids)
          Unselects rows using a collection of String ids of the un-selected rows (all other rows are selected implicitly).
 void setRowVariable(String var)
          Sets new row variable and resets the list
 void setTemplateRow()
          Sets provider to state where it returns properties for template pseudo-row.
protected  void sort()
          (Re-)sorts list according to sort info.
 boolean supportsAutoRefresh()
          Returns false
protected  void updateOriginalList()
          Copies changes from the current list to the original list.
 
Methods inherited from class com.webmethods.caf.faces.data.object.ListTableContentProvider
calculateRowId, calculateRowId, getArray, getCanTemplateRow, getOnCreateRow, getOnDeleteRow, getPropertyKeys, getRowCount, getRowIdBinding, getRowIndex, getRowType, getRowVariable, getSort, getType, getValue, hasProperty, isReadOnly, isReorderable, isRowAvailable, isTemplateRow, newRow, setArray, setCanTemplateRow, setOnCreateRow, setOnDeleteRow, setRowId, setRowIdBinding, setRowIndex, setRowType, setSort, setValue, toString
 
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, toString, wait, wait, wait
 
Methods inherited from interface com.webmethods.caf.faces.data.ITableContentProvider
getRowCount, getRowIndex, getRowVariable, isRowAvailable, setRowIndex
 
Methods inherited from interface com.webmethods.caf.faces.data.IContentProvider
getPropertyKeys, getType, getValue, hasProperty, toString
 

Field Detail

m_originalList

protected List m_originalList
m_list contains SelectableListTableContentProvider.Row instances; m_originalList contains original objects.


m_map

protected Map m_map
Map of String row ids to SelectableListTableContentProvider.Row instances.


m_selectableHelper

protected SelectableTableContentProviderHelper m_selectableHelper
Holds selection state.


m_autoIdCounter

protected static int m_autoIdCounter
Constructor Detail

SelectableListTableContentProvider

public SelectableListTableContentProvider()
Default constructor. Requires SelectableListTableContentProvider.setList(List) or ListTableContentProvider.setArray(Object[]), ListTableContentProvider.setRowIdBinding(ValueBinding) and SelectableListTableContentProvider.setRowVariable(String) to be set before use.


SelectableListTableContentProvider

public SelectableListTableContentProvider(List list)
Constructor. Requires ListTableContentProvider.setRowIdBinding(ValueBinding) and SelectableListTableContentProvider.setRowVariable(String) to be set before use.

Parameters:
list - a list to wrap

SelectableListTableContentProvider

public SelectableListTableContentProvider(List list,
                                          String rowIdBinding)
Constructor. Requires Requires SelectableListTableContentProvider.setRowVariable(String) to be set before use.

Parameters:
list - a list to wrap
rowIdBinding - row id binding expression

SelectableListTableContentProvider

public SelectableListTableContentProvider(List list,
                                          String rowIdBinding,
                                          String rowVariable)
Fully initialized constructor.

Parameters:
list - a list to wrap
rowIdBinding - row id binding expression
rowVariable - row variable to use in the expression for accessing list elements data

SelectableListTableContentProvider

public SelectableListTableContentProvider(List list,
                                          ValueBinding rowIdBinding)
Default constructor. Requires SelectableListTableContentProvider.setList(List) or ListTableContentProvider.setArray(Object[]), ListTableContentProvider.setRowIdBinding(ValueBinding) and SelectableListTableContentProvider.setRowVariable(String) to be set before use.


SelectableListTableContentProvider

public SelectableListTableContentProvider(Object[] array)
Constructor. Requires ListTableContentProvider.setRowIdBinding(ValueBinding) and SelectableListTableContentProvider.setRowVariable(String) to be set before use.

Parameters:
array - an array to wrap

SelectableListTableContentProvider

public SelectableListTableContentProvider(Object[] array,
                                          String rowIdBinding)
Constructor. Requires Requires SelectableListTableContentProvider.setRowVariable(String) to be set before use.

Parameters:
array - an array to wrap
rowIdBinding - row id binding expression

SelectableListTableContentProvider

public SelectableListTableContentProvider(Object[] array,
                                          String rowIdBinding,
                                          String rowVariable)
Fully initialized constructor.

Parameters:
array - an array to wrap
rowIdBinding - row id binding expression
rowVariable - row variable to use in the expression for accessing list elements data

SelectableListTableContentProvider

public SelectableListTableContentProvider(Object[] array,
                                          ValueBinding rowIdBinding)
Default constructor. Requires SelectableListTableContentProvider.setList(List) or ListTableContentProvider.setArray(Object[]), ListTableContentProvider.setRowIdBinding(ValueBinding) and SelectableListTableContentProvider.setRowVariable(String) to be set before use.

Method Detail

refresh

public void refresh()
Should be called by the clients when the wrapped list objects gets changed outside this provider.

Specified by:
refresh in interface IRefreshable

supportsAutoRefresh

public boolean supportsAutoRefresh()
Returns false

Specified by:
supportsAutoRefresh in interface IRefreshable
Returns:
true when auto refresh is supported
See Also:
IRefreshable.setAutoRefresh(boolean)

setAutoRefresh

public void setAutoRefresh(boolean autorefresh)
                    throws ContentProviderException
Description copied from interface: IRefreshable

Sets auto refresh mode on. When auto refresh mode is on, the provider calls IRefreshable.getNeedRefresh() to determine whether the refresh needs to be done before returning any result properties. If it returns true, the provider calls IRefreshable.refresh() method to updated the result properties.

Specified by:
setAutoRefresh in interface IRefreshable
Parameters:
autorefresh - true to turn it on
Throws:
ContentProviderException - if autorefresh is true
See Also:
IRefreshable.supportsAutoRefresh(), IRefreshable.getNeedRefresh(), IRefreshable.setNeedRefresh(boolean)

isAutoRefresh

public boolean isAutoRefresh()
Returns false

Specified by:
isAutoRefresh in interface IRefreshable
Returns:
false if auto-refresh mode is off or not supported

getNeedRefresh

public boolean getNeedRefresh()
Description copied from interface: IRefreshable

Returns true when IRefreshable.isAutoRefresh() is on and the result properties need to be refreshed from the data source by executing IRefreshable.refresh() method.

Implementations may return an accurate value from this method if they can track the changes to the input parameter properties or they may require the clients to call IRefreshable.setNeedRefresh(boolean) explicitely.

Specified by:
getNeedRefresh in interface IRefreshable
Returns:
true when the output properties are not up-to-date with the current input parameters, i.e. IRefreshable.refresh() needs to be executed manually or automatically.

setNeedRefresh

public void setNeedRefresh(boolean needRefresh)
Description copied from interface: IRefreshable
Tells the provider that the input parameters have changed and the output results need to be refreshed the next time any output property is requested via IContentProvider.getValue(Object).

Specified by:
setNeedRefresh in interface IRefreshable
Parameters:
needRefresh - true if the input parameters have changed

setRowVariable

public void setRowVariable(String var)
Sets new row variable and resets the list

Specified by:
setRowVariable in interface ITableContentProvider
Overrides:
setRowVariable in class ListTableContentProvider
Parameters:
var - row variable name

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
Overrides:
setTemplateRow in class ListTableContentProvider

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, calculates it id and inserts it before the current row, or at the end of the list if no current row.

Specified by:
createRow in interface IUpdateableTableContentProvider
Overrides:
createRow in class ListTableContentProvider

deleteRow

public void deleteRow()
Description copied from class: ListTableContentProvider
Deletes current row from the list.

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

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
Overrides:
moveTo in class ListTableContentProvider
Parameters:
index - (Zero-based) new row index.

isAddressable

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

Specified by:
isAddressable in interface IAddressableTableContentProvider
Overrides:
isAddressable in class ListTableContentProvider
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
Overrides:
getRowId in class ListTableContentProvider
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
Overrides:
setRowById in class ListTableContentProvider
Parameters:
id - row id to find and make current

isRowSelected

public boolean isRowSelected()
Description copied from interface: ISelectableTableContentProvider
Returns true if current row is selected.

Specified by:
isRowSelected in interface ISelectableTableContentProvider
Returns:
true if current row is selection

setRowSelected

public void setRowSelected(boolean selected)
Description copied from interface: ISelectableTableContentProvider
Sets the selection status for the current row.

Specified by:
setRowSelected in interface ISelectableTableContentProvider
Parameters:
selected - true to select current row; false to unselect.

getRowSelectedCount

public int getRowSelectedCount()
Description copied from interface: ISelectableTableContentProvider
Returns number of selected rows.

Specified by:
getRowSelectedCount in interface ISelectableTableContentProvider
Returns:
number of currently selection rows

getRowSelectedIds

public Collection getRowSelectedIds()
Description copied from interface: ISelectableTableContentProvider
Returns collection of String ids of the selected rows. May be empty or contain non-existent ids; never null, never contains null.

Specified by:
getRowSelectedIds in interface ISelectableTableContentProvider
Returns:
collection of ids of selected rows

setRowSelectedIds

public void setRowSelectedIds(Collection ids)
Description copied from interface: ISelectableTableContentProvider
Sets new selection using a collection of String ids of the rows to select. May be empty or contain non-existent ids; never null, never contains null.

Specified by:
setRowSelectedIds in interface ISelectableTableContentProvider
Parameters:
ids - the collection of String row ids

getUseUnselectedModel

public boolean getUseUnselectedModel()
Description copied from interface: ISelectableTableContentProvider
Returns true if it's more effecient to use unselected model (ie ISelectableTableContentProvider.getRowUnselectedIds() rather than ISelectableTableContentProvider.getRowSelectedIds()).

Specified by:
getUseUnselectedModel in interface ISelectableTableContentProvider
Returns:
true if it's more effecient to use unselected model

getRowUnselectedIds

public Collection getRowUnselectedIds()
Description copied from interface: ISelectableTableContentProvider
Returns collection of String ids of the un-selected rows (all other rows are selected implicitly) May be empty or contain non-existent ids; never null, never contains null.

Specified by:
getRowUnselectedIds in interface ISelectableTableContentProvider
Returns:
collection of ids of the un-selection rows

setRowUnselectedIds

public void setRowUnselectedIds(Collection ids)
Description copied from interface: ISelectableTableContentProvider
Unselects rows using a collection of String ids of the un-selected rows (all other rows are selected implicitly). May be empty or contain non-existent ids; never null, never contains null.

Specified by:
setRowUnselectedIds in interface ISelectableTableContentProvider
Parameters:
ids - collection of String row ids

getSelectedRows

public List getSelectedRows()
Returns collection of selected row objects (not IDs) from the ISelectableTableContentProvider.

Parameters:
provider - selectable table provider
Returns:
collection if selected row objects, never null, can be empty, can be up to ITableContentProvider.getRowCount() size

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
Overrides:
getCurrentRow in class ListTableContentProvider
Returns:
row object or null
See Also:
ITableContentProvider.isRowAvailable()

setCurrentRow

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

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

sort

protected void sort()
Description copied from class: ListTableContentProvider
(Re-)sorts list according to sort info.

Overrides:
sort in class ListTableContentProvider
See Also:
ListTableContentProvider.setSort(ISortInfo)

updateOriginalList

protected void updateOriginalList()
Copies changes from the current list to the original list.


getList

public List getList()
Returns wrapped list object

Overrides:
getList in class ListTableContentProvider
Returns:
null if not set

setList

public void setList(List list)
Sets a list to wrap

Overrides:
setList in class ListTableContentProvider
Parameters:
list - a list