Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Sorted Node Factory(How to create an automatically sorted Node Factory?)
Sorted Node Factory [message #1388431] Thu, 26 June 2014 12:41 Go to next message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
Hello Smile

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 ? &quot;UnNamed&quot; : 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]

Report message to a moderator

Re: Sorted Node Factory [message #1388504 is a reply to message #1388431] Thu, 26 June 2014 14:33 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
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 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
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.
Previous Topic:Announcing Sapphire 8 Release
Next Topic:Required @Type annotation missing
Goto Forum:
  


Current Time: Fri Dec 27 01:21:40 GMT 2024

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

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

Back to the top