|
Lines 127-141
Link Here
|
| 127 |
public void add(Object parentElementOrTreePath, Object[] childElements) { |
127 |
public void add(Object parentElementOrTreePath, Object[] childElements) { |
| 128 |
Assert.isNotNull(parentElementOrTreePath); |
128 |
Assert.isNotNull(parentElementOrTreePath); |
| 129 |
assertElementsNotNull(childElements); |
129 |
assertElementsNotNull(childElements); |
| 130 |
|
130 |
if (isBusy()) |
| 131 |
Widget[] widgets = internalFindItems(parentElementOrTreePath); |
|
|
| 132 |
// If parent hasn't been realized yet, just ignore the add. |
| 133 |
if (widgets.length == 0) { |
| 134 |
return; |
131 |
return; |
| 135 |
} |
132 |
busy = true; |
| 136 |
|
133 |
try { |
| 137 |
for (int i = 0; i < widgets.length; i++) { |
134 |
Widget[] widgets = internalFindItems(parentElementOrTreePath); |
| 138 |
internalAdd(widgets[i], parentElementOrTreePath, childElements); |
135 |
// If parent hasn't been realized yet, just ignore the add. |
|
|
136 |
if (widgets.length == 0) { |
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
for (int i = 0; i < widgets.length; i++) { |
| 141 |
internalAdd(widgets[i], parentElementOrTreePath, childElements); |
| 142 |
} |
| 143 |
} finally { |
| 144 |
busy = false; |
| 139 |
} |
145 |
} |
| 140 |
} |
146 |
} |
| 141 |
|
147 |
|
|
Lines 334-340
Link Here
|
| 334 |
int index; |
340 |
int index; |
| 335 |
if (comparator == null) { |
341 |
if (comparator == null) { |
| 336 |
if (itemExists(items, element)) { |
342 |
if (itemExists(items, element)) { |
| 337 |
refresh(element); |
343 |
internalRefresh(element); |
| 338 |
newItem = false; |
344 |
newItem = false; |
| 339 |
} |
345 |
} |
| 340 |
index = -1; |
346 |
index = -1; |
|
Lines 355-361
Link Here
|
| 355 |
// any) |
361 |
// any) |
| 356 |
if (items[lastInsertion].getData().equals(element)) { |
362 |
if (items[lastInsertion].getData().equals(element)) { |
| 357 |
// refresh the element in case it has new children |
363 |
// refresh the element in case it has new children |
| 358 |
refresh(element); |
364 |
internalRefresh(element); |
| 359 |
newItem = false; |
365 |
newItem = false; |
| 360 |
} |
366 |
} |
| 361 |
lastInsertion++;// We had an insertion so increment |
367 |
lastInsertion++;// We had an insertion so increment |
|
Lines 994-1002
Link Here
|
| 994 |
* levels of the tree |
1000 |
* levels of the tree |
| 995 |
*/ |
1001 |
*/ |
| 996 |
public void expandToLevel(Object elementOrTreePath, int level) { |
1002 |
public void expandToLevel(Object elementOrTreePath, int level) { |
| 997 |
Widget w = internalExpand(elementOrTreePath, true); |
1003 |
if (isBusy()) |
| 998 |
if (w != null) { |
1004 |
return; |
| 999 |
internalExpandToLevel(w, level); |
1005 |
busy = true; |
|
|
1006 |
try { |
| 1007 |
Widget w = internalExpand(elementOrTreePath, true); |
| 1008 |
if (w != null) { |
| 1009 |
internalExpandToLevel(w, level); |
| 1010 |
} |
| 1011 |
} finally { |
| 1012 |
busy = false; |
| 1000 |
} |
1013 |
} |
| 1001 |
} |
1014 |
} |
| 1002 |
|
1015 |
|
|
Lines 2047-2057
Link Here
|
| 2047 |
if (elementsOrTreePaths.length == 0) { |
2060 |
if (elementsOrTreePaths.length == 0) { |
| 2048 |
return; |
2061 |
return; |
| 2049 |
} |
2062 |
} |
| 2050 |
preservingSelection(new Runnable() { |
2063 |
if (isBusy()) |
| 2051 |
public void run() { |
2064 |
return; |
| 2052 |
internalRemove(elementsOrTreePaths); |
2065 |
busy = true; |
| 2053 |
} |
2066 |
try { |
| 2054 |
}); |
2067 |
preservingSelection(new Runnable() { |
|
|
2068 |
public void run() { |
| 2069 |
internalRemove(elementsOrTreePaths); |
| 2070 |
} |
| 2071 |
}); |
| 2072 |
} finally { |
| 2073 |
busy = false; |
| 2074 |
} |
| 2055 |
} |
2075 |
} |
| 2056 |
|
2076 |
|
| 2057 |
/** |
2077 |
/** |
|
Lines 2077-2087
Link Here
|
| 2077 |
if (elements.length == 0) { |
2097 |
if (elements.length == 0) { |
| 2078 |
return; |
2098 |
return; |
| 2079 |
} |
2099 |
} |
| 2080 |
preservingSelection(new Runnable() { |
2100 |
if (isBusy()) |
| 2081 |
public void run() { |
2101 |
return; |
| 2082 |
internalRemove(parent, elements); |
2102 |
busy = true; |
| 2083 |
} |
2103 |
try { |
| 2084 |
}); |
2104 |
preservingSelection(new Runnable() { |
|
|
2105 |
public void run() { |
| 2106 |
internalRemove(parent, elements); |
| 2107 |
} |
| 2108 |
}); |
| 2109 |
} finally { |
| 2110 |
busy = false; |
| 2111 |
} |
| 2085 |
} |
2112 |
} |
| 2086 |
|
2113 |
|
| 2087 |
/** |
2114 |
/** |
|
Lines 2229-2249
Link Here
|
| 2229 |
*/ |
2256 |
*/ |
| 2230 |
public void setExpandedElements(Object[] elements) { |
2257 |
public void setExpandedElements(Object[] elements) { |
| 2231 |
assertElementsNotNull(elements); |
2258 |
assertElementsNotNull(elements); |
| 2232 |
CustomHashtable expandedElements = newHashtable(elements.length * 2 + 1); |
2259 |
if (isBusy()) { |
| 2233 |
for (int i = 0; i < elements.length; ++i) { |
2260 |
return; |
| 2234 |
Object element = elements[i]; |
2261 |
} |
| 2235 |
// Ensure item exists for element. This will materialize items for |
2262 |
busy = true; |
| 2236 |
// each element and their parents, if possible. This is important |
2263 |
try { |
| 2237 |
// to support expanding of inner tree nodes without necessarily |
2264 |
CustomHashtable expandedElements = newHashtable(elements.length * 2 + 1); |
| 2238 |
// expanding their parents. |
2265 |
for (int i = 0; i < elements.length; ++i) { |
| 2239 |
internalExpand(element, false); |
2266 |
Object element = elements[i]; |
| 2240 |
expandedElements.put(element, element); |
2267 |
// Ensure item exists for element. This will materialize items for |
| 2241 |
} |
2268 |
// each element and their parents, if possible. This is important |
| 2242 |
// this will traverse all existing items, and create children for |
2269 |
// to support expanding of inner tree nodes without necessarily |
| 2243 |
// elements that need to be expanded. If the tree contains multiple |
2270 |
// expanding their parents. |
| 2244 |
// equal elements, and those are in the set of elements to be expanded, |
2271 |
internalExpand(element, false); |
| 2245 |
// only the first item found for each element will be expanded. |
2272 |
expandedElements.put(element, element); |
| 2246 |
internalSetExpanded(expandedElements, getControl()); |
2273 |
} |
|
|
2274 |
// this will traverse all existing items, and create children for |
| 2275 |
// elements that need to be expanded. If the tree contains multiple |
| 2276 |
// equal elements, and those are in the set of elements to be expanded, |
| 2277 |
// only the first item found for each element will be expanded. |
| 2278 |
internalSetExpanded(expandedElements, getControl()); |
| 2279 |
} finally { |
| 2280 |
busy = false; |
| 2281 |
} |
| 2247 |
} |
2282 |
} |
| 2248 |
|
2283 |
|
| 2249 |
/** |
2284 |
/** |
|
Lines 2263-2296
Link Here
|
| 2263 |
*/ |
2298 |
*/ |
| 2264 |
public void setExpandedTreePaths(TreePath[] treePaths) { |
2299 |
public void setExpandedTreePaths(TreePath[] treePaths) { |
| 2265 |
assertElementsNotNull(treePaths); |
2300 |
assertElementsNotNull(treePaths); |
| 2266 |
final IElementComparer comparer = getComparer(); |
2301 |
if (isBusy()) |
| 2267 |
IElementComparer treePathComparer = new IElementComparer() { |
2302 |
return; |
| 2268 |
|
2303 |
busy = true; |
| 2269 |
public boolean equals(Object a, Object b) { |
2304 |
try { |
| 2270 |
return ((TreePath) a).equals(((TreePath) b), comparer); |
2305 |
final IElementComparer comparer = getComparer(); |
| 2271 |
} |
2306 |
IElementComparer treePathComparer = new IElementComparer() { |
| 2272 |
|
2307 |
|
| 2273 |
public int hashCode(Object element) { |
2308 |
public boolean equals(Object a, Object b) { |
| 2274 |
return ((TreePath) element).hashCode(comparer); |
2309 |
return ((TreePath) a).equals(((TreePath) b), comparer); |
| 2275 |
} |
2310 |
} |
| 2276 |
}; |
2311 |
|
| 2277 |
CustomHashtable expandedTreePaths = new CustomHashtable( |
2312 |
public int hashCode(Object element) { |
| 2278 |
treePaths.length * 2 + 1, treePathComparer); |
2313 |
return ((TreePath) element).hashCode(comparer); |
| 2279 |
for (int i = 0; i < treePaths.length; ++i) { |
2314 |
} |
| 2280 |
TreePath treePath = treePaths[i]; |
2315 |
}; |
| 2281 |
// Ensure item exists for element. This will materialize items for |
2316 |
CustomHashtable expandedTreePaths = new CustomHashtable( |
| 2282 |
// each element and their parents, if possible. This is important |
2317 |
treePaths.length * 2 + 1, treePathComparer); |
| 2283 |
// to support expanding of inner tree nodes without necessarily |
2318 |
for (int i = 0; i < treePaths.length; ++i) { |
| 2284 |
// expanding their parents. |
2319 |
TreePath treePath = treePaths[i]; |
| 2285 |
internalExpand(treePath, false); |
2320 |
// Ensure item exists for element. This will materialize items for |
| 2286 |
expandedTreePaths.put(treePath, treePath); |
2321 |
// each element and their parents, if possible. This is important |
| 2287 |
} |
2322 |
// to support expanding of inner tree nodes without necessarily |
| 2288 |
// this will traverse all existing items, and create children for |
2323 |
// expanding their parents. |
| 2289 |
// elements that need to be expanded. If the tree contains multiple |
2324 |
internalExpand(treePath, false); |
| 2290 |
// equal elements, and those are in the set of elements to be expanded, |
2325 |
expandedTreePaths.put(treePath, treePath); |
| 2291 |
// only the first item found for each element will be expanded. |
2326 |
} |
| 2292 |
internalSetExpandedTreePaths(expandedTreePaths, getControl(), |
2327 |
// this will traverse all existing items, and create children for |
| 2293 |
new TreePath(new Object[0])); |
2328 |
// elements that need to be expanded. If the tree contains multiple |
|
|
2329 |
// equal elements, and those are in the set of elements to be expanded, |
| 2330 |
// only the first item found for each element will be expanded. |
| 2331 |
internalSetExpandedTreePaths(expandedTreePaths, getControl(), |
| 2332 |
new TreePath(new Object[0])); |
| 2333 |
} finally { |
| 2334 |
busy = false; |
| 2335 |
} |
| 2294 |
} |
2336 |
} |
| 2295 |
|
2337 |
|
| 2296 |
/** |
2338 |
/** |
|
Lines 2305-2316
Link Here
|
| 2305 |
*/ |
2347 |
*/ |
| 2306 |
public void setExpandedState(Object elementOrTreePath, boolean expanded) { |
2348 |
public void setExpandedState(Object elementOrTreePath, boolean expanded) { |
| 2307 |
Assert.isNotNull(elementOrTreePath); |
2349 |
Assert.isNotNull(elementOrTreePath); |
| 2308 |
Widget item = internalExpand(elementOrTreePath, false); |
2350 |
if (isBusy()) |
| 2309 |
if (item instanceof Item) { |
2351 |
return; |
| 2310 |
if (expanded) { |
2352 |
busy = true; |
| 2311 |
createChildren(item); |
2353 |
try { |
|
|
2354 |
Widget item = internalExpand(elementOrTreePath, false); |
| 2355 |
if (item instanceof Item) { |
| 2356 |
if (expanded) { |
| 2357 |
createChildren(item); |
| 2358 |
} |
| 2359 |
setExpanded((Item) item, expanded); |
| 2312 |
} |
2360 |
} |
| 2313 |
setExpanded((Item) item, expanded); |
2361 |
} finally { |
|
|
2362 |
busy = false; |
| 2314 |
} |
2363 |
} |
| 2315 |
} |
2364 |
} |
| 2316 |
|
2365 |
|
|
Lines 2789-2830
Link Here
|
| 2789 |
int position) { |
2838 |
int position) { |
| 2790 |
Assert.isNotNull(parentElementOrTreePath); |
2839 |
Assert.isNotNull(parentElementOrTreePath); |
| 2791 |
Assert.isNotNull(element); |
2840 |
Assert.isNotNull(element); |
| 2792 |
|
2841 |
if (isBusy()) |
| 2793 |
if (getComparator() != null || hasFilters()) { |
|
|
| 2794 |
add(parentElementOrTreePath, new Object[] { element }); |
| 2795 |
return; |
2842 |
return; |
| 2796 |
} |
2843 |
busy = true; |
| 2797 |
Widget[] items; |
2844 |
try { |
| 2798 |
if (internalIsInputOrEmptyPath(parentElementOrTreePath)) { |
2845 |
if (getComparator() != null || hasFilters()) { |
| 2799 |
items = new Widget[] { getControl() }; |
2846 |
add(parentElementOrTreePath, new Object[] { element }); |
| 2800 |
} else { |
2847 |
return; |
| 2801 |
items = internalFindItems(parentElementOrTreePath); |
2848 |
} |
| 2802 |
} |
2849 |
Widget[] items; |
| 2803 |
|
2850 |
if (internalIsInputOrEmptyPath(parentElementOrTreePath)) { |
| 2804 |
for (int i = 0; i < items.length; i++) { |
2851 |
items = new Widget[] { getControl() }; |
| 2805 |
Widget widget = items[i]; |
2852 |
} else { |
| 2806 |
if (widget instanceof Item) { |
2853 |
items = internalFindItems(parentElementOrTreePath); |
| 2807 |
Item item = (Item) widget; |
2854 |
} |
| 2808 |
|
2855 |
|
| 2809 |
Item[] childItems = getChildren(item); |
2856 |
for (int i = 0; i < items.length; i++) { |
| 2810 |
if (getExpanded(item) |
2857 |
Widget widget = items[i]; |
| 2811 |
|| (childItems.length > 0 && childItems[0].getData() != null)) { |
2858 |
if (widget instanceof Item) { |
| 2812 |
// item has real children, go ahead and add |
2859 |
Item item = (Item) widget; |
|
|
2860 |
|
| 2861 |
Item[] childItems = getChildren(item); |
| 2862 |
if (getExpanded(item) |
| 2863 |
|| (childItems.length > 0 && childItems[0].getData() != null)) { |
| 2864 |
// item has real children, go ahead and add |
| 2865 |
int insertionPosition = position; |
| 2866 |
if (insertionPosition == -1) { |
| 2867 |
insertionPosition = getItemCount(item); |
| 2868 |
} |
| 2869 |
|
| 2870 |
createTreeItem(item, element, insertionPosition); |
| 2871 |
} |
| 2872 |
} else { |
| 2813 |
int insertionPosition = position; |
2873 |
int insertionPosition = position; |
| 2814 |
if (insertionPosition == -1) { |
2874 |
if (insertionPosition == -1) { |
| 2815 |
insertionPosition = getItemCount(item); |
2875 |
insertionPosition = getItemCount((Control) widget); |
| 2816 |
} |
2876 |
} |
| 2817 |
|
2877 |
|
| 2818 |
createTreeItem(item, element, insertionPosition); |
2878 |
createTreeItem(widget, element, insertionPosition); |
| 2819 |
} |
|
|
| 2820 |
} else { |
| 2821 |
int insertionPosition = position; |
| 2822 |
if (insertionPosition == -1) { |
| 2823 |
insertionPosition = getItemCount((Control) widget); |
| 2824 |
} |
2879 |
} |
| 2825 |
|
|
|
| 2826 |
createTreeItem(widget, element, insertionPosition); |
| 2827 |
} |
2880 |
} |
|
|
2881 |
} finally { |
| 2882 |
busy = false; |
| 2828 |
} |
2883 |
} |
| 2829 |
} |
2884 |
} |
| 2830 |
|
2885 |
|