Pete
unread,Aug 6, 2008, 11:43:19 AM8/6/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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;
}