Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Approach for Attaching/Detaching Listeners
Approach for Attaching/Detaching Listeners [message #1229179] Wed, 08 January 2014 21:57 Go to next message
Andreas Weise is currently offline Andreas WeiseFriend
Messages: 37
Registered: January 2014
Member
I have a model containing an Element 'Captions', that I want to reuse on several other Elements in the model (using interface inheritance).

The captions element contains a ListPropery 'FooListProperty' that needs to be modified upon value change of a ValueProperty 'RootElement/BarValueProperty', which exists on the root of the model.

I therefore want to create a FilteredListener for each instance of the 'Captions' element or 'FooListProperty' property, that is in charge for making the changes. That listener should be attached on 'RootElement/BarValueProperty'. But I'm stuck on from which place I could create and attach/detach this listener.

I've tried the Service approach but could not get it running:
1. Service, that registers Listener within init(). Created a CustomService extends Service, added it to META-INF sapphire-extension.xml, annotated it on FooListProperty with @Service > but init() method is never invoked!
2. like 1. + including a Condition Class, that was also added to sapphire-extension.xml > applicable() method is never invoked!

What's required to get the init() method invoked of a CustomService that extends org.eclipse.sapphire.services.Service ?

Or could you please advice whats the easiest approach for attaching/detaching a simple listener on a field. I also did not find a suitable example in the samples project.

Thanks for your answer.
Andreas

[Updated on: Wed, 08 January 2014 21:59]

Report message to a moderator

Re: Approach for Attaching/Detaching Listeners [message #1229203 is a reply to message #1229179] Wed, 08 January 2014 23:26 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
A service will not be initialized unless it is requested. In your scenario, nothing is requesting your CustomService.

There is an @Listeners annotation that you can add to a property to listen on that property. It is frequently used to implement scenarios similar to yours. You can use it on your RootElement/BarValueProperty, so it's an inversion of your initial attempt, but should work.
Re: Approach for Attaching/Detaching Listeners [message #1229338 is a reply to message #1229203] Thu, 09 January 2014 08:34 Go to previous messageGo to next message
Andreas Weise is currently offline Andreas WeiseFriend
Messages: 37
Registered: January 2014
Member
Yeah an inversion of the attempt would work but requires more maintenance of the listener, as there are couple of captions throughout the model.

But I've now found an approach for my initial idea by creating a CustomXmlListBinding that extends StandardXmlListBindingImpl and adding it on the ListProperty of the reusable element. init()/dispose() methods of this binding are suitable for handling the listeners lifecycle.

One remaining questions regarding the custom service approach is where I would typically request such a custom service from?

[Updated on: Thu, 09 January 2014 08:34]

Report message to a moderator

Re: Approach for Attaching/Detaching Listeners [message #1229492 is a reply to message #1229338] Thu, 09 January 2014 14:59 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Quote:
One remaining questions regarding the custom service approach is where I would typically request such a custom service from?


You would request the service from its context, in this case your property instance (for instance element.getSomeProp().service(CustomService.class)). The service is initialized on first access. As to where you would make this call, that depends on what you need the service for. You can do it from another service, or from a ui aspect, such as an action, or from anywhere else for that matter.
Previous Topic:Label on @PossibleValues
Next Topic:Dynamically enable Action
Goto Forum:
  


Current Time: Tue Apr 16 05:30:13 GMT 2024

Powered by FUDForum. Page generated in 0.01873 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top