org.jdesktop.binding
Class AbstractDataModel

java.lang.Object
  extended by org.jdesktop.binding.AbstractDataModel
All Implemented Interfaces:
DataModel, MetaDataProvider
Direct Known Subclasses:
DefaultDataModel, TableModelExtAdapter

public abstract class AbstractDataModel
extends java.lang.Object
implements DataModel

Abstract base class for implementing concrete DataModel implementations. This class provides support for managing validators and value change listeners. Subclasses must implement their own mechanism to store field meta-data and values.

Version:
1.0
Author:
Amy Fowler

Field Summary
protected  java.util.ArrayList validators
           
 
Constructor Summary
AbstractDataModel()
           
 
Method Summary
 void addValidator(Validator validator)
          Adds the specified validator for the fields represented by this data model.
 void addValueChangeListener(ValueChangeListener l)
          Adds the specified value change listener to be notified when the value is changed outside of calling setValue directly.
protected  void fireValueChanged(java.lang.String fieldName)
           
abstract  java.lang.String[] getFieldNames()
          Note: if the type for id is changed to Object type this will have to change to returning Object[].
 MetaData[] getMetaData()
          convenience to return all MetaData.
abstract  MetaData getMetaData(java.lang.String fieldName)
          Note: String will likely be converted to type Object for the ID
 Validator[] getValidators()
           
abstract  java.lang.Object getValue(java.lang.String fieldName)
           
 ValueChangeListener[] getValueChangeListeners()
           
 void removeValidator(Validator validator)
          Removes the specified validator from this data model.
 void removeValueChangeListener(ValueChangeListener l)
          Removes the specified value change listener from this value adapter.
 void setValue(java.lang.String fieldName, java.lang.Object value)
           
protected abstract  void setValueImpl(java.lang.String fieldName, java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jdesktop.binding.metadata.MetaDataProvider
getFieldCount
 

Field Detail

validators

protected java.util.ArrayList validators
Constructor Detail

AbstractDataModel

public AbstractDataModel()
Method Detail

getFieldNames

public abstract java.lang.String[] getFieldNames()
Description copied from interface: MetaDataProvider
Note: if the type for id is changed to Object type this will have to change to returning Object[].

Specified by:
getFieldNames in interface MetaDataProvider
Returns:
array containing the names of all data fields in this map

getMetaData

public MetaData[] getMetaData()
Description copied from interface: MetaDataProvider
convenience to return all MetaData.

Specified by:
getMetaData in interface MetaDataProvider
Returns:

getMetaData

public abstract MetaData getMetaData(java.lang.String fieldName)
Description copied from interface: MetaDataProvider
Note: String will likely be converted to type Object for the ID

Specified by:
getMetaData in interface MetaDataProvider
Parameters:
fieldName - String containing the id of the data object
Returns:
MetaData object which describes properties, edit constraints and validation logic for a data object

getValue

public abstract java.lang.Object getValue(java.lang.String fieldName)
Specified by:
getValue in interface DataModel
Parameters:
fieldName - String containing the name of the field
Returns:
Object containing the current value of the named field

setValue

public void setValue(java.lang.String fieldName,
                     java.lang.Object value)
Specified by:
setValue in interface DataModel
Parameters:
fieldName - String containing the name of the field
value - Object containing the current value of the named field

setValueImpl

protected abstract void setValueImpl(java.lang.String fieldName,
                                     java.lang.Object value)

addValidator

public void addValidator(Validator validator)
Description copied from interface: DataModel
Adds the specified validator for the fields represented by this data model. A validator object may be used to perform validation checks which require analyzing more than one field value in a single check. This DataModel instance will be passed in as the value parameter to the validator's validate method.

Specified by:
addValidator in interface DataModel
Parameters:
validator - Validator object which performs validation checks on this set of data field values
See Also:
DataModel.removeValidator(org.jdesktop.binding.metadata.Validator), DataModel.getValidators()

removeValidator

public void removeValidator(Validator validator)
Description copied from interface: DataModel
Removes the specified validator from this data model.

Specified by:
removeValidator in interface DataModel
Parameters:
validator - Validator object which performs validation checks on this set of data field values
See Also:
DataModel.addValidator(org.jdesktop.binding.metadata.Validator)

getValidators

public Validator[] getValidators()
Specified by:
getValidators in interface DataModel
Returns:
array containing the validators registered for data model

addValueChangeListener

public void addValueChangeListener(ValueChangeListener l)
Description copied from interface: DataModel
Adds the specified value change listener to be notified when the value is changed outside of calling setValue directly.

Specified by:
addValueChangeListener in interface DataModel
Parameters:
l - ValueChangeListener object to receive events when the field value changes

removeValueChangeListener

public void removeValueChangeListener(ValueChangeListener l)
Description copied from interface: DataModel
Removes the specified value change listener from this value adapter.

Specified by:
removeValueChangeListener in interface DataModel
Parameters:
l - ValueChangeListener object to receive events when the field value changes

getValueChangeListeners

public ValueChangeListener[] getValueChangeListeners()
Specified by:
getValueChangeListeners in interface DataModel
Returns:
array containing the ValueChangeListener objects registered on this data model

fireValueChanged

protected void fireValueChanged(java.lang.String fieldName)


Copyright © 2005 Sun Microsystems All Rights Reserved.