|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.glaivestone.mv.swing.AbstractListHolder
Abstract superclass for implementations of value holders which manage the data model and the selection model for a list of values. It turns out that it's frequently desirable to have the selection managed appropriately when the list contents change and to have services which access values in the list according to the current selection. This class provides appropriate linkage between the values and the selection, along with convenience protocol to make is easier for clients to invoke standard services.
The holder can be configured for use in either single-select
or multi-select mode. Variations in the protocol are introduced
when necessary to differentiate return value types or when
deemed to improve client code readability. Operations which
are only appropriate for a specific selection mode
will cause IllegalStateException
to be thrown
if used improperly.
Subclass implementations are responsible for providing a suitable data model to hold the list values and implementing value accessing services (addEntry, clearValues, get, getValues, indexOf), removeEntry, size).
Field Summary | |
static int |
DEFAULT_SELECTION_MODE
|
static int |
MULTI_SELECT_MODE
|
static int |
NOT_FOUND_INDEX
The index which is returned when the requested value is not found in the list of data values. |
static int |
SINGLE_SELECT_MODE
|
Method Summary | |
void |
add(java.lang.Object aValue)
Add the specified value to the list. |
void |
addAll(java.util.Collection values)
Add all of the values in the given collection to the list. |
void |
clear()
Clear the contents of the list. |
void |
clearSelection()
Clear the selection. |
abstract boolean |
contains(java.lang.Object aValue)
Answer whether the specified value is contained in the list. |
static javax.swing.ListSelectionModel |
createDefaultSelectionModel()
Create a new instance of the default selection model. |
static javax.swing.ListSelectionModel |
createDefaultSelectionModel(int selectionMode)
Create a new instance of the default selection model configured for single or multiple selection according to the java.swing.ListSelectionModel constant
specified by the selectionMode argument. |
abstract java.lang.Object |
get(int index)
Answer the value at the specified position in the list. |
int |
getSelectedIndex()
Answer the index of the selected value. |
java.lang.Object |
getSelectedValue()
Answer the selected value. |
java.util.List |
getSelectedValues()
Answer the selected values. |
javax.swing.ListSelectionModel |
getSelectionModel()
Answer the selection model. |
int |
getSelectionSize()
Answer the number of values in the current selection. |
java.util.List |
getValues()
Answer a list containing the values in the list. |
boolean |
hasSelection()
Answer whether there is a selection in the list. |
abstract int |
indexOf(java.lang.Object aValue)
Answer the index of the specified value in the list. |
boolean |
isMultiSelect()
Answer whether the holder is configured for multi-select. |
boolean |
isSingleSelect()
Answer whether the holder is configured for single-select. |
void |
remove(int index)
Remove the value at the specified position in the list. |
void |
remove(java.lang.Object aValue)
Remove the specified value from the list. |
void |
selectAll()
Set the selection to include all values in a multi-select list. |
void |
selectIndex(int index)
Select the value at the specified position in the list. |
void |
selectIndex(int index,
boolean addToExistingSelection)
Select the value at the specified position in the list. |
void |
selectIndices(int firstIndex,
int lastIndex)
Select the values at the specified range of positions in a multi-select list. |
void |
selectIndices(int firstIndex,
int lastIndex,
boolean addToExistingSelection)
Select the values at the specified range of positions in a multi-select list. |
void |
selectValue(java.lang.Object aValue)
Select the specified value in the list. |
void |
selectValue(java.lang.Object aValue,
boolean addToExistingSelection)
Select the specified value in the list. |
void |
selectValues(java.util.List valuesToSelect)
Select the specified values in the list. |
void |
selectValues(java.util.List valuesToSelect,
boolean addToExistingSelection)
Select the specified values in the list. |
void |
setMultiSelect()
Configure the receiver for multi-select operation. |
void |
setSingleSelect()
Configure the receiver for single-select operation. |
abstract int |
size()
Answer the number of elements in the list. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NOT_FOUND_INDEX
public static final int SINGLE_SELECT_MODE
public static final int MULTI_SELECT_MODE
public static final int DEFAULT_SELECTION_MODE
Method Detail |
public static javax.swing.ListSelectionModel createDefaultSelectionModel()
public static javax.swing.ListSelectionModel createDefaultSelectionModel(int selectionMode)
java.swing.ListSelectionModel
constant
specified by the selectionMode
argument.
public void add(java.lang.Object aValue)
public void addAll(java.util.Collection values)
public void clear()
public void clearSelection()
public abstract boolean contains(java.lang.Object aValue)
public abstract java.lang.Object get(int index)
java.lang.IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public int getSelectedIndex()
java.lang.IllegalStateException
- Not a single-select list holderpublic java.lang.Object getSelectedValue()
java.lang.IllegalStateException
- Not a single-select list holderpublic java.util.List getSelectedValues()
java.lang.IllegalStateException
- Not a multi-select list holderpublic javax.swing.ListSelectionModel getSelectionModel()
public int getSelectionSize()
Returns [0..1] for a single-select holder. Returns a value in the range [0..n]
for a multiselect list, where n
is the number of values in the list.
public java.util.List getValues()
public boolean hasSelection()
public abstract int indexOf(java.lang.Object aValue)
public boolean isMultiSelect()
public boolean isSingleSelect()
public void remove(java.lang.Object aValue)
public void remove(int index)
public void selectAll()
java.lang.IllegalStateException
- Not a multi-select list holderpublic void selectIndex(int index)
For a multi-select list, this adds to any existing selection(s).
public void selectIndex(int index, boolean addToExistingSelection)
For a multi-select list, the addToExistingSelection
flag
indicates whether to add to the existing selection or make
the specified value to entire selection.
public void selectIndices(int firstIndex, int lastIndex)
This adds to any existing selection(s).
java.lang.IllegalStateException
- Not a multi-select list holderpublic void selectIndices(int firstIndex, int lastIndex, boolean addToExistingSelection)
addToExistingSelection
flag indicates whether to add to
the existing selection or make the specified values be the entire selection.
java.lang.IllegalStateException
- Not a multi-select list holderpublic void selectValue(java.lang.Object aValue)
For a multi-select list, this adds to any existing selection(s).
public void selectValue(java.lang.Object aValue, boolean addToExistingSelection)
For a multi-select list, the addToExistingSelection
flag
indicates whether to add to the existing selection or make
the specified value to entire selection.
public void selectValues(java.util.List valuesToSelect)
This adds to any existing selection(s).
java.lang.IllegalStateException
- Not a multi-select list holderpublic void selectValues(java.util.List valuesToSelect, boolean addToExistingSelection)
addToExistingSelection
flag indicates whether to add to
the existing selection or make the specified values be the entire selection.
java.lang.IllegalStateException
- Not a multi-select list holderpublic void setMultiSelect()
Should usually be invoked only once to configure a newly created holder..
public void setSingleSelect()
Should usually be invoked only once to configure a newly created holder..
public abstract int size()
|
GFL 1.1 API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |