Bug 159918 [Viewers] TreeViewer.setChildCount(...) should preserve selection
Since changing the child count of an element in a tree can effectively remove children, the #setChildCount(...) method should preserve selection. This way if a selected item is disposed, the selection change will fire with the new <empty selection>.
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
children = ((TreeItem) widget).getItems();
			}
			if (element != null && children.length > 0) {
				for (int i = 0; i < children.length; i++) {
					lazyTreeContentProvider.updateElement(element, i);
				}
			}
			return;
		}
		super.createChildren(widget);
	}
	protected void internalAdd(Widget widget, Object parentElement,
			Object[] childElements) {
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
			if (widget instanceof TreeItem) {
				TreeItem ti = (TreeItem) widget;
				int count = ti.getItemCount() + childElements.length;
				ti.setItemCount(count);
				ti.clearAll(false);
			} else {
				Tree t = (Tree) widget;
				t.setItemCount(t.getItemCount() + childElements.length);
				t.clearAll(false);
			}
			return;
		}
		super.internalAdd(widget, parentElement, childElements);
	}
	private void virtualMaterializeItem(TreeItem treeItem) {
		if (treeItem.getData() != null) {