SPT Core API

com.sptci.echo.list
Class ListModel<D extends Serializable>

java.lang.Object
  extended by nextapp.echo.app.list.AbstractListModel
      extended by com.sptci.echo.list.ListModel<D>
Type Parameters:
D - The class name of the model object backing this list model.
All Implemented Interfaces:
Serializable, ListModel
Direct Known Subclasses:
JDOListModel

public class ListModel<D extends Serializable>
extends AbstractListModel

A ListModel used to display a collection of model objects in list components.

The following shows sample use of this model:

  import com.sptci.echo.list.ListModel;
  import com.sptci.echo.list.SelectField;

    ...
    final Collection<Data> data = new ArrayList<Data>();
    // populate data collection with Data instances and Data has a field
    // named name.
    final ListModel<Data> model = new ListModel<Data>( data, "name" );
    final SelectField<ListModel<Data>> select = new SelectField<ListModel<Data>>();
    select.setModel( model );
 

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: ListModel.java 4722 2009-02-28 14:29:55Z rakesh $
Author:
Rakesh Vidyadharan 2008-04-15
See Also:
Serialized Form

Field Summary
protected  List<D> data
          A list used to represent the data held in this model
protected  String field
          The name of the field in the backing model object whose value is to to be displayed in the list.
protected  Map<String,Integer> nameMap
          A map used to quickly fetch index of value object by name.
 
Constructor Summary
protected ListModel()
          Default constructor.
  ListModel(Collection<D> data, String field)
          Create a new model with the specified collection of data backing this model.
 
Method Summary
 void add(D model)
          Add the specified value object to the list model.
 void addAll(Collection<D> data)
          Add the specified collection of objects to the model.
 Object get(int index)
          Returns the value at the specified index in the list.
 List<D> getData()
          Return a read-only view of the data in data.
 D getObject(int index)
          Returns the object at the specified index in the list.
protected  String getValue(D model)
          Return the value from the model object that is to be displayed in the list.
protected  String getValue(int index)
          Return the value from the model object that is to be displayed at the specified index in the list.
 int indexByName(String name)
          Return the index of the specified name.
 void remove(D model)
          Remove the specified model object from the list model.
 void setData(List<D> data)
          Set the data in data.
 int size()
          Return the size of the model.
 
Methods inherited from class nextapp.echo.app.list.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getEventListenerList, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected List<D extends Serializable> data
A list used to represent the data held in this model


nameMap

protected Map<String,Integer> nameMap
A map used to quickly fetch index of value object by name.


field

protected String field
The name of the field in the backing model object whose value is to to be displayed in the list.

Constructor Detail

ListModel

protected ListModel()
Default constructor.


ListModel

public ListModel(Collection<D> data,
                 String field)
Create a new model with the specified collection of data backing this model.

Parameters:
data - The collection of objects to represent.
field - The field in the model object whose value is to be displayed in the list component.
Method Detail

getValue

protected String getValue(int index)
Return the value from the model object that is to be displayed at the specified index in the list.

Parameters:
index - The index for which the value is to be fetched.
Returns:
The value to be displayed.
See Also:
getValue(java.io.Serializable)

getValue

protected String getValue(D model)
Return the value from the model object that is to be displayed in the list.

Parameters:
model - The model object from which the display value is to be retrieved.
Returns:
The value to be displayed.

get

public Object get(int index)
Returns the value at the specified index in the list.

Parameters:
index - The index in data from which the value is to be retrieved.
Returns:
The value at specified index that is to be displayed.
See Also:
getValue(int)

getObject

public D getObject(int index)
Returns the object at the specified index in the list.

Parameters:
index - The index in data from which the objec5 is to be retrieved.
Returns:
The model object at the specified index.

size

public int size()
Return the size of the model.

Returns:
The size of data.

indexByName

public int indexByName(String name)
Return the index of the specified name.

Parameters:
name - The name (value) displayed in the list component.
Returns:
The index in data at which the corresponding model object exists.

addAll

public void addAll(Collection<D> data)
Add the specified collection of objects to the model.

Parameters:
data - The collection of objects to add to data.

add

public void add(D model)
Add the specified value object to the list model. Adds the model object to data and nameMap.

Parameters:
model - The model object that is to be added to this list model.

remove

public void remove(D model)
Remove the specified model object from the list model. Updates nameMap accordingly.

Parameters:
model - The object to be removed.

getData

public List<D> getData()
Return a read-only view of the data in data.

Returns:
A list of the data underlying this model.

setData

public void setData(List<D> data)
Set the data in data. Updates the associated maps.

Parameters:
data - The new collection of model objects to display.
See Also:
addAll(java.util.Collection)

SPT Core API