D - The class name of the model object backing this list model.public class ListModel<D> extends AbstractListModel
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.
| Modifier and Type | Field and Description |
|---|---|
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.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ListModel()
Default constructor.
|
|
ListModel(Collection<D> data,
String field)
Create a new model with the specified collection of data backing this
model.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(D model)
Add the specified value object to the list model.
|
void |
addAll(Collection<D> collection)
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> collection)
Set the data in
data. |
int |
size()
Return the size of the model.
|
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getEventListenerList, removeListDataListenerprotected Map<String,Integer> nameMap
protected String field
protected ListModel()
public ListModel(Collection<D> data, String field)
data - The collection of objects to represent.field - The field in the model object whose value is to be
displayed in the list component.protected String getValue(int index)
index - The index for which the value is to be fetched.getValue(int)protected String getValue(D model)
model - The model object from which the display value is to be
retrieved.public Object get(int index)
index - The index in data from which the value is to
be retrieved.getValue(int)public D getObject(int index)
index - The index in data from which the objec5 is to
be retrieved.public int size()
data.public int indexByName(String name)
name - The name (value) displayed in the list component.data at which the corresponding model
object exists.public void addAll(Collection<D> collection)
collection - The collection of objects to add to data.public void add(D model)
model - The model object that is to be added to this list model.public void remove(D model)
nameMap accordingly.model - The object to be removed.public List<D> getData()
data.public void setData(List<D> collection)
data. Updates the associated maps.collection - The new collection of model objects to display.addAll(java.util.Collection<D>)