org.jminor.common.model.valuemap
Class AbstractValueChangeMapEditModel<K,V>

java.lang.Object
  extended by org.jminor.common.model.valuemap.AbstractValueChangeMapEditModel<K,V>
Type Parameters:
K - the type of the keys in the value map
V - the type of the values in the value map
All Implemented Interfaces:
Refreshable, ValueChangeMapEditModel<K,V>
Direct Known Subclasses:
DefaultEntityEditModel

public abstract class AbstractValueChangeMapEditModel<K,V>
extends Object
implements ValueChangeMapEditModel<K,V>

A class which facilitates the editing of the contents of a ValueChangeMap instance by providing a validation mechanism as well as value change events.


Constructor Summary
AbstractValueChangeMapEditModel(ValueChangeMap<K,V> initialMap, ValueMapValidator<K,V> validator)
          Instantiates a new edit model instance for the given value map.
 
Method Summary
 void addValueListener(K key, ActionListener listener)
          
 void addValueMapSetListener(ActionListener listener)
          
 void addValueSetListener(K key, ActionListener listener)
          
 void clear()
          Clears all data from this refreshable instance
 StateObserver getModifiedState()
          
 ValueMapValidator<K,V> getValidator()
          
 StateObserver getValidState()
          
 V getValue(K key)
          Returns the value associated with the given key in the underlying value map
 EventObserver getValueChangeObserver(K key)
          
protected  ValueChangeMap<K,V> getValueMap()
           
 boolean isModified()
          
 boolean isNullable(K key)
          
 boolean isValid()
          
 boolean isValid(K key, int action)
          Returns true if the given value is valid for the given key, using the validate method
 boolean isValueNull(K key)
          
protected  V prepareNewValue(K key, V value)
          Provides a hook into the value setting mechanism, override to translate or otherwise manipulate the value being set
 void refresh()
          Performs a refresh
 void removeValueListener(K key, ActionListener listener)
          
 void removeValueMapSetListener(ActionListener listener)
          
 void removeValueSetListener(K key, ActionListener listener)
          
 void setValue(K key, V value)
          Sets the given value in the underlying value map
 void setValueMap(ValueChangeMap<K,V> valueMap)
          Sets the active value map, that is, deep copies the value from the source map into the underlying map
 void validate(K key, int action)
          Checks if the value associated with the give key is valid, throws a ValidationException if not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jminor.common.model.valuemap.ValueChangeMapEditModel
getDefaultValueMap
 

Constructor Detail

AbstractValueChangeMapEditModel

public AbstractValueChangeMapEditModel(ValueChangeMap<K,V> initialMap,
                                       ValueMapValidator<K,V> validator)
Instantiates a new edit model instance for the given value map.

Parameters:
initialMap - the value map to edit
validator - the validator
Method Detail

clear

public void clear()
Clears all data from this refreshable instance

Specified by:
clear in interface Refreshable

refresh

public void refresh()
Performs a refresh

Specified by:
refresh in interface Refreshable

getValidator

public final ValueMapValidator<K,V> getValidator()

Specified by:
getValidator in interface ValueChangeMapEditModel<K,V>
Returns:
the validatorAFTM

isNullable

public final boolean isNullable(K key)

Specified by:
isNullable in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
Returns:
true if this value is allowed to be null in the underlying value map

validate

public final void validate(K key,
                           int action)
                    throws ValidationException
Checks if the value associated with the give key is valid, throws a ValidationException if not

Specified by:
validate in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
action - describes the action requiring validation, ValueChangeMapEditModel.INSERT, ValueChangeMapEditModel.UPDATE or ValueChangeMapEditModel.UNKNOWN
Throws:
ValidationException - if the given value is not valid for the given key

getValue

public final V getValue(K key)
Returns the value associated with the given key in the underlying value map

Specified by:
getValue in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key of the value to retrieve
Returns:
the value associated with the given key

setValue

public final void setValue(K key,
                           V value)
Sets the given value in the underlying value map

Specified by:
setValue in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key to associate the given value with
value - the value to associate with the given key

isValueNull

public final boolean isValueNull(K key)

Specified by:
isValueNull in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
Returns:
true if the value of the given key is null

setValueMap

public final void setValueMap(ValueChangeMap<K,V> valueMap)
Sets the active value map, that is, deep copies the value from the source map into the underlying map

Specified by:
setValueMap in interface ValueChangeMapEditModel<K,V>
Parameters:
valueMap - the map to set as active, if null then the default map value is set as active
See Also:
ValueChangeMapEditModel.getDefaultValueMap(), ValueChangeMapEditModel.addValueMapSetListener(java.awt.event.ActionListener)

isValid

public final boolean isValid(K key,
                             int action)
Returns true if the given value is valid for the given key, using the validate method

Specified by:
isValid in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
action - describes the action requiring validation, ValueChangeMapEditModel.INSERT, ValueChangeMapEditModel.UPDATE or ValueChangeMapEditModel.UNKNOWN
Returns:
true if the value is valid
See Also:
ValueChangeMapEditModel.validate(Object, int), ValueMapValidator.validate(ValueMap, Object, int)

isModified

public final boolean isModified()

Specified by:
isModified in interface ValueChangeMapEditModel<K,V>
Returns:
true if the underlying value map is modified
See Also:
ValueChangeMapEditModel.getModifiedState()

isValid

public final boolean isValid()

Specified by:
isValid in interface ValueChangeMapEditModel<K,V>
Returns:
true if the underlying value map contains only valid values
See Also:
()

addValueSetListener

public final void addValueSetListener(K key,
                                      ActionListener listener)

Specified by:
addValueSetListener in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key for which to monitor value changes
listener - a listener notified each time the value of key is set

removeValueSetListener

public final void removeValueSetListener(K key,
                                         ActionListener listener)

Specified by:
removeValueSetListener in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
listener - the listener to remove

getValueChangeObserver

public final EventObserver getValueChangeObserver(K key)

Specified by:
getValueChangeObserver in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key for which to retrieve the event
Returns:
an Event object which fires when the value of key changes

addValueListener

public final void addValueListener(K key,
                                   ActionListener listener)

Specified by:
addValueListener in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key for which to monitor value changes
listener - a listener notified each time the value of key changes

removeValueListener

public final void removeValueListener(K key,
                                      ActionListener listener)

Specified by:
removeValueListener in interface ValueChangeMapEditModel<K,V>
Parameters:
key - the key
listener - the listener to remove

addValueMapSetListener

public final void addValueMapSetListener(ActionListener listener)

Specified by:
addValueMapSetListener in interface ValueChangeMapEditModel<K,V>
Parameters:
listener - a listener notified each time the value map is set

removeValueMapSetListener

public final void removeValueMapSetListener(ActionListener listener)

Specified by:
removeValueMapSetListener in interface ValueChangeMapEditModel<K,V>
Parameters:
listener - the listener to remove

getModifiedState

public final StateObserver getModifiedState()

Specified by:
getModifiedState in interface ValueChangeMapEditModel<K,V>
Returns:
a State indicating the modified status of this value map
See Also:
ValueChangeMapEditModel.isModified()

getValidState

public final StateObserver getValidState()

Specified by:
getValidState in interface ValueChangeMapEditModel<K,V>
Returns:
a State indicating the valid status of this value map
See Also:
ValueChangeMapEditModel.getValidator(), ValueChangeMapEditModel.isValid()

prepareNewValue

protected V prepareNewValue(K key,
                            V value)
Provides a hook into the value setting mechanism, override to translate or otherwise manipulate the value being set

Parameters:
key - the key
value - the value
Returns:
the prepared value

getValueMap

protected final ValueChangeMap<K,V> getValueMap()
Returns:
the value map instance being edited