|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--org.scopemvc.model.basic.BasicModel
A simple implementation of ModelChangeEventSource for use as a base class. An alternative (JavaBeans style) is to use ModelChangeEventSupport as a delegate in all models.
To implement a BasicModel:
BasicModel, set methods by: fireModelChange(...)
public final static Selector NAME = Selector.fromString("name");
public final static Selector ADDRESS = Selector.fromString("address");
public void setAddress(AddressModel inAddress) throws ModelException {
if (inAddress == address) {
return;
}
unlistenOldSubmodel(ADDRESS); address =
inAddress; listenNewSubmodel(ADDRESS);
fireModelChange(VALUE_CHANGE, ADDRESS); } ModelChangeEventSource for more discussion. Note
the use of the Selector constants: this is for convenience (and
performance).
| Field Summary |
| Fields inherited from interface org.scopemvc.core.ModelChangeTypes |
ACCESS_CHANGED, VALUE_ADDED, VALUE_CHANGED, VALUE_REMOVED |
| Constructor Summary | |
BasicModel()
|
|
| Method Summary | |
void |
addModelChangeListener(ModelChangeListener inListener)
Adds a listener for ModelChangeEvent |
void |
fireModelChange(int inChangeType,
Selector inSelector)
Fire a ModelChangeEvent to all listeners |
protected void |
listenNewSubmodel(Selector inSelector)
Convenience for BasicModel implementors: call this at the end of setters for submodel properties (ie properties of type ModelChangeEventSource) to register this as a ModelChangeListener to the current submodel for event propagation. |
void |
makeActive(boolean inActive)
Control whether this BasicModel broadcasts ModelChangeEvents. |
void |
modelChanged(ModelChangeEvent inEvent)
Handle changes to children ModelChangeEventSources by firing a change event from this (and propagating the original Selector). |
void |
removeModelChangeListener(ModelChangeListener inListener)
Removes a listener for ModelChangeEvent |
protected void |
unlistenOldSubmodel(Selector inSelector)
Convenience for BasicModel implementors: call this at the start of setters for submodel properties (ie properties of type ModelChangeEventSource) to deregister this as a ModelChangeListener to the current submodel (about to be set to another Model). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public BasicModel()
| Method Detail |
public final void addModelChangeListener(ModelChangeListener inListener)
addModelChangeListener in interface ModelChangeEventSourceinListener - The listener to be addedpublic final void removeModelChangeListener(ModelChangeListener inListener)
removeModelChangeListener in interface ModelChangeEventSourceinListener - The listener to be removed
public final void fireModelChange(int inChangeType,
Selector inSelector)
fireModelChange in interface ModelChangeEventSourceinChangeType - The type of the change. One of the ModelChangeTypes valuesinSelector - The Selector for the property of the model affected by
the changepublic void modelChanged(ModelChangeEvent inEvent)
Handle changes to children ModelChangeEventSources by firing a change
event from this (and propagating the original Selector). If
the event's source is no longer a child property of this parent then
there is no need to continue propagating the event.
modelChanged in interface ModelChangeEventSourceinEvent - the event received from a child ModelChangeEventSource.public void makeActive(boolean inActive)
Control whether this BasicModel broadcasts ModelChangeEvents. Make sure nested calls are properly matched to fully re-activate a BasicModel that was deactivated.
Subclasses may override this to propagate the activation state to child BasicModel properties if necessary.
inActive - true to activate this model, false to desactivate itprotected final void unlistenOldSubmodel(Selector inSelector)
inSelector - The Selector for the submodelprotected final void listenNewSubmodel(Selector inSelector)
inSelector - The Selector for the submodel
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||