On 6/10/11 1:18 , Frank Grimm wrote:
I'm trying to add SideEffects to Properties of Composites so that I can
trace getting and setting of property values. In order to get a feeling
for Qi4j in general (I'm a Newbie) and SideEffects in particular, I
copied LogPropertyAccess and LogPropertyChanges from
org.qi4j.runtime.property.PropertyTest together with the Company and Co.
composite to my test application:
<snip>
I just verified in PropertyTest that my previous email works. Here is
the final code I used for the concern:
@AppliesTo( PropertyMixin.PropertyFilter.class )
public static class LogConcern
extends GenericConcern
{
@Override
public Object invoke( Object o, Method method, Object[] objects
) throws Throwable
{
final Property<Object> property = (Property<Object>)
next.invoke( o, method, objects );
return new ComputedPropertyInstance<Object>(property)
{
@Override
public Object get()
{
Object result = property.get();
System.out.println( "Property " +
property.qualifiedName().name() + " accessed with value " + result);
return result;
}
@Override
public void set( Object newValue ) throws
IllegalArgumentException, IllegalStateException
{
Object current = property.get();
property.set( newValue );
System.out
.println( "Property " + property.qualifiedName()
.name() + " changed from " + current +
" to " + newValue );
}
};
}
}
---
The main modification that one would like here is that it should be
possible to register PropertyChangeListeners to an individual property
instance. Putting a PropertyChangeSupport instance into the metainfo
would make the most sense I think, but the question is how to get a new
instance per property instance, instead of one for all property
instances. This I don't yet know how to do.
With the above it would still be possible to generate events that are
broadcast in the application (using something like
http://java.net/projects/eventbus), which listeners could then pick up.
In my own apps I have found that pattern to be more useful anyway, in
order to get property changes in one place to easily affect a completely
different panel.
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev