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
if (element instanceof TreePath) {
					return new TreeSelection((TreePath) element, getComparer());
				}
				return new StructuredSelection(element);
			}
			protected Item[] getSelection() {
				return tree.getSelection();
			}
			protected void setEditor(Control w, Item item, int fColumnNumber) {
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
			}
			protected void setLayoutData(LayoutData layoutData) {
				treeEditor.grabHorizontal = layoutData.grabHorizontal;
				treeEditor.horizontalAlignment = layoutData.horizontalAlignment;
				treeEditor.minimumWidth = layoutData.minimumWidth;
			}
			protected void showSelection() {
				getTree().showSelection();
			}
		};
	}
	/*
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
	 */
	protected Item newItem(Widget parent, int flags, int ix) {
		TreeItem item;
		if (parent instanceof TreeItem) {
			item = (TreeItem) createNewRowPart(getViewerRowFromItem(parent),
					flags, ix).getItem();
		} else {