|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.jfacefactories.presenters.AbstractPresenter<T>
public class AbstractPresenter<T>
Parent for 'Presenter' classes that wrap domain objects as java beans and
add UI logic as additional properties.
The wrapped domain object is of type T.
The domain object should be modified through the following protected
mutator methods that ensure that events are properly propagated:
setDomainObjectValue
addToDomainObjectCollection()
removeFromDomainObjectCollection()
editedDomainObjectCollectionElement()
setPresenterValue()
IS_CHANGED
- a boolean
IS_SAVEABLE
- a boolean
CHANGES
- a list of PropertyChangeEvent
's
addStandardProperty()
.
addPropertyMapping()
for more.
addStandardProperty()
, addPropertyMapping()
and
setExceptionHandler()
;
doPreSave()
,
doSave()
and doPostSave()
as necessary;
Create getters for the necessary domain object properties that simply
delegate to the the wrapped domain object;
Create setters for the necessary domain object properties that use the
protected mutator methods listed above;
Add additional properties direct to the subclass to describe GUI behaviour
Field Summary | |
---|---|
static java.lang.String |
CHANGES
One of the standard properties. |
static java.lang.String |
IS_CHANGED
One of the standard properties. |
static java.lang.String |
IS_SAVEABLE
One of the standard properties. |
Constructor Summary | |
---|---|
protected |
AbstractPresenter(AbstractPresenter<T> parent)
Constructor for presenter that has a parent model. |
protected |
AbstractPresenter(T domainObject)
Constructor for presenter that does not have a parent model. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Alerts the passed listener to any property changes on the Presenter. |
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Alerts the passed listener to any property changes relating to the passed property on the Presenter. |
protected void |
addPropertyMapping(java.lang.String modelProperty,
java.lang.String domainObjectProperty)
Adds a mapping between a presentation model property and the domain object's property. |
protected void |
addSiblingPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Alerts the passed listener to any property changes relating to the passed property on any other child presenter of this instance's parent presenter. |
protected void |
addStandardProperty(java.lang.String property)
Adds a standard property (see class javadoc for more). |
protected void |
addToDomainObjectCollection(java.lang.String propertyName,
java.lang.Object newElement)
Add the passed element to the Collection property identified by the passed property name. |
protected void |
addToDomainObjectCollection(java.lang.String propertyName,
java.lang.Object newElement,
java.lang.String... listenerProperties)
Add the passed element to the Collection property identified by the passed property name. |
protected boolean |
doIsSaveable()
Default method simply returns true. |
protected void |
doPostSave()
Subclasses can override if they have post-save actions. |
protected boolean |
doPreSave()
Default method simply returns true. |
protected boolean |
doSave()
Default method simply returns true. |
protected void |
editedDomainObjectCollectionElement(java.lang.String propertyName,
java.lang.Object changedElement)
Records that an element of a collection property has been changed. |
protected void |
editedDomainObjectCollectionElement(java.lang.String propertyName,
java.lang.Object changedElement,
java.lang.String... listenerProperties)
Records that an element of a collection property has been changed. |
java.util.List<java.beans.PropertyChangeEvent> |
getChanges()
Returns the recorded property changes on the domain object since the last save. |
protected T |
getDomainObject()
Accessor to the domain model. |
boolean |
isChanged()
Public property - whether the domain object has been changed or not. |
boolean |
isSaveable()
Public property - whether the domain object can be saved. |
protected void |
removeFromDomainObjectCollection(java.lang.String propertyName,
java.lang.Object newElement)
Removes the passed element from the Collection property identified by the passed property name. |
protected void |
removeFromDomainObjectCollection(java.lang.String propertyName,
java.lang.Object newElement,
java.lang.String... listenerProperties)
Removes the passed element from the Collection property identified by the passed property name. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the listener |
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Removes the listener |
protected void |
removeSiblingPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Removes the listener. |
void |
rollback()
Clears all changes, resetting the model and the domain object to their state after their last save (or initialisation). |
void |
save()
Causes the following sequence of calls: calls doPreSave() - if this returns false stops
calls doPreSave() on each child - if any returns false stops immediately
calls doSave() - if this returns false stops
calls doSave() on each child - if any returns false stops immediately
calls doPostSave()
calls doPostSave() on each child
Each implemented method in this sequence must handle its own errors, simply returning
false to indicate the save process must terminate. |
protected void |
setDomainObjectValue(java.lang.String propertyName,
java.lang.Object newValue)
Sets the value for the passed property on the domain object if it has changed where there are no associated calculated values affected Fires all standard property listeners; This also records the change and (potentially) marks the model as dirty. |
protected void |
setDomainObjectValue(java.lang.String propertyName,
java.lang.Object newValue,
java.lang.String... listenerProperties)
Sets the value for the passed property on the domain object if it has changed. |
void |
setExceptionHandler(IExceptionHandler handler)
Sets the exception handler for save and setter operations. |
protected void |
setPresenterValue(java.lang.String propertyName,
java.lang.Object newValue)
Sets the value for a passed property on the presenter (as opposed to the underlying domain object). |
protected void |
setPresenterValue(java.lang.String propertyName,
java.lang.Object newValue,
java.lang.String... listenerProperties)
Sets the value for a passed property on the presenter (as opposed to the underlying domain object). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String IS_CHANGED
boolean
property describing whether the
wrapped domain object has been changed since the last save. Note
this is based on the CHANGES
property so will report the
domain object as changed even if the changes result in the domain
object back in its original state.
public static final java.lang.String IS_SAVEABLE
boolean
property describing whether the
wrapped domain object can be saved or not.
public static final java.lang.String CHANGES
List
of PropertyChangeEvent
s
which lists the changes to the domain object since the last save.
Constructor Detail |
---|
protected AbstractPresenter(AbstractPresenter<T> parent)
perent
- - cannot be null.protected AbstractPresenter(T domainObject)
domainObject
- - cannot be null.Method Detail |
---|
protected final void addPropertyMapping(java.lang.String modelProperty, java.lang.String domainObjectProperty)
addPropertyMapping( "A", "B" )
would mean that the presentation model operates on a property called
"A" but whenever it updates the domain object, it updates the property
name "B". This is primarily for use in nested properties; ie. a
presenter property such as 'companyPhone' mapped to the domain
object property 'company.phone.number'.
modelProperty
- domainObjectProperty
- protected final void addStandardProperty(java.lang.String property)
property
- - cannot be null and must not already have been added.AbstractPresenter
public final void setExceptionHandler(IExceptionHandler handler)
handler
- public final void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- PropertyChangeSupport.addPropertyChangeListener(java.beans.PropertyChangeListener)
public final void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
propertyName
- listener
- PropertyChangeSupport.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
public final void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- PropertyChangeSupport.removePropertyChangeListener(java.beans.PropertyChangeListener)
public final void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
propertyName
- listener
- PropertyChangeSupport.removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
public final boolean isChanged()
IS_CHANGED
public boolean isSaveable()
super
.
public final java.util.List<java.beans.PropertyChangeEvent> getChanges()
CHANGES
public final void save()
doPreSave()
- if this returns false stops
calls doPreSave()
on each child - if any returns false stops immediately
calls doSave()
- if this returns false stops
calls doSave()
on each child - if any returns false stops immediately
calls doPostSave()
calls doPostSave()
on each child
public final void rollback()
rollback()
on all child presenters.
java.lang.Exception
protected final void setDomainObjectValue(java.lang.String propertyName, java.lang.Object newValue)
property
- - cannot be nullnewValue
- - can be nullprotected final void setDomainObjectValue(java.lang.String propertyName, java.lang.Object newValue, java.lang.String... listenerProperties)
property
- - cannot be nullnewValue
- - can be nulllistenerProperties
- - other properties for which listeners should be
fired if their values changeprotected final void addToDomainObjectCollection(java.lang.String propertyName, java.lang.Object newElement)
property
- newElement
- protected final void addToDomainObjectCollection(java.lang.String propertyName, java.lang.Object newElement, java.lang.String... listenerProperties)
property
- newElement
- listenerProperties
- - other properties for which listeners should be
fired if their values changeprotected final void removeFromDomainObjectCollection(java.lang.String propertyName, java.lang.Object newElement)
property
- newElement
- protected final void removeFromDomainObjectCollection(java.lang.String propertyName, java.lang.Object newElement, java.lang.String... listenerProperties)
property
- newElement
- listenerProperties
- - other properties for which listeners should be
fired if their values changeprotected final void editedDomainObjectCollectionElement(java.lang.String propertyName, java.lang.Object changedElement)
propertyName
- changedElement
- protected final void editedDomainObjectCollectionElement(java.lang.String propertyName, java.lang.Object changedElement, java.lang.String... listenerProperties)
propertyName
- changedElement
- listenerProperties
- - other properties for which listeners should be
fired if their values changeprotected final void setPresenterValue(java.lang.String propertyName, java.lang.Object newValue)
property
- - cannot be nullnewValue
- - can be nullprotected final void setPresenterValue(java.lang.String propertyName, java.lang.Object newValue, java.lang.String... listenerProperties)
property
- - cannot be nullnewValue
- - can be nulllistenerProperties
- - other properties for which listeners should be
fired if their values changeprotected final void addSiblingPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
IllegalStateException()
if the instance
was not instantiated with a parent presenter.
propertyName
- listener
- PropertyChangeSupport.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
protected final void removeSiblingPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
IllegalStateException()
if the instance
was not instantiated with a parent presenter.
propertyName
- listener
- PropertyChangeSupport.removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
protected T getDomainObject()
protected boolean doIsSaveable()
isSaveable()
property.
isSaveable()
protected boolean doPreSave()
save()
protected boolean doSave()
save()
protected void doPostSave()
doPostSave()
calls being made.
save()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |