Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » On using PossibleValuesService for dynamically changed list of values
On using PossibleValuesService for dynamically changed list of values [message #1497449] Wed, 03 December 2014 20:49 Go to next message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
I have a long list of xml elements
    <object id="object107" extends="object17"/>

where each element declares an unique id and optionally extends another object from the same file, referencing it by id.
Field editor for property 'extends' should display list of available ids. The list should dynamically change when xml is modified.

I implemented extension of PossibleValuesService for property 'extends'. When computing values, the implementation adds listeners to referenced model objects, so that when 'id' is modified or element 'object' added or removed, listener calls for refresh of values.

It works fine for small files, but causes concerns for large ones.

An instance of PossibleValuesService is created for each object/@extends. At invoking popup by a filed editor button, the first call to computing values occurs. That is nice. However, then, at a change event, each of service objects that computed values should be called through its listener to refresh them, - otherwise, possible values at corresponding field editor remain obsolete. I could do computation just once, but even if each service object is going to have the same list of possible values, I have to fill new Set<String> in compute(Set<String>) method because method PossibleValuesService.compute() is final.

Suppose I work with a file that has 1000 objects in the editor for a long time, and have edited 'extends' at 100 objects. By now, 100 service instances added listeners to 1000 model objects and keep 100 tree sets of 1000 strings each. Each next adding new object will cause creating 100 new sets and filling them with 1000 objects each. They will replace old sets, no memory leak, but it is still a heavy load on memory and performance.

Maybe I do it all wrong and there is a better solution. Please advise it.
Re: On using PossibleValuesService for dynamically changed list of values [message #1497471 is a reply to message #1497449] Wed, 03 December 2014 21:10 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
No, you didn't miss anything. Memory use optimization is an area that could definitely use further work. Please open an enhancement request to make PossibleValuesService.compute() method non-final to allow re-use of existing sets.

Note that you can also implement your scenario by using the @PossibleValues annotation. This wouldn't be any more efficient than your custom PossibleValuesService implementation, but definitely less code to write. Figuring out a way to re-use sets computed by this annotation would also be a good project and worth a separate enhancement request.

@PossibleValues( property = "/Objects/@id" )
Re: On using PossibleValuesService for dynamically changed list of values [message #1499151 is a reply to message #1497471] Fri, 05 December 2014 00:07 Go to previous messageGo to next message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
My example is simplified, in general, values can depend on object, e.g. in my example it may be not allowed for an element to reference itself.
It may be just important to avoid cashing all possible values. Moreover, it may be desirable to represent all possible values as a tree with an opportunity to build children dynamically, as a tree node is expanded - the tree may have unlimited set of values.
I guess it can be achieved in Sapphire by customising property editor instead of using values service. May I bind to the property editor declaration in *.sdef PopUpListFieldPropertyEditorPresentation.Factory (to have text input and button) and a custom action, bound to 'Sapphire.Browse' in that property editor declaration's context, that would run a wizard with a desired values provider and presentation?

[Updated on: Fri, 05 December 2014 00:11]

Report message to a moderator

Re: On using PossibleValuesService for dynamically changed list of values [message #1499193 is a reply to message #1499151] Fri, 05 December 2014 00:55 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Quote:
It may be just important to avoid cashing all possible values.


That's not possible. The browse dialog isn't the only consumer of the set computed by PossibleValuesService. It's also used for validation, so it's critical to not re-compute the set on every reference and to know when the set has changed, so that validation can be updated.

Quote:
May I bind to the property editor declaration in *.sdef PopUpListFieldPropertyEditorPresentation.Factory (to have text input and button) and a custom action, bound to 'Sapphire.Browse' in that property editor declaration's context, that would run a wizard with a desired values provider and presentation?


The pop-up list presentation is based on PossibleValuesService, but you can use the basic text box presentation together with a custom browse action handler that you attach to the property editor in sdef.
Re: On using PossibleValuesService for dynamically changed list of values [message #1499326 is a reply to message #1499193] Fri, 05 December 2014 03:40 Go to previous messageGo to next message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
Yes, the text box with a custom browse action is a nice solution. Only one more question. Will it be possible to bind to the text box a custom content assist that I would implement with use of the same values provider as for browser? It would be perfect if for the case of tree-like structured values (as Java classes in packages) it could be possible to give in assist parts of entire value (as for Java class in empty field only root packages 'org', 'com', etc.)
Re: On using PossibleValuesService for dynamically changed list of values [message #1499339 is a reply to message #1499326] Fri, 05 December 2014 03:59 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
To get content assist within the property editor text box, implement ContentProposalService. There is a system-provided implementation that works with PossibleValuesService, but you can supply a custom implementation and attach it to the property.
Re: On using PossibleValuesService for dynamically changed list of values [message #1499403 is a reply to message #1499339] Fri, 05 December 2014 05:14 Go to previous message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
Thank you! I've got it.
Previous Topic:How to declare and set an integer field in Sapphire?
Next Topic:Expanding tree node on dbl click
Goto Forum:
  


Current Time: Tue Mar 19 02:28:19 GMT 2024

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

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

Back to the top