Object[] children = getSortedChildren(getRoot());
Item[] items = doGetItems();
int min = Math.min(children.length, items.length);
for (int i = 0; i < min; ++i) {
Item item = items[i];
// if the element is unchanged, update its label if appropriate
if (equals(children[i], item.getData())) {
if (updateLabels) {
updateItem(item, children[i]);
} else {
// associate the new element, even if equal to the old
// one,
// to remove stale references (see bug 31314)
associate(children[i], item);
}
} else {
// updateItem does an associate(...), which can mess up
// the associations if the order of elements has changed.
// E.g. (a, b) -> (b, a) first replaces a->0 with b->0, then
// replaces b->1 with a->1, but this actually removes b->0.
// So, if the object associated with this item has changed,
// just disassociate it for now, and update it below.
// we also need to reset the item (set its text,images etc. to
// default values) because the label decorators rely on this
disassociate(item);
doClear(i);
}
}
// dispose of all items beyond the end of the current elements
if (min < items.length) {
for (int i = items.length; --i >= min;) {
disassociate(items[i]);
}
if (virtualManager != null) {
virtualManager.removeIndicesFromTo(min, items.length - 1);
}
doRemove(min, items.length - 1);
}
// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get
// scrunched
if (doGetItemCount() == 0) {
doRemoveAll();
}
// Update items which were disassociated above
for (int i = 0; i < min; ++i) {
Item item = items[i];
if (item.getData() == null) {
updateItem(item, children[i]);
}
}
// add any remaining elements
for (int i = min; i < children.length; ++i) {