net.sf.doolin.bus.support
Class PropertyChangeSupport

java.lang.Object
  extended by net.sf.doolin.bus.support.PropertyChangeSupport

public class PropertyChangeSupport
extends Object

Utility class to support property changes based on the Bus.

Author:
Damien Coraboeuf
See Also:
PropertyChangeSubscriber, PropertyChangeMessage

Method Summary
static void change(Object bean, String property, Object oldValue, Object newValue)
          Notifies the Bus that a property has changed
static void connectBothWays(SubscriberValidator validator, Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath)
          Operates a two-ways connection between two beans and two properties.
static void connectOneWay(SubscriberValidator validator, Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath)
          Connects a source property to a target property, in one way only.
static
<S,T> void
connectOneWay(SubscriberValidator validator, Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath, Adapter<S,T> adapter)
          Connects a source property to a target property, in one way only, using an adapter between the two properties.
static void connectOneWayAndUpdate(SubscriberValidator validator, Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath)
          Connects a source property to a target property, in one way only, and updates the target immediately.
static
<S,T> void
connectOneWayAndUpdate(SubscriberValidator validator, Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath, Adapter<S,T> adapter)
          Connects a source property to a target property, in one way only, using an adapter between the two properties, and updates the target property immediately.
static String getExecutionDescription(Object targetBean, String targetPropertyPath)
           
static void subscribe(PropertyChangeSubscriber subscriber)
          Utility method to subscribe a Subscriber to the Bus.
static void subscribe(SubscriberValidator validator, Object bean, String propertyPath, PropertyChangeListener listener)
           
static void subscribe(SubscriberValidator validator, Object bean, String propertyPath, Runnable runnable)
          Registers a property subscriber that runs a task whenever the given property is changed.
static
<S,T> void
update(Object sourceBean, String sourcePropertyPath, Object targetBean, String targetPropertyPath, Adapter<S,T> adapter)
          Updates a target property from a source property, using an optional adapter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

change

public static void change(Object bean,
                          String property,
                          Object oldValue,
                          Object newValue)
Notifies the Bus that a property has changed

Parameters:
bean - Bean whose property has changed
property - Path to the changed property
oldValue - New value for the property
newValue - New value for the property

connectBothWays

public static void connectBothWays(SubscriberValidator validator,
                                   Object sourceBean,
                                   String sourcePropertyPath,
                                   Object targetBean,
                                   String targetPropertyPath)
Operates a two-ways connection between two beans and two properties. The target property is immediately updated from the source.

Parameters:
validator - Subscription validator
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property
See Also:
BothWayPropertyChangeSubscriber, update(Object, String, Object, String, Adapter)

connectOneWay

public static void connectOneWay(SubscriberValidator validator,
                                 Object sourceBean,
                                 String sourcePropertyPath,
                                 Object targetBean,
                                 String targetPropertyPath)
Connects a source property to a target property, in one way only.

Parameters:
validator - Subscription validator
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property

connectOneWay

public static <S,T> void connectOneWay(SubscriberValidator validator,
                                       Object sourceBean,
                                       String sourcePropertyPath,
                                       Object targetBean,
                                       String targetPropertyPath,
                                       Adapter<S,T> adapter)
Connects a source property to a target property, in one way only, using an adapter between the two properties.

Type Parameters:
S - Type of the source property
T - Type of the target property
Parameters:
validator - Subscription validator
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property
adapter - Adapter from the source property to the target property

connectOneWayAndUpdate

public static void connectOneWayAndUpdate(SubscriberValidator validator,
                                          Object sourceBean,
                                          String sourcePropertyPath,
                                          Object targetBean,
                                          String targetPropertyPath)
Connects a source property to a target property, in one way only, and updates the target immediately.

Parameters:
validator - Subscription validator
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property
See Also:
update(Object, String, Object, String, Adapter)

connectOneWayAndUpdate

public static <S,T> void connectOneWayAndUpdate(SubscriberValidator validator,
                                                Object sourceBean,
                                                String sourcePropertyPath,
                                                Object targetBean,
                                                String targetPropertyPath,
                                                Adapter<S,T> adapter)
Connects a source property to a target property, in one way only, using an adapter between the two properties, and updates the target property immediately.

Type Parameters:
S - Type of the source property
T - Type of the target property
Parameters:
validator - Subscription validator
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property
adapter - Adapter from the source property to the target property
See Also:
update(Object, String, Object, String, Adapter)

getExecutionDescription

public static String getExecutionDescription(Object targetBean,
                                             String targetPropertyPath)

subscribe

public static void subscribe(PropertyChangeSubscriber subscriber)
Utility method to subscribe a Subscriber to the Bus.

Parameters:
subscriber - Subscriber to subscribe

subscribe

public static void subscribe(SubscriberValidator validator,
                             Object bean,
                             String propertyPath,
                             Runnable runnable)
Registers a property subscriber that runs a task whenever the given property is changed.

Parameters:
validator - Subscription validator
bean - Bean whose property may be changed
propertyPath - Path to the property
runnable - Task to execute when the property changes

subscribe

public static void subscribe(SubscriberValidator validator,
                             Object bean,
                             String propertyPath,
                             PropertyChangeListener listener)

update

public static <S,T> void update(Object sourceBean,
                                String sourcePropertyPath,
                                Object targetBean,
                                String targetPropertyPath,
                                Adapter<S,T> adapter)
Updates a target property from a source property, using an optional adapter.

Type Parameters:
S - Type of the source property
T - Type of the target property
Parameters:
sourceBean - Source bean
sourcePropertyPath - Path to the source property
targetBean - Target bean
targetPropertyPath - Path to the target property
adapter - Adapter between the source and the target property, or null if no adaptation is needed.


Copyright © 2011. All Rights Reserved.