Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sapphire-dev] Model property enablement API?

Ok. Now I remember what’s going on. This is an artifact of how pre-cursors to EnablementService worked and adding refresh() call to state() was the easiest way to handle migration of existing code. See here:

 

http://www.eclipse.org/sapphire/releases/0.3/documentation/releases/0.3/migration.html#enablement

 

When using @DependsOn, there is expectation that enablement state is re-computed, but EnablementService is architected to do its own caching so that all that happens during @DependsOn triggered property refresh is that the existing enablement value is returned by state() method. Triggering refresh() during state() call "fixes" that. An ok solution for migrating a lot of existing code, but not the best way to write new code.

 

The way it supposed to work is that EnablementService is responsible for listening on its own inputs and triggering refresh(). That’s why the refresh() method is protected.

 

Hope that makes sense.

 

- Konstantin

 

From: sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On Behalf Of Shenxue Zhou
Sent: Wednesday, November 16, 2011 9:36 AM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

 

I searched all the subclasses of EnablementService within OEPE, they all override this method. Without doing so, I am not able to trigger calls to compute() method. Could it be a bug in the enablement state refresh logic?

 


From: Konstantin Komissarchik
Sent: Wednesday, November 16, 2011 10:32 AM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

That looks like patching over a bug somewhere else. You should not be triggering refresh on every call to state() and its only by chance that something asks for state at the precise moment that a refresh is needed in your scenario. In fact, I am not sure why the state() method isn’t final in the first place…

 

- Konstantin

 

 

From: sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On Behalf Of Shenxue Zhou
Sent: Wednesday, November 16, 2011 9:28 AM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

 

I forgot to add the following method override in my enablement service. After I added it, it works fine. Thanks!

 

@Override

public boolean state()

{

refresh();

return super.state();

}

 


From: Konstantin Komissarchik
Sent: Tuesday, November 15, 2011 6:21 PM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

That looks ok to me. You can debug this by placing a breakpoint on the line where refreshPropertyEnablement call is made for PROP_CREATE_WITH_PAGE_FRAGMENTS in the generated element class.

 

- Konstantin

 

 

From: sapphire-dev-bounces@xxxxxxxxxxx [mailto:sapphire-dev-bounces@xxxxxxxxxxx] On Behalf Of Shenxue Zhou
Sent: Tuesday, November 15, 2011 4:01 PM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

 

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

 


From: Shenxue Zhou
Sent: Tuesday, November 15, 2011 4:11 PM
To: Sapphire project
Subject: Re: [sapphire-dev] Model property enablement API?

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?

 

Thanks,

 

Shenxue


Back to the top