I attached an enablement service and a @DependsOn to my
"CreateWithPageFragment" property:
// *** CreateWithPageFragments
***
@Type( base = Boolean.class
) @Label( standard = "create with page fragments"
) @DefaultValue( text = "true" )
@DependsOn("TemplateReference/Document") @Service(impl =
PageFragmentEnablementService.class)
ValueProperty PROP_CREATE_WITH_PAGE_FRAGMENTS = new
ValueProperty( TYPE, "CreateWithPageFragments" );
Value<Boolean>
isCreateWithPageFragments(); void
setCreateWithPageFragments( String value ); void
setCreateWithPageFragments( Boolean value ); //
*** TemplateReference *** @Type( base =
ITemplateReference.class ) @Label( standard = "based on
template") ElementProperty PROP_TEMPLATE_REFERENCE =
new ElementProperty( TYPE, "TemplateReference" );
ModelElementHandle<ITemplateReference2>
getTemplateReference();
But
PageFragmentEnablementService isn't called when TemplateReference's Document property is changed. Am I doing something wrong here?
Thanks,
Shenxue
When I thought about doing this through a property
listener, the logic actually involved creating a new model and checking property
states in the new model. So I am not able to write an EL for
that.
An enablement service plus DependsOn should work in this
case. Thanks!
Shenxue
From: Konstantin
Komissarchik Sent: Tuesday, November 15, 2011 3:57 PM To:
Sapphire project Subject: Re: [sapphire-dev] Model property enablement
API?
The
EnablementService controls property’s enablement state. The standard
implementation that goes along with @Enablement annotation uses Sapphire EL, but
you can implement the service directly. Typically, the service implementation
would use information in the model or the environment to compute the enablement
state, but there is nothing stopping one from implementing an EnablementService
that exposes getter/setter methods for directly controlling the enablement
state.
I’d
question the need for inverting the typical logic, though. If you needing to do
this from a property listener, then apparently the enablement state is
controlled based on some property’s state. You should therefore be able to
define enablement logic (either via Sapphire EL or via a custom
EnablementService) that computes the enablement state instead of relying on some
external party to set it.
-
Konstantin
From:
sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On
Behalf Of Shenxue Zhou Sent: Tuesday, November 15, 2011 2:29
PM To: Sapphire project Subject: [sapphire-dev] Model
property enablement API?
I need to
enable/disable a model property based on certain events and conditions. The
_expression_ based @Enablement is not sufficient for my needs. I'm actually trying
to do this inside a property listener. ModelElement does not seem to have API's
to disable/enable a property. How do I do this?
|