Bug 210448 [Viewers] [JFace] AbstractTreeViewer inputChanged setRedraw should be in try/finally
The inputChanged method on the AbstractTreeViewer makes use of setRedraw, which is good, but it doesn't use a try/finally block as per recommendations. If an exception is thrown from within one of the methods called, redraw will remain false. Additionally, the commented out portion is fine, but the fact that we have conditionals in the code that always evaluate to true is less fine. When we're ready to actually determine when to use redraw we could put them back in. Current code: protected void inputChanged(Object input, Object oldInput) { preservingSelection(new Runnable() { public void run() { Control tree = getControl(); boolean useRedraw = true; // (size > REDRAW_THRESHOLD) || (table.getItemCount() > // REDRAW_THRESHOLD); if (useRedraw) { tree.setRedraw(false); } removeAll(tree); tree.setData(getRoot()); internalInitializeTree(tree); if (useRedraw) { tree.setRedraw(true); } } }); } Suggestion: protected void inputChanged(Object input, Object oldInput) { preservingSelection(new Runnable() { public void run() { Control tree = getControl(); try { tree.setRedraw(false); removeAll(tree); tree.setData(getRoot()); internalInitializeTree(tree); } finally { tree.setRedraw(true); } } }); }
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
* This method takes a tree path or an element. If the argument is not a
	 * tree path, returns the parent of the given element or <code>null</code>
	 * if the parent is not known. If the argument is a tree path with more than
	 * one segment, returns its parent tree path, otherwise returns
	 * <code>null</code>.
	 *
	 * @param elementOrTreePath
	 * @return the parent element, or parent path, or <code>null</code>
	 *
	 * @since 3.2
	 */
	protected Object getParentElement(Object elementOrTreePath) {
		if (elementOrTreePath instanceof TreePath) {
			TreePath treePath = (TreePath) elementOrTreePath;
			return (treePath).getParentPath();
		}
		IContentProvider cp = getContentProvider();
		if (cp instanceof ITreePathContentProvider) {
			ITreePathContentProvider tpcp = (ITreePathContentProvider) cp;
			TreePath[] paths = tpcp.getParents(elementOrTreePath);
			if (paths.length > 0) {
				if (paths[0].getSegmentCount() == 0) {
					return getInput();
				}
				return paths[0].getLastSegment();
			}
		}
		if (cp instanceof ITreeContentProvider) {
			ITreeContentProvider tcp = (ITreeContentProvider) cp;
			return tcp.getParent(elementOrTreePath);