com.sun.data.provider.impl
Class ListDataProvider

java.lang.Object
  extended bycom.sun.data.provider.impl.AbstractDataProvider
      extended bycom.sun.data.provider.impl.AbstractTableDataProvider
          extended bycom.sun.data.provider.impl.ListDataProvider
All Implemented Interfaces:
DataProvider, java.io.Serializable, TableDataProvider

public class ListDataProvider
extends AbstractTableDataProvider

This TableDataProvider implementation wraps the contents of a List. This DataProvider ignores FieldKeys entirely, and maintains a single list of objects.

NOTE about Serializable: By default, this class uses an ArrayList as its internal data storage, which is a Serializable implementation of List. The internal storage can be swapped out using the setList(List) method. For this class to remain Serializable, the contained List must be a Serializable implementation. Also, and more importantly, the contents of the storage List must be Serializable as well for this class to successfully be serialized.

Author:
Joe Nuxoll
See Also:
Serialized Form

Field Summary
protected  java.util.List list
          Storage for the internal List (ArrayList by default)
 
Fields inherited from class com.sun.data.provider.impl.AbstractTableDataProvider
cursorRow, rowKeyList, rowKeyMap, tcListeners
 
Fields inherited from class com.sun.data.provider.impl.AbstractDataProvider
dpListeners, fieldKeys
 
Constructor Summary
ListDataProvider()
          Constructs a new ListDataProvider using the default internal storage
ListDataProvider(java.util.List list)
          Constructs a new ListDataProvider using the specified List as internal storage.
 
Method Summary
 RowKey appendRow()
          

Appends a new row at the end of the list and returns the row key for the newly appended row.

NOTE: The method should only be called after testing the canAppendRow() method to see if this TableDataProvider supports the append operation.

 boolean canAppendRow()
          NOTE: This implementation always returns false from this method.
 boolean canInsertRow(RowKey beforeRow)
          NOTE: This implementation always returns false from this method.
 boolean canRemoveRow(RowKey row)
          NOTE: This implementation always returns true from this method.
 int getCursorIndex()
           
 java.util.List getList()
           
 int getRowCount()
          
 int getRowIndex(RowKey row)
           
 java.lang.Class getType(FieldKey fieldKey)
          NOTE: FieldKey is ignored in this class.
 java.lang.Object getValue(FieldKey fieldKey, RowKey row)
          NOTE: FieldKey is ignored in this class.
 RowKey insertRow(RowKey beforeRow)
          

Inserts a new row at the specified row.

NOTE: The method should only be called after testing the canInsertRow(RowKey beforeRow) to see if this TableDataProvider supports resizing.

 boolean isReadOnly(FieldKey fieldKey)
          NOTE: FieldKey is ignored in this class.
 boolean isRowAvailable(RowKey row)
          Returns true if the specified RowKey represents data elements that are supported by this TableDataProvider; otherwise, return false
 void removeRow(RowKey row)
          

Removes the specified row.

NOTE: The method should only be called after testing the canRemoveRow(RowKey) method to see if this TableDataProvider supports removing rows.

 void setList(java.util.List list)
          Sets the List to use for internal storage.
 void setValue(FieldKey fieldKey, RowKey row, java.lang.Object value)
          NOTE: FieldKey is ignored in this class.
 
Methods inherited from class com.sun.data.provider.impl.AbstractTableDataProvider
addTableCursorListener, addTableDataListener, cursorFirst, cursorLast, cursorNext, cursorPrevious, findAll, findAll, findAll, findAll, findFirst, findFirst, findFirst, findFirst, fireCursorChanged, fireCursorChanging, fireRowAdded, fireRowRemoved, fireValueChanged, getAllRows, getCursorRow, getRowKey, getRowKeys, getTableCursorListeners, getTableDataListeners, getValue, getValue, removeTableCursorListener, removeTableDataListener, setCursorIndex, setCursorRow, setValue, setValue
 
Methods inherited from class com.sun.data.provider.impl.AbstractDataProvider
addDataListener, addFieldKey, addFieldKeys, clearFieldKeys, fireProviderChanged, fireValueChanged, getDataListeners, getFakeData, getFakeData, getFieldKey, getFieldKeys, getType, getValue, isReadOnly, removeDataListener, removeFieldKey, removeFieldKeys, setValue, sortFieldKeys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.data.provider.DataProvider
addDataListener, getDataListeners, getFieldKey, getFieldKeys, removeDataListener
 

Field Detail

list

protected java.util.List list
Storage for the internal List (ArrayList by default)

Constructor Detail

ListDataProvider

public ListDataProvider()
Constructs a new ListDataProvider using the default internal storage


ListDataProvider

public ListDataProvider(java.util.List list)

Constructs a new ListDataProvider using the specified List as internal storage.

NOTE about Serializable: By default, this class uses an ArrayList as its internal data storage, which is a Serializable implementation of List. The internal storage can be swapped out using the setList(List) method. For this class to remain Serializable, the contained List must be a Serializable implementation. Also, and more importantly, the contents of the storage List must be Serializable as well for this class to successfully be serialized.

Parameters:
list - List to use for internal storage
Method Detail

getList

public java.util.List getList()
Returns:
List used for internal storage

setList

public void setList(java.util.List list)

Sets the List to use for internal storage.

NOTE about Serializable: By default, this class uses an ArrayList as its internal data storage, which is a Serializable implementation of List. The internal storage can be swapped out using the setList(List) method. For this class to remain Serializable, the contained List must be a Serializable implementation. Also, and more importantly, the contents of the storage List must be Serializable as well for this class to successfully be serialized.

Parameters:
list - List to use for internal storage

getValue

public java.lang.Object getValue(FieldKey fieldKey,
                                 RowKey row)
                          throws DataProviderException

NOTE: FieldKey is ignored in this class.

Return value of the data element referenced by the specified FieldKey and RowKey.

Specified by:
getValue in interface TableDataProvider
Specified by:
getValue in class AbstractTableDataProvider
Throws:
DataProviderException

getType

public java.lang.Class getType(FieldKey fieldKey)
                        throws DataProviderException

NOTE: FieldKey is ignored in this class.

Returns the data type of the data element referenced by the specified data key.

Specified by:
getType in interface DataProvider
Specified by:
getType in class AbstractTableDataProvider
Throws:
DataProviderException

isReadOnly

public boolean isReadOnly(FieldKey fieldKey)
                   throws DataProviderException

NOTE: FieldKey is ignored in this class.

NOTE: This method always returns false, as the storage List can be edited at any row.

Return a flag indicating whether the value of the data element represented by the specified FieldKey can be modified via the setValue() method.

Specified by:
isReadOnly in interface DataProvider
Specified by:
isReadOnly in class AbstractTableDataProvider
Throws:
DataProviderException

setValue

public void setValue(FieldKey fieldKey,
                     RowKey row,
                     java.lang.Object value)
              throws DataProviderException

NOTE: FieldKey is ignored in this class.

Sets the value of the data element represented by the specified FieldKey and RowKey to the specified new value.

Specified by:
setValue in interface TableDataProvider
Specified by:
setValue in class AbstractTableDataProvider
Throws:
DataProviderException

getRowCount

public int getRowCount()
                throws DataProviderException

Specified by:
getRowCount in interface TableDataProvider
Specified by:
getRowCount in class AbstractTableDataProvider
Throws:
DataProviderException

isRowAvailable

public boolean isRowAvailable(RowKey row)
                       throws DataProviderException
Returns true if the specified RowKey represents data elements that are supported by this TableDataProvider; otherwise, return false

Specified by:
isRowAvailable in interface TableDataProvider
Overrides:
isRowAvailable in class AbstractTableDataProvider
Throws:
DataProviderException

getCursorIndex

public int getCursorIndex()
                   throws DataProviderException
Overrides:
getCursorIndex in class AbstractTableDataProvider
Throws:
DataProviderException

getRowIndex

public int getRowIndex(RowKey row)
                throws DataProviderException
Throws:
DataProviderException

canInsertRow

public boolean canInsertRow(RowKey beforeRow)
                     throws DataProviderException

NOTE: This implementation always returns false from this method. To resize the data provider, access the List directly.

This method is called to test if this TableDataProvider supports resizability. If objects can be inserted and removed from the list, this method should return true. If the data provider is not resizable, this method should return false.

The following methods will only be called if this method returns true:

Specified by:
canInsertRow in interface TableDataProvider
Specified by:
canInsertRow in class AbstractTableDataProvider
Throws:
DataProviderException

insertRow

public RowKey insertRow(RowKey beforeRow)
                 throws DataProviderException

Inserts a new row at the specified row.

NOTE: The method should only be called after testing the canInsertRow(RowKey beforeRow) to see if this TableDataProvider supports resizing.

Specified by:
insertRow in interface TableDataProvider
Specified by:
insertRow in class AbstractTableDataProvider
Throws:
DataProviderException

canAppendRow

public boolean canAppendRow()
                     throws DataProviderException

NOTE: This implementation always returns false from this method. To resize the data provider, access the List directly.

This method is called to test if this TableDataProvider supports the append operation. If rows can be appended to the list, this method should return true. If the data provider is not resizable, or cannot support an append operation, this method should return false.

Specified by:
canAppendRow in interface TableDataProvider
Specified by:
canAppendRow in class AbstractTableDataProvider
Throws:
DataProviderException

appendRow

public RowKey appendRow()
                 throws DataProviderException

Appends a new row at the end of the list and returns the row key for the newly appended row.

NOTE: The method should only be called after testing the canAppendRow() method to see if this TableDataProvider supports the append operation.

Specified by:
appendRow in interface TableDataProvider
Specified by:
appendRow in class AbstractTableDataProvider
Throws:
DataProviderException

canRemoveRow

public boolean canRemoveRow(RowKey row)
                     throws DataProviderException

NOTE: This implementation always returns true from this method.

This method is called to test if this TableDataProvider supports the removeRow operation. If rows can be removed from the table, this method should return true. If the data provider is does not support removing rows, this method should return false.

Specified by:
canRemoveRow in interface TableDataProvider
Specified by:
canRemoveRow in class AbstractTableDataProvider
Throws:
DataProviderException

removeRow

public void removeRow(RowKey row)
               throws DataProviderException

Removes the specified row.

NOTE: The method should only be called after testing the canRemoveRow(RowKey) method to see if this TableDataProvider supports removing rows.

Specified by:
removeRow in interface TableDataProvider
Specified by:
removeRow in class AbstractTableDataProvider
Throws:
DataProviderException