Sorted Node Factory [message #1388431] |
Thu, 26 June 2014 12:41  |
Eclipse User |
|
|
|
Hello 
Let's say I have the following XML:
<salaries>
<employee name="name1" salary="1000" />
<employee name="name2" salary="2000" />
<employee name="name3" salary="4000" />
<employee name="name4" salary="2500" />
<employee name="name5" salary="1500" />
<employee name="name6" salary="1100" />
<employee name="name7" salary="2300" />
</salaries>
Normally I would create a Node Factory for that like this:
<node-factory>
<property>Employees</property>
<case>
<section>
<content>
<property-editor>Name</property-editor>
<property-editor>Salary</property-editor>
</content>
</section>
<label>${ Name == null ? "UnNamed" : Name }</label>
</case>
</node-factory>
But then the employees will be viewed with the order they are in the XML. What if I want them to be viewed sorted by salary for example? or by name?
Note: I use Sapphire 0.7.2
[Updated on: Thu, 26 June 2014 12:44] by Moderator Report message to a moderator
|
|
|
Re: Sorted Node Factory [message #1388504 is a reply to message #1388431] |
Thu, 26 June 2014 14:33   |
Eclipse User |
|
|
|
The node factory itself does not support sorting, but you can sort the list in the model at the XML binding level.
1. Extend StandardXmlListBindingImpl and do your sorting in the readUnderlyingList() method.
2. Add @CustomXmlListBinding( impl = YourBinding.class ) and @ReadOnly to your list property. If you want to be able to insert, delete and rearrange elements in the list (no @ReadOnly), you will need to override more methods in StandardXmlListBindingImpl as the standard implementations will behave oddly with a sorted list.
You can even have multiple list properties pointing to the same XML elements, but with different sortings. Hope this helps.
|
|
|
Re: Sorted Node Factory [message #1390910 is a reply to message #1388504] |
Mon, 30 June 2014 07:01   |
Eclipse User |
|
|
|
Quote:If you want to be able to insert, delete and rearrange elements in the list (no @ReadOnly), you will need to override more methods in StandardXmlListBindingImpl as the standard implementations will behave oddly with a sorted list.
Which methods? and how is that?
|
|
|
Re: Sorted Node Factory [message #1392739 is a reply to message #1390910] |
Wed, 02 July 2014 19:44  |
Eclipse User |
|
|
|
I recommend just giving it a try to see what kind of behavior you get. Looking at the code, all position-based list manipulation methods reference the list provided by readUnderlyingList(), so you may not need to override anything else, but I couldn't tell you that for sure as I haven't tried this scenario myself.
|
|
|
Powered by
FUDForum. Page generated in 0.03791 seconds