View | Details | Raw Unified | Return to bug 113675
Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/AbstractTreeViewer.java (+46 lines)
Lines 85-90 Link Here
85
	 */
85
	 */
86
	private int expandToLevel = 0;
86
	private int expandToLevel = 0;
87
87
88
	private boolean preserveExpansion;
89
88
	/**
90
	/**
89
	 * Safe runnable used to update an item.
91
	 * Safe runnable used to update an item.
90
	 */
92
	 */
Lines 104-109 Link Here
104
106
105
	}
107
	}
106
108
109
	protected void preservingSelection(Runnable updateCode) {
110
		Object[] expandedElements = null;
111
		if (preserveExpansion) {
112
			expandedElements = getExpandedElements();
113
		}
114
		super.preservingSelection(updateCode);
115
		if (preserveExpansion) {
116
			setExpandedElements(expandedElements);
117
		}
118
	}
119
	
107
	/**
120
	/**
108
	 * Creates an abstract tree viewer. The viewer has no input, no content
121
	 * Creates an abstract tree viewer. The viewer has no input, no content
109
	 * provider, a default label provider, no sorter, no filters, and has
122
	 * provider, a default label provider, no sorter, no filters, and has
Lines 2436-2441 Link Here
2436
	}
2449
	}
2437
2450
2438
	/**
2451
	/**
2452
	 * Enable or disable the preserve expansion behavior of this viewer. The
2453
	 * default is that the viewer does not guarantee preserving deep expansion state
2454
	 * across update operations, for performance reasons. Note that this method
2455
	 * has been introduced in 3.5 and that trying to enable expansion state
2456
	 * preserving may not be possible for all subclasses of
2457
	 * <code>AbstractTreeViewer</code>, or may cause program errors. This method
2458
	 * is supported for {@link TreeViewer}, but no promises are made for other
2459
	 * subclasses of AbstractTreeViewer, or subclasses of the listed viewer
2460
	 * classes.
2461
	 * 
2462
	 * @param preserve
2463
	 *            <code>true</code> if expansion state should be preserved,
2464
	 *            <code>false</code> otherwise
2465
	 * @since 3.5
2466
	 */
2467
	public void setPreserveExpansion(boolean preserve) {
2468
		this.preserveExpansion = preserve;
2469
	}
2470
2471
	/**
2472
	 * Returns whether (deep) expansion state should be preserved across
2473
	 * update operations. To be used by subclasses that override
2474
	 * {@link #preservingSelection(Runnable)}.
2475
	 * 
2476
	 * @return <code>true</code> if expansion should be preserved,
2477
	 *         <code>false</code> otherwise
2478
	 * @since 3.5
2479
	 */
2480
	protected boolean getPreserveExpansion() {
2481
		return preserveExpansion;
2482
	}
2483
2484
	/**
2439
	 * Sets the selection to the given list of items.
2485
	 * Sets the selection to the given list of items.
2440
	 *
2486
	 *
2441
	 * @param items
2487
	 * @param items

Return to bug 113675