Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » How to get live updates while maintaining a sorted tree(Live updates are tearing the tree items apart)
icon5.gif  How to get live updates while maintaining a sorted tree [message #1567817] Fri, 16 January 2015 15:47 Go to next message
Xavier Wolfs is currently offline Xavier WolfsFriend
Messages: 10
Registered: January 2015
Junior Member
We are trying to fill a tree with a bunch of activities, each of which can have 0 to many subactivities which specify the day they take place on. All updates were going great (testing against 10.000 activities, each with 0-7 subactivities) until we began to implement sorting. When sorting, it seemed that some items would not be sorted correctly. Right now, we are sorting on the time of an activity and haven't expanded to allowing to user to choose a different kind of sorting.

Initial sorting of the list goes fine, but we update an activity (and subactivities), there is a reasonable chance that the sorting will fail. For instance, if we start with a tree like

-Activity 1, starts at 4:00
---SubActivity1, starts at 4:00 on Mondays
---SubActivity2, starts at 4:00 on Tuesdays
---SubActivity3, starts at 4:00 on Thursdays
-Activity 2, starts at 12:30
---SubActivity1, starts at 12:30 on Tuesdays
---SubActivity2, starts at 12:30 on Wednesdays
---SubActivity3, starts at 12:30 on Thursdays
-Activity 3, starts at 23:00
---SubActivity1, starts at 23:00 on Mondays
---SubActivity2, starts at 23:00 on Tuesdays
---SubActivity3, starts at 23:00 on Sundays

If we now update the activities in activity 1 to start at 19:00 (the subactivities are changed as well to reflect this, sometimes the sorting fails and we get a tree that looks like this:

-Activity 1, starts at 19:00
---SubActivity3, starts at 19:00 on Thursdays
-Activity 2, starts at 12:30
---SubActivity1, starts at 12:30 on Tuesdays
---SubActivity2, starts at 12:30 on Wednesdays
---SubActivity3, starts at 12:30 on Thursdays
-Activity 1, starts at 19:00
---SubActivity1, starts at 19:00 on Mondays
---SubActivity2, starts at 19:00 on Tuesdays
-Activity 3, starts at 23:00
---SubActivity1, starts at 23:00 on Mondays
---SubActivity2, starts at 23:00 on Tuesdays
---SubActivity3, starts at 23:00 on Sundays

Also, not changing the time of the subactivities would leave all of them stranded at the top.

Our code

Glazed list wise, we are using: ArrayList > EventList > ObservableList > SortedList > TreeList. The sortedlist takes the comparator which compares the activities by time. We then put the treelist into a GlazedListTreeData etc. as per the example _6041_TreeGridExample line 199-262.

The TreeFormat we use right now has no comparator specified, as we sort this in the list, which seems to override this sorting. I should mention that I did attempt to place the sorting of the Activities here, returning the comparator at a depth of 0, which ended up with the same results (children got seperated from their parents). Each child has a reference to their parent, which is how we create the entire treepath, so the fact that they lose their parent is rather weird to me.

I have the feeling there is something that we are missing, either the fact that sorting a tree with live updates is just to time intensive to make workable, or there is a part of Nattable we have failed to implement correctly. So basically, the question would be if it is actually possible to do what we are trying to do in the first place.

I should mention that for testing, we are updating 500 rows each second. However, with a smaller number of activities and updates (20 activities and 2 updates per second), we saw the exact same behaviour. Also, I am not sure if this is normal, but it seemed that with 60.000 rows, the comparator we are using (the one on the sortedlist) was called over a million times.
Re: How to get live updates while maintaining a sorted tree [message #1567850 is a reply to message #1567817] Fri, 16 January 2015 16:14 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
What you are missing is the comparator on the TreeFormat. To get the tree correctly build it is necessary to have the TreeList sorted in a way the tree can be build. This means the children need to be in the correct order so the parents only need to be created once.

Also you need to ensure that your activities and subactivities implement equals and hashCode to work properly with the TreeList.
Re: How to get live updates while maintaining a sorted tree [message #1567892 is a reply to message #1567850] Fri, 16 January 2015 16:40 Go to previous messageGo to next message
Xavier Wolfs is currently offline Xavier WolfsFriend
Messages: 10
Registered: January 2015
Junior Member
Thanks for the quick response. I fifured we were missing something, just not what. I belive I tried everything, except for sorting the subactivites in the treeformat. Seeing as I'm already commuting home, I will let you know on Monday what the results are. Thanks in advance and have a great weekend.
Re: How to get live updates while maintaining a sorted tree [message #1572840 is a reply to message #1567892] Mon, 19 January 2015 11:12 Go to previous messageGo to next message
Xavier Wolfs is currently offline Xavier WolfsFriend
Messages: 10
Registered: January 2015
Junior Member
Hi Dirk,

I tried implementing the comparator in the TreeFormat as you suggested, with children being sorted and then the parents. However, I find myself unable to sort at depth 1 (the SubActivities), as these do not allow children. I did sort Activities, but with the same result. Children ended up being separated from their parents after an update. We now think the problem lies not with Nattable but with GlazedList and are looking at redesigning the view to no longer require a tree, but a table.

To clarify:

public class Activity extends RowData {
        public UUID rowId;
        public String time;

        //getters and observable setters

        //equals and hashcode implemented to be equal on rowId.equals(other.rowId);
}


public class SubActivity extends RowData {
        public UUID rowId;
        public String time;
        public String day;

        //getters and observable setters

        //equals and hashcode implemented to be equal on rowId.equals(other.rowId);
}


public class RowFormat implements TreeList.Format<RowData> {

 @Override
    public void getPath(List<RowData> path, RowData element) {
        if (element instanceof SubActivity) {
            path.add(((Activity) element).getParent());
        }
        path.add(element);
    }

@Override
    public boolean allowsChildren(RowData element) {
        return element instanceof Activity;
    }

    @Override
    public Comparator<? super RowData > getComparator(final int depth) {
        return new Comparator<RowData>() {
                @Override
                public int compare(RowData row1, RowDatarij2 row2) {
                        return row1.getTime().compareTo(row2.getTime());
                }
        };
}

[Updated on: Mon, 19 January 2015 11:54]

Report message to a moderator

Re: How to get live updates while maintaining a sorted tree [message #1572911 is a reply to message #1572840] Mon, 19 January 2015 12:09 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
Well I'm pretty sure your issue is not related to NatTable. Smile

How does your update code look like? Maybe it is a runtime issue somehow. Since all your RowData objects do have a time and they all have the same time value in the example, the sorting should work even without a type check. So from your initial post, the first two elements in the tree after the update do not reflect the data, since they need to be with the second occurence of Activity 1.

The only other thing I know is about updating a TreeList. Maybe this link helps http://glazedlists.1045722.n5.nabble.com/sorting-a-treelist-td4704550.html ... We use a similar approach for the GroupBy feature.
Re: How to get live updates while maintaining a sorted tree [message #1573143 is a reply to message #1572911] Mon, 19 January 2015 15:06 Go to previous messageGo to next message
Xavier Wolfs is currently offline Xavier WolfsFriend
Messages: 10
Registered: January 2015
Junior Member
From your response and link I am getting the feeling that the way we have set up our Comparator might have been wrong. What we did was create the comparator to sort the Activities and then trust the SubActivities to follow suit. From the link however I am getting the feeling that the position given to the RowData object by the sorted list takes presedence over the location of its parent.

Going to try and work on that, see what turns up. Thanks for the help.
Re: How to get live updates while maintaining a sorted tree [message #1580342 is a reply to message #1573143] Fri, 23 January 2015 12:37 Go to previous message
Xavier Wolfs is currently offline Xavier WolfsFriend
Messages: 10
Registered: January 2015
Junior Member
Follow-up with where we went wrong, so other people might learn from our mistake.

To quickly summarize, what we were seeing was that our sorted tree was seperating parents from children once we started updating rows. Eventually, we discovered that this was caused by the fact that our treenodes and leaves were both alive inside our Eventlist. Going from the example above, the list held both Activities as well as Subactivities. This meant, that as soon as we started sorting them, it would put them in the correct order (SortedList) and then add parents to the children (TreeList).

We figured our Comparator would help with this, but this doesn't work with the way GlazedList sorts its lists. To summarize, what we told our Comparator was to always put a child below their parent.
if (activity.getId().equals(subactivity.getParentid()) {
return <1 or -1, depending on what is being sorted>
}
. Now, the SortedList will look left and right to see where to put an updated element, so when looking right, an Activity would always say it was smaller than its children, and not be sorted.

We eventually fixed this by only putting SubActivities and those Activities that did not have SubActivities inside the Eventlist. The Activities to which any SubActivities belong are then added later, by the TreeFormat. I think it's a little hard to understand and I am afraid I can't really explain to much of this without breaking any NDA's, but suffice it to say that an Activity in our domain is fundamentally different from a SubActivity, but still have a parent/child relation.

Anyway, updates and sorting are now going great (using 10k parents with 1k updates every second) we hardly notice any lag, though sometimes NatTable will repaint itself. We are not to overly worried about this, since this is a crazy stress test to see how the table will hold up under extreme. We are, in a real scenario, looking at more like 5-10 activities maybe twice a minute, if that. It is, at the least, a very significant improvement over the old table.

[Updated on: Fri, 23 January 2015 12:38]

Report message to a moderator

Previous Topic:Multi edit in Menu options
Next Topic:NatTable version numbers
Goto Forum:
  


Current Time: Wed Mar 03 02:40:22 GMT 2021

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

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

Back to the top