Bug 140697 [Viewers] selection not preserved when setting has children
1. Debug testcase without stopping in main or breakpoint 2. Select thread, and terminate The suspend action sometimes remain enabled after the debug session is terminated. I added some tracing to the code. When the debug session is terminated, if AbstractDebugContextAction#updateEnablementStateForContext is run after SuspendResumeAdapter's "canSuspend" job, then the suspend action would be disabled properly. However, in some cases, the updateEnablementStateForContext method is run before the "canSuspend" job from SuspendResumeAdapter, and because JDTThread returns true for #canSuspend even if it's terminated, the action got enabled incorrectly. (I am wondering if JDIThread is doing the right thing here. It should return false for #canSuspend if it's teminated?) I also tried making async viewer not preserve selection during setData with this bug. If I turned off preserve selection in this case, the action is always disabled properly. This is because the action would never try to update its enablement state for a terminated java thread. Testcase: public class TestConsole { /** * @param args */ public static void main(String[] args) { try { int count = 0; while (System.in.read() != -1); } catch (IOException e) { e.printStackTrace(); } }
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
}
				Widget[] items = internalFindItems(elementOrTreePath);
				for (int i = 0; i < items.length; i++) {
					TreeItem treeItem = (TreeItem) items[i];
					treeItem.setItemCount(count);
				}
			}
		});
	}
	/**
	 * For a TreeViewer with a tree with the VIRTUAL style bit set, replace the
	 * given parent's child at index with the given element. If the given parent
	 * is this viewer's input or an empty tree path, this will replace the root
	 * element at the given index.
	 * <p>
	 * This method should be called by implementers of ILazyTreeContentProvider
	 * to populate this viewer.
	 * </p>
	 * 
	 * @param parentElementOrTreePath
	 *            the parent of the element that should be updated, or the tree
	 *            path to that parent
	 * @param index
	 *            the index in the parent's children
	 * @param element
	 *            the new element
	 * 
	 * @see #setChildCount(Object, int)
	 * @see ILazyTreeContentProvider
	 * @see ILazyTreePathContentProvider