Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » DerivedValueService not working
DerivedValueService not working [message #1038318] Wed, 10 April 2013 18:25 Go to next message
Ellen Badgley is currently offline Ellen BadgleyFriend
Messages: 35
Registered: October 2012
Member
I have a model element with two properties: a ListProperty (containing "wrapped" ReferenceValues) and a String ValueProperty. The value of the second property is derived from the content of the first (it simply concatenates the IDs of all the referenced elements). The properties are as below:

//ListProperty
@Type(base = FusibleRef.class)
@Service(impl=InputIdPossibleValuesService.class)
@Label(full="Inputs", standard="Inputs")
ListProperty PROP_INPUTS = new ListProperty(TYPE, "inputs");
ModelElementList<FusibleRef> getInputs();

//ValueProperty that I want to refresh based on the above ListProperty
@Derived
@DependsOn("inputs")
@Service(impl=FusionFeedDerivedValueService.class)
ValueProperty PROP_FEED = new ValueProperty(TYPE, "Feed");
Value<String> getFeed();


However, my implementation of DerivedValueService is having its compute() method called only once, when the file is opened in the Sapphire editor, and nothing is happening when I make any changes to the "inputs" property. What might I be doing wrong?

Re: DerivedValueService not working [message #1038361 is a reply to message #1038318] Wed, 10 April 2013 19:39 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The issue is with your @DependsOn. As specified, it only catches changes to the list itself (adding an element, removing an element, re-arranging elements). It doesn't catch changes to internal properties of the contained elements. You want something like this instead...

@DependsOn( "Inputs/SomeValueProperty" )


- Konstantin
Re: DerivedValueService not working [message #1038376 is a reply to message #1038361] Wed, 10 April 2013 20:03 Go to previous messageGo to next message
Ellen Badgley is currently offline Ellen BadgleyFriend
Messages: 35
Registered: October 2012
Member
I wondered if something like that were the case, but adding/moving/rearranging elements in the list doesn't trigger the compute() in my DerivedValueService either.
Re: DerivedValueService not working [message #1038387 is a reply to message #1038376] Wed, 10 April 2013 20:23 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Does changing @DependsOn the way I suggested work?
Re: DerivedValueService not working [message #1038393 is a reply to message #1038387] Wed, 10 April 2013 20:31 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Never mind. The @DependsOn annotation causes a property refresh, which will call DerivedValueService.value(), which will not cause the value to be re-computed. The @DependsOn annotation is really a blunt legacy system for wiring up dependencies. The proper way to get DerivedValueService to update is for the service itself to listen on its inputs (override initDerivedValueService() and dispose() to do this). When your listener detects a change, call refresh() method in the service, which will call compute() and broadcast a change if the value changes.

- Konstantin
Re: DerivedValueService not working [message #1038421 is a reply to message #1038393] Wed, 10 April 2013 21:17 Go to previous messageGo to next message
Ellen Badgley is currently offline Ellen BadgleyFriend
Messages: 35
Registered: October 2012
Member
Konstantin-- Thank you. Overriding the other methods did the trick.

This is a related question (and should probably go in another thread), but...if I want to wait on retrieving a referenced element (out of my list property) until the user has had a chance to actually browse for and select one, is there 1) a particular PropertyEvent type to use; 2) an alternative to listening on each individual element in the list?
Re: DerivedValueService not working [message #1038437 is a reply to message #1038421] Wed, 10 April 2013 21:54 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
I am not quite sure I understand your question, but I can answer this part:

> an alternative to listening on each individual element in the list

When you attach a listener, you can use a model path. For instance, using a path like "Inputs/SomeValueProperty" will ensure that you are listening on all current instances of SomeValueProperty as well as all future ones. Sapphire will ensure the listener is propagated to the new elements when list changes.

You will likely want to focus on PropertyContentEvent. See FilteredListener for an easy way to do that. At the very least, you will want to ignore PropertyInitializationEvent.

- Konstantin
Re: DerivedValueService not working [message #1038440 is a reply to message #1038437] Wed, 10 April 2013 21:56 Go to previous message
Ellen Badgley is currently offline Ellen BadgleyFriend
Messages: 35
Registered: October 2012
Member
That is exactly what I was looking for (and you alluded to it above when you suggested changing the path passed to @DependsOn). Learning something new everyday, mostly thanks to you!
Previous Topic:Adding listener to a ListSelectionService from outside Sapphire?
Next Topic:Horizontal layout with fixed width
Goto Forum:
  


Current Time: Tue Mar 19 02:31:49 GMT 2024

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

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

Back to the top