org.scopemvc.view.swing
Class SAbstractListModel

java.lang.Object
  |
  +--javax.swing.AbstractListModel
        |
        +--org.scopemvc.view.swing.SAbstractListModel
All Implemented Interfaces:
javax.swing.ListModel, ModelBindable, ModelChangeListener, Refreshable, java.io.Serializable
Direct Known Subclasses:
SComboBoxModel, SListModel, STableModel

public abstract class SAbstractListModel
extends javax.swing.AbstractListModel
implements ModelBindable, Refreshable, ModelChangeListener

A javax.swing.AbstractListModel bound to a property of a model used by SList, SComboBox, STable. The property should have elements accessible using IntIndexedSelectors and needs to fulfill one of the following criteria:

  1. be a java.util.List
  2. be an Object[]
  3. optional: have an accessible 'size' property in the parent view model (see below)
Unfortunately this means that JavaBeans indexed properties cannot be bound directly to an SAbstractListModel because there is no way to discover the size of such a list, unless a separate property can be accessed to provide the size of the list using setSizeSelector(org.scopemvc.core.Selector) or setSizeSelectorString(java.lang.String).

If required, the model for items can be specified as a static ListModelAdapter when it is more convenient to specify the list model at initialisation of (for example) an SComboBox rather than include it in the view model for active binding.

The list can present its elements as a sorted list if a Comparator is passed to setSorted(java.util.Comparator) or all list elements implement Comparable and setSorted(boolean) is called.

***** This implementation makes no provisions for thread-safety.

Version:
$Revision: 1.17 $ $Date: 2002/09/13 17:11:26 $
Author:
Steve Meyfroidt
See Also:
SList, STable, SComboBox, ListModelAdaptor, Serialized Form

Field Summary
protected  java.lang.Object listModel
          TODO: describe of the Field
protected  Selector sizeSelector
          TODO: describe of the Field
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SAbstractListModel()
           
 
Method Summary
protected  boolean containsElement(java.lang.Object inValue)
          Returns true if the bound model contains the value in its list of elements
protected  void doModelChanged(ModelChangeEvent inEvent)
          Respond to a change in the model by firing the appropriate ListDataEvent
 java.lang.Object getBoundModel()
          Gets the bound model
 java.lang.Object getElementAt(int inIndex)
          Note that if the get() fails for any reason, a null is returned.
 Selector getSelector()
          Gets the selector
 java.lang.Object getShownModel()
          Get the (list) model object that the SListModel presents, which may be a property of the bound model if a Selector is specified.
 int getSize()
          Gets the size
 Selector getSizeSelector()
          Gets the size selector
 java.lang.Object getViewValue()
          Get the current value (what would be set as a property of the bound model object) being presented on the View.
 boolean isSorted()
          Gets the sorted
 void modelChanged(ModelChangeEvent inEvent)
           Invoked to notify listeners of a change in the state of a ModelChangeEventSource.
 void refresh()
          TODO: document the method
 void setBoundModel(java.lang.Object inModel)
          Sets the bound model
 void setComparator(java.util.Comparator inComparator)
          Deprecated. see setSorted(Comparator)
 void setListModel(java.lang.Object inModel)
          Can use this to specify a static list model for the contents of the list rather than binding to a dynamic property of some view model.
 void setSelector(Selector inSelector)
          Sets the selector
 void setSelectorString(java.lang.String inSelectorString)
          Sets the selector string
protected  void setShownModel(java.lang.Object inModel)
          Called internally from updateFromProperty().
 void setSizeSelector(Selector inSelector)
          Sets the size selector
 void setSizeSelectorString(java.lang.String inSelectorString)
          Sets the size selector string
 void setSorted(boolean inSorted)
          Sets the sorted
 void setSorted(java.util.Comparator inComparator)
          Sets the sorted
 void updateFromProperty(java.lang.Object inValue, boolean inReadOnly)
          Ignores inReadOnly because makes no sense here.
 void validationFailed(java.lang.Exception inException)
          Makes no sense: can't change the property using an SAbstractListModel!
 void validationSuccess()
          Makes no sense: can't change the property using an SAbstractListModel!
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeSelector

protected Selector sizeSelector
TODO: describe of the Field


listModel

protected java.lang.Object listModel
TODO: describe of the Field

Constructor Detail

SAbstractListModel

public SAbstractListModel()
Method Detail

getBoundModel

public final java.lang.Object getBoundModel()
Gets the bound model

Returns:
The boundModel value

getSelector

public final Selector getSelector()
Gets the selector

Returns:
The selector value

getViewValue

public final java.lang.Object getViewValue()
Get the current value (what would be set as a property of the bound model object) being presented on the View.

Specified by:
getViewValue in interface ModelBindable
Returns:
property's value from the UI.

getShownModel

public final java.lang.Object getShownModel()
Get the (list) model object that the SListModel presents, which may be a property of the bound model if a Selector is specified. May be null if the bound property is a JavaBeans indexed property.

Returns:
The shownModel value

getSizeSelector

public Selector getSizeSelector()
Gets the size selector

Returns:
The sizeSelector value

isSorted

public boolean isSorted()
Gets the sorted

Returns:
The sorted value

getSize

public int getSize()
Gets the size

Specified by:
getSize in interface javax.swing.ListModel
Returns:
The size value

getElementAt

public java.lang.Object getElementAt(int inIndex)
Note that if the get() fails for any reason, a null is returned.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
inIndex - TODO: Describe the Parameter
Returns:
The elementAt value

setSelector

public final void setSelector(Selector inSelector)
Sets the selector

Parameters:
inSelector - The new selector value

setSelectorString

public final void setSelectorString(java.lang.String inSelectorString)
Sets the selector string

Parameters:
inSelectorString - The new selectorString value

setSizeSelector

public void setSizeSelector(Selector inSelector)
Sets the size selector

Parameters:
inSelector - The new sizeSelector value

setSizeSelectorString

public void setSizeSelectorString(java.lang.String inSelectorString)
Sets the size selector string

Parameters:
inSelectorString - The new sizeSelectorString value

setListModel

public void setListModel(java.lang.Object inModel)
Can use this to specify a static list model for the contents of the list rather than binding to a dynamic property of some view model.

Parameters:
inModel - The new listModel value
See Also:
ListModelAdaptor

setSorted

public void setSorted(boolean inSorted)
Sets the sorted

Parameters:
inSorted - The new sorted value

setSorted

public void setSorted(java.util.Comparator inComparator)
Sets the sorted

Parameters:
inComparator - The new sorted value

setComparator

public void setComparator(java.util.Comparator inComparator)
Deprecated. see setSorted(Comparator)

Parameters:
inComparator - The new comparator value

setBoundModel

public void setBoundModel(java.lang.Object inModel)
Sets the bound model

Parameters:
inModel - The new boundModel value

updateFromProperty

public void updateFromProperty(java.lang.Object inValue,
                               boolean inReadOnly)
Ignores inReadOnly because makes no sense here.

Specified by:
updateFromProperty in interface ModelBindable
Parameters:
inValue - TODO: Describe the Parameter
inReadOnly - TODO: Describe the Parameter

validationFailed

public void validationFailed(java.lang.Exception inException)
Makes no sense: can't change the property using an SAbstractListModel!

Specified by:
validationFailed in interface ModelBindable
Parameters:
inException - TODO: Describe the Parameter

validationSuccess

public void validationSuccess()
Makes no sense: can't change the property using an SAbstractListModel!

Specified by:
validationSuccess in interface ModelBindable
See Also:
ModelBindable.validationFailed(java.lang.Exception)

refresh

public void refresh()
TODO: document the method

Specified by:
refresh in interface Refreshable

modelChanged

public void modelChanged(ModelChangeEvent inEvent)

Invoked to notify listeners of a change in the state of a ModelChangeEventSource.

ListDataEvent are fired by this method from the Swing event thread.

Specified by:
modelChanged in interface ModelChangeListener
Parameters:
inEvent - the ModelChangeEvent representing the change in state of the ModelChangeEventSource.

setShownModel

protected void setShownModel(java.lang.Object inModel)
Called internally from updateFromProperty().

Parameters:
inModel - The new shownModel value

doModelChanged

protected void doModelChanged(ModelChangeEvent inEvent)
Respond to a change in the model by firing the appropriate ListDataEvent

Parameters:
inEvent - the ModelChangeEvent representing the change in state of the ModelChangeEventSource.

containsElement

protected boolean containsElement(java.lang.Object inValue)
Returns true if the bound model contains the value in its list of elements

Parameters:
inValue - The value to check
Returns:
true if the value belongs to the list of bound items


Copyright © 2000-2002 The Scope Team. All Rights Reserved.