Skip to content

Commit

Permalink
Performance improvement and setRedraw() changes for expandable node.
Browse files Browse the repository at this point in the history
  • Loading branch information
raghucssit authored and iloveeclipse committed Aug 15, 2023
1 parent 6a83787 commit dca05b9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,32 +468,43 @@ void handleExpandableNodeClicked(Widget w) {
if (!(data instanceof ExpandableNode expNode)) {
return;
}

Object[] sortedChildren = expNode.getRemainingElements();
Object[] nextChildren = applyItemsLimit(data, sortedChildren);
disassociate(item);
int index = doIndexOf(item);
// will also call item.dispose()
doRemove(new int[] { index });

if (nextChildren.length > 0) {
// create remaining elements
for (Object nextChild : nextChildren) {
createItem(nextChild, -1);
}
// If we've expanded but still have not reached the limit
// select new expandable node, so user can click through
// to the end
if (getLastElement() instanceof ExpandableNode node) {
setSelection(new StructuredSelection(node), true);
} else {
// reset the selection. client's selection listener should not be triggered.
// there was only one selection on Expandable Node.
int[] curSel = this.getTable().getSelectionIndices();
if (curSel.length == 1) {
this.getTable().deselect(curSel[0]);
boolean oldBusy = isBusy();
Table table = getTable();
try {
setBusy(true);
table.setRedraw(false);

Object[] sortedChildren = expNode.getRemainingElements();
Object[] nextChildren = applyItemsLimit(data, sortedChildren);

if (nextChildren.length > 0) {
// update the expandable node with first item.
doUpdateItem(item, nextChildren[0], true);
// create remaining elements
if (nextChildren.length > 1) {
// current index is updated so start creating from next index.
int index = doIndexOf(item) + 1;
for (int i = 1; i < nextChildren.length; i++) {
createItem(nextChildren[i], index++);
}
}
// If we've expanded but still have not reached the limit
// select new expandable node, so user can click through
// to the end
if (getLastElement() instanceof ExpandableNode node) {
setSelection(new StructuredSelection(node), true);
} else {
// reset the selection. client's selection listener should not be triggered.
// there was only one selection on Expandable Node.
int[] curSel = table.getSelectionIndices();
if (curSel.length == 1) {
table.deselect(curSel[0]);
}
}
}
} finally {
setBusy(oldBusy);
table.setRedraw(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,20 +1148,28 @@ void handleExpandableNodeClicked(Widget w) {
return;
}

Widget parent = getParentItem(item);
if (parent == null) {
parent = getControl();
}
// destroy widget
disassociate(item);
item.dispose();
boolean oldBusy = isBusy();
Tree tree = getTree();
try {
setBusy(true);
tree.setRedraw(false);

// create children on parent
for (Object element : children) {
createTreeItem(parent, element, -1);
}
Widget parent = getParentItem(item);
if (parent == null) {
parent = getControl();
}

// update widget
updateItem(item, children[0]);
updatePlus(item, children[0]);

if (children.length > 1) {
// create children on parent
for (int i = 1; i < children.length; i++) {
createTreeItem(parent, children[i], -1);
}
}

if (children.length > 0) {
// If we've expanded but still have not reached the limit
// select new expandable node, so user can click through
// to the end
Expand All @@ -1171,11 +1179,14 @@ void handleExpandableNodeClicked(Widget w) {
} else {
// reset the selection. client's selection listener should not be triggered.
// there was only one selection on Expandable Node.
Item[] curSel = this.getTree().getSelection();
Item[] curSel = tree.getSelection();
if (curSel.length == 1) {
this.getTree().deselect((TreeItem) curSel[0]);
tree.deselect((TreeItem) curSel[0]);
}
}
} finally {
tree.setRedraw(true);
setBusy(oldBusy);
}
}

Expand Down

0 comments on commit dca05b9

Please sign in to comment.