com.glaivestone.mv.swing
Class AbstractListHolder

java.lang.Object
  |
  +--com.glaivestone.mv.swing.AbstractListHolder
Direct Known Subclasses:
ListHolder, TableHolder

public abstract class AbstractListHolder
extends java.lang.Object

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 Responsibilities

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).

Author:
Deb Lewis

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

NOT_FOUND_INDEX

public static final int NOT_FOUND_INDEX
The index which is returned when the requested value is not found in the list of data values.

See Also:
Constant Field Values

SINGLE_SELECT_MODE

public static final int SINGLE_SELECT_MODE
See Also:
Constant Field Values

MULTI_SELECT_MODE

public static final int MULTI_SELECT_MODE
See Also:
Constant Field Values

DEFAULT_SELECTION_MODE

public static final int DEFAULT_SELECTION_MODE
See Also:
Constant Field Values
Method Detail

createDefaultSelectionModel

public static javax.swing.ListSelectionModel createDefaultSelectionModel()
Create a new instance of the default selection model.


createDefaultSelectionModel

public 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.


add

public void add(java.lang.Object aValue)
Add the specified value to the list. The selection is not affected.


addAll

public void addAll(java.util.Collection values)
Add all of the values in the given collection to the list. The selection is not affected.


clear

public void clear()
Clear the contents of the list.


clearSelection

public void clearSelection()
Clear the selection.


contains

public abstract boolean contains(java.lang.Object aValue)
Answer whether the specified value is contained in the list.


get

public abstract java.lang.Object get(int index)
Answer the value at the specified position in the list.

Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).

getSelectedIndex

public int getSelectedIndex()
Answer the index of the selected value. Returns NOT_FOUND_INDEX if there is no selection.

Throws:
java.lang.IllegalStateException - Not a single-select list holder

getSelectedValue

public java.lang.Object getSelectedValue()
Answer the selected value. Returns null if there is no selection.

Throws:
java.lang.IllegalStateException - Not a single-select list holder

getSelectedValues

public java.util.List getSelectedValues()
Answer the selected values. Returns an empty list if there is no selection.

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

getSelectionModel

public javax.swing.ListSelectionModel getSelectionModel()
Answer the selection model.


getSelectionSize

public int getSelectionSize()
Answer the number of values in the current selection. Returns 0 if there is no selection

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.


getValues

public java.util.List getValues()
Answer a list containing the values in the list.


hasSelection

public boolean hasSelection()
Answer whether there is a selection in the list.


indexOf

public abstract int indexOf(java.lang.Object aValue)
Answer the index of the specified value in the list. Answer NOT_FOUND_INDEX if not found.


isMultiSelect

public boolean isMultiSelect()
Answer whether the holder is configured for multi-select.


isSingleSelect

public boolean isSingleSelect()
Answer whether the holder is configured for single-select.


remove

public void remove(java.lang.Object aValue)
Remove the specified value from the list. Update the selection suitably if the value was selected.


remove

public void remove(int index)
Remove the value at the specified position in the list. Update the selection suitably if the value was selected.


selectAll

public void selectAll()
Set the selection to include all values in a multi-select list.

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

selectIndex

public void selectIndex(int index)
Select the value at the specified position in the list.

For a multi-select list, this adds to any existing selection(s).


selectIndex

public void selectIndex(int index,
                        boolean addToExistingSelection)
Select the value at the specified position in the list.

For a multi-select list, the addToExistingSelection flag indicates whether to add to the existing selection or make the specified value to entire selection.


selectIndices

public void selectIndices(int firstIndex,
                          int lastIndex)
Select the values at the specified range of positions in a multi-select list.

This adds to any existing selection(s).

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

selectIndices

public void selectIndices(int firstIndex,
                          int lastIndex,
                          boolean addToExistingSelection)
Select the values at the specified range of positions in a multi-select list. The addToExistingSelection flag indicates whether to add to the existing selection or make the specified values be the entire selection.

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

selectValue

public void selectValue(java.lang.Object aValue)
Select the specified value in the list.

For a multi-select list, this adds to any existing selection(s).


selectValue

public void selectValue(java.lang.Object aValue,
                        boolean addToExistingSelection)
Select the specified value in the list.

For a multi-select list, the addToExistingSelection flag indicates whether to add to the existing selection or make the specified value to entire selection.


selectValues

public void selectValues(java.util.List valuesToSelect)
Select the specified values in the list.

This adds to any existing selection(s).

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

selectValues

public void selectValues(java.util.List valuesToSelect,
                         boolean addToExistingSelection)
Select the specified values in the list. The addToExistingSelection flag indicates whether to add to the existing selection or make the specified values be the entire selection.

Throws:
java.lang.IllegalStateException - Not a multi-select list holder

setMultiSelect

public void setMultiSelect()
Configure the receiver for multi-select operation.

Should usually be invoked only once to configure a newly created holder..


setSingleSelect

public void setSingleSelect()
Configure the receiver for single-select operation.

Should usually be invoked only once to configure a newly created holder..


size

public abstract int size()
Answer the number of elements in the list.


GFL 1.1 API