Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.scopemvc.view.swing
Class SAbstractListModel  view SAbstractListModel download SAbstractListModel.java

java.lang.Object
  extended byjavax.swing.AbstractListModel
      extended byorg.scopemvc.view.swing.SAbstractListModel
All Implemented Interfaces:
javax.swing.ListModel, org.scopemvc.view.util.ModelBindable, org.scopemvc.core.ModelChangeListener, Refreshable, java.io.Serializable
Direct Known Subclasses:
SComboBoxModel, SListModel, STableModel

public abstract class SAbstractListModel
extends javax.swing.AbstractListModel
implements org.scopemvc.view.util.ModelBindable, Refreshable, org.scopemvc.core.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) 55 or setSizeSelectorString(java.lang.String) 55 .

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) 55 or all list elements implement Comparable and setSorted(boolean) 55 is called.

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

Version:
$Revision: 1.11 $ $Date: 2002/01/26 09:46:20 $

Field Summary
private  SwingBoundModel boundModel
          Helper to manage model to view binding.
private  java.util.Comparator comparator
           
private static org.scopemvc.core.IntIndexSelector index
          Share this instance for all fetches from the list.
protected  java.lang.Object listModel
           
private static org.apache.commons.logging.Log LOG
           
private  org.scopemvc.core.PropertyManager manager
          The property manager for the bound (list) model.
private  java.lang.Object shownModel
          The (list) model object that the SListModel presents, which may be a property of the bound model if a Selector is specified.
protected  org.scopemvc.core.Selector sizeSelector
           
private  boolean sorted
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SAbstractListModel()
           
 
Method Summary
 java.lang.Object getBoundModel()
           
 java.lang.Object getElementAt(int inIndex)
          Note that if the get() fails for any reason, a null is returned.
(package private)  org.scopemvc.core.PropertyManager getManager()
           
 org.scopemvc.core.Selector getSelector()
           
 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()
          Return the number of data elements in the list.
 org.scopemvc.core.Selector getSizeSelector()
           
 java.lang.Object getViewValue()
          Makes no sense: can't change the property using an SAbstractListModel!
 boolean isSorted()
           
 void modelChanged(org.scopemvc.core.ModelChangeEvent inEvent)
           Invoked to notify listeners of a change in the state of a org.scopemvc.core.ModelChangeEventSource.
 void refresh()
          Update the widget with the current state of the bound model.
 void setBoundModel(java.lang.Object inModel)
           
 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(org.scopemvc.core.Selector inSelector)
           
 void setSelectorString(java.lang.String inSelectorString)
           
protected  void setShownModel(java.lang.Object inModel)
          Called internally from updateFromProperty().
 void setSizeSelector(org.scopemvc.core.Selector inSelector)
           
 void setSizeSelectorString(java.lang.String inSelectorString)
           
 void setSorted(boolean inSorted)
           
 void setSorted(java.util.Comparator inComparator)
           
 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

LOG

private static final org.apache.commons.logging.Log LOG

sorted

private boolean sorted

comparator

private java.util.Comparator comparator

sizeSelector

protected org.scopemvc.core.Selector sizeSelector

listModel

protected java.lang.Object listModel

boundModel

private SwingBoundModel boundModel
Helper to manage model to view binding.


shownModel

private java.lang.Object shownModel
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.


index

private static final org.scopemvc.core.IntIndexSelector index
Share this instance for all fetches from the list. Synchronize on it first!


manager

private org.scopemvc.core.PropertyManager manager
The property manager for the bound (list) model.

Constructor Detail

SAbstractListModel

public SAbstractListModel()
Method Detail

setSizeSelector

public void setSizeSelector(org.scopemvc.core.Selector inSelector)

setSizeSelectorString

public void setSizeSelectorString(java.lang.String inSelectorString)

getSizeSelector

public org.scopemvc.core.Selector getSizeSelector()

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.


isSorted

public boolean isSorted()

setSorted

public void setSorted(boolean inSorted)

setSorted

public void setSorted(java.util.Comparator inComparator)

setComparator

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


getBoundModel

public final java.lang.Object getBoundModel()

setBoundModel

public void setBoundModel(java.lang.Object inModel)

getSelector

public final org.scopemvc.core.Selector getSelector()

setSelector

public final void setSelector(org.scopemvc.core.Selector inSelector)

setSelectorString

public final void setSelectorString(java.lang.String inSelectorString)

updateFromProperty

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

Specified by:
updateFromProperty in interface org.scopemvc.view.util.ModelBindable

getViewValue

public final java.lang.Object getViewValue()
Makes no sense: can't change the property using an SAbstractListModel!

Specified by:
getViewValue in interface org.scopemvc.view.util.ModelBindable

validationFailed

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

Specified by:
validationFailed in interface org.scopemvc.view.util.ModelBindable

validationSuccess

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

Specified by:
validationSuccess in interface org.scopemvc.view.util.ModelBindable

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.


setShownModel

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


refresh

public void refresh()
Description copied from interface: Refreshable
Update the widget with the current state of the bound model. Probably something like this:
     Object propertyValue = boundModel.getPropertyValue();
     boolean propertyReadOnly = boundModel.getPropertyReadOnly();
     updateFromProperty(propertyValue, propertyReadOnly);
 

Specified by:
refresh in interface Refreshable

getManager

final org.scopemvc.core.PropertyManager getManager()

modelChanged

public void modelChanged(org.scopemvc.core.ModelChangeEvent inEvent)
Description copied from interface: org.scopemvc.core.ModelChangeListener

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

Specified by:
modelChanged in interface org.scopemvc.core.ModelChangeListener

getSize

public int getSize()
Description copied from interface: javax.swing.ListModel
Return the number of data elements in the list.

Specified by:
getSize in interface javax.swing.ListModel

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