*/
private void virtualSetSelectionToWidget(List list, boolean reveal) {
int size = list.size();
int[] indices = new int[list.size()];
Item firstItem = null;
int count = 0;
HashSet virtualElements = new HashSet();
for (int i = 0; i < size; ++i) {
Object o = list.get(i);
Widget w = findItem(o);
if (w instanceof Item) {
Item item = (Item) w;
indices[count++] = doIndexOf(item);
if (firstItem == null) {
firstItem = item;
}
} else {
virtualElements.add(o);
}
}
if (getContentProvider() instanceof ILazyContentProvider) {
ILazyContentProvider provider = (ILazyContentProvider) getContentProvider();
// Now go through it again until all is done or we are no longer
// virtual
// This may create all items so it is not a good
// idea in general.
// Use #setSelection (int [] indices,boolean reveal) instead
for (int i = 0; virtualElements.size() > 0 && i < doGetItemCount(); i++) {
provider.updateElement(i);
Item item = doGetItem(i);
if (virtualElements.contains(item.getData())) {
indices[count++] = i;
virtualElements.remove(item.getData());
if (firstItem == null) {
firstItem = item;
}
}
}
} else {
if (count != list.size()) {// As this is expensive skip it if all
// have been found
// If it is not lazy we can use the cache
for (int i = 0; i < virtualManager.cachedElements.length; i++) {
Object element = virtualManager.cachedElements[i];
if (virtualElements.contains(element)) {
Item item = doGetItem(i);
item.getText();// Be sure to fire the update
indices[count++] = i;
virtualElements.remove(element);
if (firstItem == null) {
firstItem = item;
}