Skip to content

Commit

Permalink
Support increase/decrease of ColumnViewer#setDisplayIncrementally(int
Browse files Browse the repository at this point in the history
incrementSize)

Refresh the viewer when the viewer limit is set based on different
conditions.
Adapt WorkbenchViewerSetup to consume above change.

Fixes eclipse-platform#1093
  • Loading branch information
raghucssit committed Oct 4, 2023
1 parent 0847f8e commit febdbea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public abstract class ColumnViewer extends StructuredViewer {

private Set<ExpandableNode> expandableNodes;

private boolean limitChanged = false;

// after logging for the first
// time

Expand Down Expand Up @@ -912,17 +914,31 @@ void handleExpandableNodeClicked(Widget cell) {
Object[] getChildrenWithLimitApplied(final Object parent, Item[] visibleChildren) {
final int limit = getItemsLimit();
final int visibleItemsLength = visibleChildren.length;
if (visibleItemsLength < limit || limit <= 0) {

if (visibleItemsLength == 0) {
return null;
}

int modelItemsLenght = visibleItemsLength;
// exclude expandable place holder.
if (visibleChildren[visibleItemsLength - 1].getData() instanceof ExpandableNode) {
modelItemsLenght = visibleItemsLength - 1;
}

if (modelItemsLenght <= limit || limit <= 0 || limitChanged) {
return null;
}

// fetch entire sorted children we need them in any of next cases.
boolean oldBusy = isBusy();
setBusy(true);
setDisplayIncrementally(0);
Object[] sortedAll;
try {
sortedAll = getSortedChildren(parent);
} finally {
setDisplayIncrementally(limit);
setBusy(oldBusy);
}

// model has lost some elements and length is less then visible items.
Expand Down Expand Up @@ -1006,7 +1022,39 @@ int getItemsLimit() {
* @since 3.31
*/
public void setDisplayIncrementally(int incrementSize) {
if (incrementSize == itemsLimit) {
return;
}

int oldLimit = itemsLimit;
itemsLimit = incrementSize;

if (isBusy()) {
return;
}

// limit has been reset.
if (incrementSize <= 0) {
internalRefresh(getRoot());
return;
}

// viewer limit has decreased/increased than before. we will shrink/expand to
// new limit
// doesn't matter how much user has expanded before.
if (incrementSize < oldLimit || (oldLimit > 0 && incrementSize > oldLimit)) {
limitChanged = true;
try {
internalRefresh(getRoot());
} finally {
limitChanged = false;
}
return;
}

// in any case just refresh the viewer
internalRefresh(getRoot());

}

ExpandableNode createExpandableNode(Object[] result, int startOffSet, int limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public void propertyChange(PropertyChangeEvent event) {
int itemsLimit = getItemsLimit();
registeredViewers.values().forEach(v -> {
v.setDisplayIncrementally(itemsLimit);
Object input = v.getInput();
if (input != null) {
v.setInput(null);
v.setInput(input);
} else {
v.refresh();
}
});
}
};
Expand Down

0 comments on commit febdbea

Please sign in to comment.