|
Lines 127-133
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 |
return; |
| 131 |
Widget[] widgets = internalFindItems(parentElementOrTreePath); |
132 |
Widget[] widgets = internalFindItems(parentElementOrTreePath); |
| 132 |
// If parent hasn't been realized yet, just ignore the add. |
133 |
// If parent hasn't been realized yet, just ignore the add. |
| 133 |
if (widgets.length == 0) { |
134 |
if (widgets.length == 0) { |
|
Lines 334-340
Link Here
|
| 334 |
int index; |
335 |
int index; |
| 335 |
if (comparator == null) { |
336 |
if (comparator == null) { |
| 336 |
if (itemExists(items, element)) { |
337 |
if (itemExists(items, element)) { |
| 337 |
refresh(element); |
338 |
internalRefresh(element); |
| 338 |
newItem = false; |
339 |
newItem = false; |
| 339 |
} |
340 |
} |
| 340 |
index = -1; |
341 |
index = -1; |
|
Lines 355-361
Link Here
|
| 355 |
// any) |
356 |
// any) |
| 356 |
if (items[lastInsertion].getData().equals(element)) { |
357 |
if (items[lastInsertion].getData().equals(element)) { |
| 357 |
// refresh the element in case it has new children |
358 |
// refresh the element in case it has new children |
| 358 |
refresh(element); |
359 |
internalRefresh(element); |
| 359 |
newItem = false; |
360 |
newItem = false; |
| 360 |
} |
361 |
} |
| 361 |
lastInsertion++;// We had an insertion so increment |
362 |
lastInsertion++;// We had an insertion so increment |
|
Lines 740-785
Link Here
|
| 740 |
* the widget |
741 |
* the widget |
| 741 |
*/ |
742 |
*/ |
| 742 |
protected void createChildren(final Widget widget) { |
743 |
protected void createChildren(final Widget widget) { |
| 743 |
final Item[] tis = getChildren(widget); |
744 |
boolean oldBusy = busy; |
| 744 |
if (tis != null && tis.length > 0) { |
745 |
busy = true; |
| 745 |
Object data = tis[0].getData(); |
746 |
try { |
| 746 |
if (data != null) { |
747 |
final Item[] tis = getChildren(widget); |
| 747 |
return; // children already there! |
748 |
if (tis != null && tis.length > 0) { |
|
|
749 |
Object data = tis[0].getData(); |
| 750 |
if (data != null) { |
| 751 |
return; // children already there! |
| 752 |
} |
| 748 |
} |
753 |
} |
| 749 |
} |
754 |
|
| 750 |
|
755 |
BusyIndicator.showWhile(widget.getDisplay(), new Runnable() { |
| 751 |
BusyIndicator.showWhile(widget.getDisplay(), new Runnable() { |
756 |
public void run() { |
| 752 |
public void run() { |
757 |
// fix for PR 1FW89L7: |
| 753 |
// fix for PR 1FW89L7: |
758 |
// don't complain and remove all "dummies" ... |
| 754 |
// don't complain and remove all "dummies" ... |
759 |
if (tis != null) { |
| 755 |
if (tis != null) { |
760 |
for (int i = 0; i < tis.length; i++) { |
| 756 |
for (int i = 0; i < tis.length; i++) { |
761 |
if (tis[i].getData() != null) { |
| 757 |
if (tis[i].getData() != null) { |
762 |
disassociate(tis[i]); |
| 758 |
disassociate(tis[i]); |
763 |
Assert.isTrue(tis[i].getData() == null, |
| 759 |
Assert.isTrue(tis[i].getData() == null, |
764 |
"Second or later child is non -null");//$NON-NLS-1$ |
| 760 |
"Second or later child is non -null");//$NON-NLS-1$ |
765 |
|
| 761 |
|
766 |
} |
|
|
767 |
tis[i].dispose(); |
| 762 |
} |
768 |
} |
| 763 |
tis[i].dispose(); |
|
|
| 764 |
} |
769 |
} |
| 765 |
} |
770 |
Object d = widget.getData(); |
| 766 |
Object d = widget.getData(); |
771 |
if (d != null) { |
| 767 |
if (d != null) { |
772 |
Object parentElement = d; |
| 768 |
Object parentElement = d; |
773 |
Object[] children; |
| 769 |
Object[] children; |
774 |
if (isTreePathContentProvider() && widget instanceof Item) { |
| 770 |
if (isTreePathContentProvider() && widget instanceof Item) { |
775 |
TreePath path = getTreePathFromItem((Item) widget); |
| 771 |
TreePath path = getTreePathFromItem((Item) widget); |
776 |
children = getSortedChildren(path); |
| 772 |
children = getSortedChildren(path); |
777 |
} else { |
| 773 |
} else { |
778 |
children = getSortedChildren(parentElement); |
| 774 |
children = getSortedChildren(parentElement); |
779 |
} |
| 775 |
} |
780 |
for (int i = 0; i < children.length; i++) { |
| 776 |
for (int i = 0; i < children.length; i++) { |
781 |
createTreeItem(widget, children[i], -1); |
| 777 |
createTreeItem(widget, children[i], -1); |
782 |
} |
| 778 |
} |
783 |
} |
| 779 |
} |
784 |
} |
| 780 |
} |
785 |
|
| 781 |
|
786 |
}); |
| 782 |
}); |
787 |
} finally { |
|
|
788 |
busy = oldBusy; |
| 789 |
} |
| 783 |
} |
790 |
} |
| 784 |
|
791 |
|
| 785 |
/** |
792 |
/** |
|
Lines 944-966
Link Here
|
| 944 |
|
951 |
|
| 945 |
/* (non-Javadoc) Method declared on StructuredViewer. */ |
952 |
/* (non-Javadoc) Method declared on StructuredViewer. */ |
| 946 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
953 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
| 947 |
if (widget instanceof Item) { |
954 |
boolean oldBusy = busy; |
| 948 |
Item item = (Item) widget; |
955 |
busy = true; |
| 949 |
|
956 |
try { |
| 950 |
// ensure that back pointer is correct |
957 |
if (widget instanceof Item) { |
| 951 |
if (fullMap) { |
958 |
Item item = (Item) widget; |
| 952 |
associate(element, item); |
959 |
|
| 953 |
} else { |
960 |
// ensure that back pointer is correct |
| 954 |
Object data = item.getData(); |
961 |
if (fullMap) { |
| 955 |
if (data != null) { |
962 |
associate(element, item); |
| 956 |
unmapElement(data, item); |
963 |
} else { |
|
|
964 |
Object data = item.getData(); |
| 965 |
if (data != null) { |
| 966 |
unmapElement(data, item); |
| 967 |
} |
| 968 |
item.setData(element); |
| 969 |
mapElement(element, item); |
| 957 |
} |
970 |
} |
| 958 |
item.setData(element); |
971 |
|
| 959 |
mapElement(element, item); |
972 |
// update icon and label |
|
|
973 |
SafeRunnable.run(new UpdateItemSafeRunnable(item, element)); |
| 960 |
} |
974 |
} |
| 961 |
|
975 |
} finally { |
| 962 |
// update icon and label |
976 |
busy = oldBusy; |
| 963 |
SafeRunnable.run(new UpdateItemSafeRunnable(item, element)); |
|
|
| 964 |
} |
977 |
} |
| 965 |
} |
978 |
} |
| 966 |
|
979 |
|
|
Lines 995-1000
Link Here
|
| 995 |
* levels of the tree |
1008 |
* levels of the tree |
| 996 |
*/ |
1009 |
*/ |
| 997 |
public void expandToLevel(Object elementOrTreePath, int level) { |
1010 |
public void expandToLevel(Object elementOrTreePath, int level) { |
|
|
1011 |
if (isBusy()) |
| 1012 |
return; |
| 998 |
Widget w = internalExpand(elementOrTreePath, true); |
1013 |
Widget w = internalExpand(elementOrTreePath, true); |
| 999 |
if (w != null) { |
1014 |
if (w != null) { |
| 1000 |
internalExpandToLevel(w, level); |
1015 |
internalExpandToLevel(w, level); |
|
Lines 1248-1293
Link Here
|
| 1248 |
|
1263 |
|
| 1249 |
/* (non-Javadoc) Method declared on StructuredViewer. */ |
1264 |
/* (non-Javadoc) Method declared on StructuredViewer. */ |
| 1250 |
protected Object[] getRawChildren(Object parentElementOrTreePath) { |
1265 |
protected Object[] getRawChildren(Object parentElementOrTreePath) { |
| 1251 |
Object parent; |
1266 |
boolean oldBusy = busy; |
| 1252 |
TreePath path; |
1267 |
busy = true; |
| 1253 |
if (parentElementOrTreePath instanceof TreePath) { |
1268 |
try { |
| 1254 |
path = (TreePath) parentElementOrTreePath; |
1269 |
Object parent; |
| 1255 |
parent = path.getLastSegment(); |
1270 |
TreePath path; |
| 1256 |
} else { |
1271 |
if (parentElementOrTreePath instanceof TreePath) { |
| 1257 |
parent = parentElementOrTreePath; |
1272 |
path = (TreePath) parentElementOrTreePath; |
| 1258 |
path = null; |
1273 |
parent = path.getLastSegment(); |
| 1259 |
} |
1274 |
} else { |
| 1260 |
if (parent != null) { |
1275 |
parent = parentElementOrTreePath; |
| 1261 |
if (equals(parent, getRoot())) { |
1276 |
path = null; |
| 1262 |
return super.getRawChildren(parent); |
1277 |
} |
| 1263 |
} |
1278 |
if (parent != null) { |
| 1264 |
IContentProvider cp = getContentProvider(); |
1279 |
if (equals(parent, getRoot())) { |
| 1265 |
if (cp instanceof ITreePathContentProvider) { |
1280 |
return super.getRawChildren(parent); |
| 1266 |
ITreePathContentProvider tpcp = (ITreePathContentProvider) cp; |
1281 |
} |
| 1267 |
if (path == null) { |
1282 |
IContentProvider cp = getContentProvider(); |
| 1268 |
// A path was not provided so try and find one |
1283 |
if (cp instanceof ITreePathContentProvider) { |
| 1269 |
Widget w = findItem(parent); |
1284 |
ITreePathContentProvider tpcp = (ITreePathContentProvider) cp; |
| 1270 |
if (w instanceof Item) { |
|
|
| 1271 |
Item item = (Item) w; |
| 1272 |
path = getTreePathFromItem(item); |
| 1273 |
} |
| 1274 |
if (path == null) { |
1285 |
if (path == null) { |
| 1275 |
path = new TreePath(new Object[] { parent }); |
1286 |
// A path was not provided so try and find one |
|
|
1287 |
Widget w = findItem(parent); |
| 1288 |
if (w instanceof Item) { |
| 1289 |
Item item = (Item) w; |
| 1290 |
path = getTreePathFromItem(item); |
| 1291 |
} |
| 1292 |
if (path == null) { |
| 1293 |
path = new TreePath(new Object[] { parent }); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
Object[] result = tpcp.getChildren(path); |
| 1297 |
if (result != null) { |
| 1298 |
return result; |
| 1299 |
} |
| 1300 |
} else if (cp instanceof ITreeContentProvider) { |
| 1301 |
ITreeContentProvider tcp = (ITreeContentProvider) cp; |
| 1302 |
Object[] result = tcp.getChildren(parent); |
| 1303 |
if (result != null) { |
| 1304 |
return result; |
| 1276 |
} |
1305 |
} |
| 1277 |
} |
|
|
| 1278 |
Object[] result = tpcp.getChildren(path); |
| 1279 |
if (result != null) { |
| 1280 |
return result; |
| 1281 |
} |
| 1282 |
} else if (cp instanceof ITreeContentProvider) { |
| 1283 |
ITreeContentProvider tcp = (ITreeContentProvider) cp; |
| 1284 |
Object[] result = tcp.getChildren(parent); |
| 1285 |
if (result != null) { |
| 1286 |
return result; |
| 1287 |
} |
1306 |
} |
| 1288 |
} |
1307 |
} |
|
|
1308 |
return new Object[0]; |
| 1309 |
} finally { |
| 1310 |
busy = oldBusy; |
| 1289 |
} |
1311 |
} |
| 1290 |
return new Object[0]; |
|
|
| 1291 |
} |
1312 |
} |
| 1292 |
|
1313 |
|
| 1293 |
/** |
1314 |
/** |
|
Lines 2045-2050
Link Here
|
| 2045 |
if (elementsOrTreePaths.length == 0) { |
2066 |
if (elementsOrTreePaths.length == 0) { |
| 2046 |
return; |
2067 |
return; |
| 2047 |
} |
2068 |
} |
|
|
2069 |
if (isBusy()) |
| 2070 |
return; |
| 2048 |
preservingSelection(new Runnable() { |
2071 |
preservingSelection(new Runnable() { |
| 2049 |
public void run() { |
2072 |
public void run() { |
| 2050 |
internalRemove(elementsOrTreePaths); |
2073 |
internalRemove(elementsOrTreePaths); |
|
Lines 2075-2080
Link Here
|
| 2075 |
if (elements.length == 0) { |
2098 |
if (elements.length == 0) { |
| 2076 |
return; |
2099 |
return; |
| 2077 |
} |
2100 |
} |
|
|
2101 |
if (isBusy()) |
| 2102 |
return; |
| 2078 |
preservingSelection(new Runnable() { |
2103 |
preservingSelection(new Runnable() { |
| 2079 |
public void run() { |
2104 |
public void run() { |
| 2080 |
internalRemove(parent, elements); |
2105 |
internalRemove(parent, elements); |
|
Lines 2227-2232
Link Here
|
| 2227 |
*/ |
2252 |
*/ |
| 2228 |
public void setExpandedElements(Object[] elements) { |
2253 |
public void setExpandedElements(Object[] elements) { |
| 2229 |
assertElementsNotNull(elements); |
2254 |
assertElementsNotNull(elements); |
|
|
2255 |
if (isBusy()) { |
| 2256 |
return; |
| 2257 |
} |
| 2230 |
CustomHashtable expandedElements = newHashtable(elements.length * 2 + 1); |
2258 |
CustomHashtable expandedElements = newHashtable(elements.length * 2 + 1); |
| 2231 |
for (int i = 0; i < elements.length; ++i) { |
2259 |
for (int i = 0; i < elements.length; ++i) { |
| 2232 |
Object element = elements[i]; |
2260 |
Object element = elements[i]; |
|
Lines 2261-2266
Link Here
|
| 2261 |
*/ |
2289 |
*/ |
| 2262 |
public void setExpandedTreePaths(TreePath[] treePaths) { |
2290 |
public void setExpandedTreePaths(TreePath[] treePaths) { |
| 2263 |
assertElementsNotNull(treePaths); |
2291 |
assertElementsNotNull(treePaths); |
|
|
2292 |
if (isBusy()) |
| 2293 |
return; |
| 2264 |
final IElementComparer comparer = getComparer(); |
2294 |
final IElementComparer comparer = getComparer(); |
| 2265 |
IElementComparer treePathComparer = new IElementComparer() { |
2295 |
IElementComparer treePathComparer = new IElementComparer() { |
| 2266 |
|
2296 |
|
|
Lines 2303-2308
Link Here
|
| 2303 |
*/ |
2333 |
*/ |
| 2304 |
public void setExpandedState(Object elementOrTreePath, boolean expanded) { |
2334 |
public void setExpandedState(Object elementOrTreePath, boolean expanded) { |
| 2305 |
Assert.isNotNull(elementOrTreePath); |
2335 |
Assert.isNotNull(elementOrTreePath); |
|
|
2336 |
if (isBusy()) |
| 2337 |
return; |
| 2306 |
Widget item = internalExpand(elementOrTreePath, false); |
2338 |
Widget item = internalExpand(elementOrTreePath, false); |
| 2307 |
if (item instanceof Item) { |
2339 |
if (item instanceof Item) { |
| 2308 |
if (expanded) { |
2340 |
if (expanded) { |
|
Lines 2787-2793
Link Here
|
| 2787 |
int position) { |
2819 |
int position) { |
| 2788 |
Assert.isNotNull(parentElementOrTreePath); |
2820 |
Assert.isNotNull(parentElementOrTreePath); |
| 2789 |
Assert.isNotNull(element); |
2821 |
Assert.isNotNull(element); |
| 2790 |
|
2822 |
if (isBusy()) |
|
|
2823 |
return; |
| 2791 |
if (getComparator() != null || hasFilters()) { |
2824 |
if (getComparator() != null || hasFilters()) { |
| 2792 |
add(parentElementOrTreePath, new Object[] { element }); |
2825 |
add(parentElementOrTreePath, new Object[] { element }); |
| 2793 |
return; |
2826 |
return; |