public class ItemList extends Object implements Copyable<ItemList>
ItemList
is the backend for some ListModel
s in XDEV.
The ItemList
consists of entries (ItemList.Entry
) which provide two
stores: item
and data
. The item
is
used to display the list entry in a GUI component. The data
object is not displayed and used as a hidden store for data like ids
or references.
XdevListBox
,
XdevComboBox
,
XdevListBox.setItemList(ItemList)
,
XdevComboBox.setItemList(ItemList)
Modifier and Type | Class and Description |
---|---|
static class |
ItemList.Entry
An entry in an
ItemList holding
a data object
a display item
an icon
settings: enabled
and client properties
|
Constructor and Description |
---|
ItemList()
Creates a new empty
ItemList . |
ItemList(Collection<?> item,
Collection<?> data)
|
ItemList(Collection<? extends ItemList.Entry> entries) |
ItemList(ListModel model)
|
ItemList(Object[] item,
Object[] data)
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
ItemList.Entry entry)
Adds the entry at the specified
index to this
ItemList . |
void |
add(int index,
String item,
Object data)
Adds a new row / item data pair at the specified
index to
this ItemList . |
void |
add(ItemList.Entry entry)
Adds the
entry to the end of this ItemList . |
void |
add(String item,
Object data)
Adds a new row / item data pair to the end of this
ItemList . |
void |
addAll(Collection<?> item,
Collection<?> data)
|
void |
addAll(Collection<? extends ItemList.Entry> entries)
Adds all
entries to this ItemList . |
void |
addAll(ItemList il)
|
void |
addAll(ListModel model)
Adds all entries of the
model to this ItemList . |
void |
addListDataListener(ListDataListener listener)
Adds a
ListDataListener to this ItemList . |
void |
clear()
Removes all of the elements from this
ItemList . |
ItemList |
clone()
Returns a field-for-field copy of this instance.
|
boolean |
contains(ItemList.Entry entry)
Returns true if this
ItemList contains the specified
entry . |
boolean |
containsData(Object data)
Returns true if this
ItemList contains the specified
data . |
boolean |
containsItem(Object item)
Returns true if this
ItemList contains the specified
item . |
ItemList |
copy()
Creates a (defensive) copy of this
ItemList . |
protected void |
fireContentsChanged(int index0,
int index1) |
protected void |
fireIntervalAdded(int index0,
int index1) |
protected void |
fireIntervalRemoved(int index0,
int index1) |
ItemList.Entry |
get(int index)
Returns the entry at the specified position in this
ItemList . |
Object |
getData(int index)
Returns the data at the specified position in this
ItemList . |
List |
getDataAsList()
|
Object |
getItem(int index)
Returns the item at the specified position in this
ItemList . |
List |
getItemsAsList()
|
VirtualTable |
getVirtualTable()
Returns the
VirtualTable which was associated via
setModel(VirtualTable, String, String) , or null if
no VirtualTable has been associated yet. |
int |
indexOfData(Object data)
Returns the index of the first occurrence of the specified
data in this list, or -1 if this ItemList does not
contain the data . |
int |
indexOfItem(Object item)
Returns the index of the first occurrence of the specified
item in this list, or -1 if this ItemList does not
contain the item . |
void |
refresh()
Reloads the data from the underlying data source with the last executed
resp.
|
ItemList.Entry |
remove(int index)
Removes the element at the specified position in this
ItemList . |
ItemList.Entry[] |
removeAll(int... indices)
Removes the elements at the specified positions in this
ItemList . |
void |
removeListDataListener(ListDataListener listener)
Removes the
ListDataListener from this ItemList . |
void |
setModel(VirtualTable vt,
String itemCol,
String dataCol)
|
void |
setModel(VirtualTable vt,
String itemCol,
String dataCol,
boolean queryData)
|
void |
setModel(VirtualTable vt,
String itemCol,
String dataCol,
boolean queryData,
boolean selectiveQuery)
|
void |
setModel(VirtualTable vt,
String itemCol,
String dataCol,
SELECT select,
Object... params)
|
void |
setSize(int size)
Sets the size of this
ItemList . |
int |
size()
Returns the size of the list.
|
void |
syncWithVT()
public @since 4.0
|
String |
toString() |
void |
updateModel(Condition condition,
Object... params)
Reloads the data form the underlying data source.
|
public ItemList()
ItemList
.public ItemList(Collection<?> item, Collection<?> data)
public ItemList(Object[] item, Object[] data)
ItemList
based on the provided arrays
item
and data
. Item
and
data
must be non null and have an equal size. The first
object in item
is mapped to first object in
data
... and so on.item
- array to use as itemsdata
- array to use as datapublic ItemList(ListModel model)
ItemList
based on the provided ListModel
.
The data are the model's values and the item's are the model's values as
String
.model
- The data modelpublic ItemList(Collection<? extends ItemList.Entry> entries)
public void addListDataListener(ListDataListener listener)
ListDataListener
to this ItemList
.listener
- the ListDataListener
to addpublic void removeListDataListener(ListDataListener listener)
ListDataListener
from this ItemList
.listener
- the ListDataListener
to removeprotected void fireContentsChanged(int index0, int index1)
protected void fireIntervalAdded(int index0, int index1)
protected void fireIntervalRemoved(int index0, int index1)
public ItemList copy()
ItemList
.ItemList
.public ItemList clone()
public void add(String item, Object data)
ItemList
.item
- to adddata
- to addpublic void add(int index, String item, Object data)
index
to
this ItemList
.index
- index at which the specified element is to be inserteditem
- the display item to adddata
- the data object to addpublic void add(ItemList.Entry entry)
entry
to the end of this ItemList
.entry
- the entry to addpublic void add(int index, ItemList.Entry entry)
index
to this
ItemList
.index
- index at which the specified element is to be insertedentry
- the entry to addpublic void addAll(Collection<?> item, Collection<?> data)
item
- Collection
of items to adddata
- Collection
of data to addpublic void addAll(Collection<? extends ItemList.Entry> entries)
entries
to this ItemList
.entries
- the entries to addpublic void addAll(ListModel model)
model
to this ItemList
.model
- the data modelpublic ItemList.Entry remove(int index) throws IndexOutOfBoundsException
ItemList
.
Shifts any subsequent elements to the top (subtracts one from their
indices). Returns the element that was removed from the list.index
- the index of the element to be removedIndexOutOfBoundsException
- if the index is out of range (
index < 0 || index >= size())public ItemList.Entry[] removeAll(int... indices) throws IndexOutOfBoundsException
ItemList
.
Shifts any subsequent elements to the top (subtracts one from their
indices). Returns the elements that were removed from the list.indices
- the indices of the elements to be removedIndexOutOfBoundsException
- if an index is out of range (
index < 0 || index >= size())public ItemList.Entry get(int index) throws IndexOutOfBoundsException
ItemList
.index
- index of the entry to returnIndexOutOfBoundsException
- if the index is out of range (
index < 0 || index >= size())public Object getItem(int index) throws IndexOutOfBoundsException
ItemList
.index
- index of the item to returnIndexOutOfBoundsException
- if the index is out of range (
index < 0 || index >= size())public Object getData(int index) throws IndexOutOfBoundsException
ItemList
.index
- index of the data to returnIndexOutOfBoundsException
- if the index is out of range (
index < 0 || index >= size())public int size()
public void clear()
public void syncWithVT()
public void setModel(VirtualTable vt, String itemCol, String dataCol)
vt
- VirtualTable
to read the rows from.itemCol
- columnname to fill item
from or string with
variables like "{%SURNAME} {%NAME} - {%AGE}"
dataCol
- column name to fill data
from, or multiple
columns names, comma-separatedpublic void setModel(VirtualTable vt, String itemCol, String dataCol, boolean queryData)
vt
- VirtualTable
to read the rows from.itemCol
- columnname to fill item
from or string with
variables like "{%SURNAME} {%NAME} - {%AGE}"
dataCol
- column name to fill data
from, or multiple
columns names, comma-separatedqueryData
- if true
, the best fitting select for this vt
is usedpublic void setModel(VirtualTable vt, String itemCol, String dataCol, boolean queryData, boolean selectiveQuery)
vt
- VirtualTable
to read the rows from.itemCol
- columnname to fill item
from or string with
variables like "{%SURNAME} {%NAME} - {%AGE}"
dataCol
- column name to fill data
from, or multiple
columns names, comma-separatedqueryData
- if true
, the best fitting select for this vt
is usedselectiveQuery
- if true
, only the used columns
are
queriedpublic void setModel(VirtualTable vt, String itemCol, String dataCol, SELECT select, Object... params)
vt
- VirtualTable
to read the rows from.itemCol
- columnname to fill item
from or string with
variables like "{%SURNAME} {%NAME} - {%AGE}"
dataCol
- column name to fill data
from, or multiple
columns names, comma-separatedselect
- a custom SELECT
for filtering or ordering the results
of the vt
, may be null for the default selectparams
- a set of parameters related to the param select
, may
be nullpublic void refresh()
public void updateModel(Condition condition, Object... params)
The last executed query is extended with condition
.
condition
- The additional filter for the queryparams
- param objects used in condition
public VirtualTable getVirtualTable()
VirtualTable
which was associated via
setModel(VirtualTable, String, String)
, or null
if
no VirtualTable
has been associated yet.VirtualTable
which was associated via
setModel(VirtualTable, String, String)
, or
null
public boolean containsItem(Object item)
ItemList
contains the specified
item
. More formally, returns true if and only if
this list contains at least one element e such that
(o==null ? e==null : o.equals(e)).item
- item
whose presence in this list is to be testedpublic boolean contains(ItemList.Entry entry)
ItemList
contains the specified
entry
. More formally, returns true if and only if
this list contains at least one element e such that
(o==null ? e==null : o.equals(e)).entry
- item
whose presence in this list is to be testedpublic int indexOfItem(Object item)
item
in this list, or -1 if this ItemList
does not
contain the item
. More formally, returns the lowest index
i such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.item
- item
to search foritem
in this list, or -1 if this list does not
contain the item
public boolean containsData(Object data)
ItemList
contains the specified
data
. More formally, returns true if and only if
this list contains at least one element e such that
(o==null ? e==null : o.equals(e)).data
- data
whose presence in this list is to be testedpublic int indexOfData(Object data)
data
in this list, or -1 if this ItemList
does not
contain the data
. More formally, returns the lowest index
i such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.data
- data
to search foritem
in this list, or -1 if this list does not
contain the data
public void setSize(int size)
ItemList
. If the ItemList
has more
entries that the specified size
, list entries will be
removed beginning with the largest index. If the ItemList
has
less than the specified size
, list entries (item = "", data
= "") will be added at the end of this ItemList
.size
- new size of the ItemList
Copyright © 2003–2020 XDEV Software. All rights reserved.