ObjectListTable ordering issue after change - help!

0 views
Skip to first unread message

Pete

unread,
Aug 6, 2008, 11:43:19 AM8/6/08
to GWT-Stuff
Hi Sandy,

I've been tearing my hair out with an issue where I have an
ObjectListTable backed by an EventList, initially just a
ObservingEventList wrapped in a SortedEventList (natural order). My
model objects in the list implement compareTo(o) and I add all the
Objects at once initially using addAll(orders) on the
ObservingEventList.

The initial sorting and rendering of the table is fine, but if I edit
a value in the Table then the ordering of the object I've just changed
goes wrong - the changed object jumps down a place in the rendered
table, e.g. if edit row 5 then after edit the row that was after it
(row 6) jumps to before the row5 !. I'm not editing any of the values
used in the compareTo, and it happens if I edit either of 2 cells that
are editable. I've checked the setters and all seems fine.

e.g before
1
2
3
4
5 row 5 edited
6 not edited
7
8
9
10

after
1
2
3
4
6 not edited (moved forward!)
5 row 5 edited
7
8
9
10

I've compared the code to your TestObjectListTable and it's very
similar, yet yours works fine after editing a cell.
My onChange() event for the editable cells just sets the property into
the model object.


I have stepped thru the code in debug, in gwt-stuff and thought I
could get to bottom of it, but no luck after many hours, what is
baffling is the comparator is working fine on initial rendering so why
would it go wrong after a change. I've struggled to understand the

SortedEventListImpl.listChangedAdded()

in particular the translations and reverse lists, I can see the code
seems to start with the changed model object instance o
then compares each model object with the changed one, when comparator
finds a row in list > than the changed row the iteration stops, it's
here things start to go wrong but I can't see why and what I've done
different. Anyhow I've annotated below the values found during debug
which seems to show why the rows get swapped, but I've no clue why...

for (pos = 0; pos < translations.size(); pos++) {
final Object posO =
delegate.get(((Index)translations.get(pos)).getIndex());
if (comparator.compare(posO, o) > 0) {
break;
}
}

final Index newIdx = new Index(i); // 4 - position of changed
row
final Index revIdx = new Index(pos); // 5 - position of row >
changed row after compareTo

shiftUp(i, translations.iterator()); // 4, [0, 1, 2, 3, 4, 5, 6, 7,
8] after [0, 1, 2, 3, 5, 6, 7, 8, 9] i.e to leave a gap for 4? i.e
adds 1 to items 4 and above
shiftUp(pos, reverse.iterator()); // 5, [0, 1, 2, 3, 4, 5, 6, 7,
8] after [0, 1, 2, 3, 4, 6, 7, 8, 9] i.e to leave a gap for 5? i.e
adds 1 to items 5 and above

translations.add(pos, newIdx); // add index into translations at
pos 5 was [0, 1, 2, 3, 5, 6, 7, 8, 9] after [0, 1, 2, 3, 5, 4, 6, 7,
8, 9]
reverse.add(i, revIdx); // add revIdx into reverse at
pos 4 was [0, 1, 2, 3, 4, 6, 7, 8, 9] after [0, 1, 2, 3, 5, 4,
6, 7, 8, 9]

fireListEvent(ListEvent.createAdded(SortedEventListImpl.this,
pos)); // fires ADDED for pos 5 (one after changed row)

I would very much appreciate your help with this. I'm sure it some
mistake on my part.

I also tried nesting the SortedEventList inside a Filtered and Ranged
list like your TestObjectListTable but it made no difference

many thanks
Pete

public int compareTo(Object object) {
final OrderLine other = (OrderLine)object;

final int LESSTHAN = -1;
final int EQUAL = 0;
final int GRTHAN = 1;

int i =
getOrderlineLineNumber().compareTo(other.getOrderlineLineNumber());
if (i == EQUAL) {
i =
getDeliveryLineNumber().compareTo(other.getDeliveryLineNumber());
if (i == EQUAL) {
i =
getDeliveryLineSubNumber().compareTo(other.getDeliveryLineSubNumber());
}
}
return i;
}

Pete

unread,
Aug 22, 2008, 5:50:24 AM8/22/08
to GWT-Stuff
Any thoughts on this one ?

Only thing I have found is after this sorting error occurs (after an
edit), if I then re-sort the ObjectListTable by clicking 'Sort Down'
then 'Sort up' in the table column heading, then the list is rendered
in the correct order.

All this does is set the same comparator into the :-

sortedEventList.setComparator(OrderLine.OrderLineComparator.ASCENDING_LINENUMBER);

I've made sure both the natural ordering compareTo() and the
sortedEventList.setComparator use the same logic by making natural
ordering compareTo() delegate to that same comparator, yet I still
get the problem if a individual row is changed. I've also made sure
the original construction of the ObjectListTable is with a EventList
wrapped in the sortedEventList which also has the same comparator
set.

So this seems to indicate there might be a bug in the
SortedEventListImpl.listChangedAdded() logic ? (although as I said
before it seems to be ok in your TestObjectListTable's instance).

I'm quite stuck.

Pete

Pete

unread,
Sep 3, 2008, 9:24:05 AM9/3/08
to GWT-Stuff
For now I have patched a local copy of gwt-stuff...

the line to re-sort the whole list was commented out so I presume this
once originally used before the newer optimized code ,
so I've brought back in the complete re-sort to solve this problem
which seems to occur in the listChangedChanged(listEvent) when just
passed a single row range

Again any ideas on the underlying bug would be much appreciated.

private class SortedListEventListener implements ListEventListener {
public void listChanged(final ListEvent listEvent) {
if (listEvent.isAdded()) {
listChangedAdded(listEvent);

} else if (listEvent.isChanged()) {
// TODO: Optimize
// XXX: fuck it! just resort the whole thing.

// Pete: the line below was commented out, but using a
complete re-sort solves this problem which seems to occur
// in the now commented out
listChangedChanged(listEvent) below
sort();
//listChangedChanged(listEvent);

} else if (listEvent.isRemoved()) {
listChangedRemoved(listEvent);

} else {

fireListEvent(listEvent.resource(SortedEventListImpl.this));
Reply all
Reply to author
Forward
0 new messages