protected static final Function createVersionCompatibleFunction( final Property property )
{
if( property != null )
{
final MasterVersionCompatibilityService service = property.service( MasterVersionCompatibilityService.class );
final Function function = new Function()
{
@Override
public String name()
{
return "VersionCompatible";
}
@Override
public FunctionResult evaluate( final FunctionContext context )
{
return new FunctionResult( this, context )
{
private Listener serviceListener;
private Listener propertyListener;
@Override
protected void init()
{
this.serviceListener = new Listener()
{
@Override
public void handle( final Event event )
{
refresh();
}
};
service.attach( this.serviceListener );
this.propertyListener = new FilteredListener<PropertyContentEvent>()
{
@Override
protected void handleTypedEvent( final PropertyContentEvent event )
{
refresh();
}
};
if( property.definition() instanceof ImpliedElementProperty )
{
property.element().attach( this.propertyListener, property.name() + "/*" );
}
else
{
property.element().attach( this.propertyListener, property.name() );
}
}
@Override
protected Object evaluate()
{
return service.compatible() || ! property.empty();
}
@Override
public void dispose()
{
super.dispose();
service.detach( this.serviceListener );
if( property.definition() instanceof ImpliedElementProperty )
{
property.element().detach( this.propertyListener, property.name() + "/*" );
}