@Override
public void elementsChanged(final Object[] updatedElements) {
if (getSearchResult() == null) {
return;
}
final TreeViewer viewer = getViewer();
final int elementLimit = getElementLimit();
final boolean treeLimited = elementLimit != -1;
final int n = updatedElements.length;
final List<Object> toRemove = new ArrayList<Object>(n);
final List<Object> toAdd = new ArrayList<Object>(n);
final List<Object> toUpdate = new ArrayList<Object>(n);
for (final Object element : updatedElements) {
if (fResult.getMatchCount(element) > 0) {
if (viewer.testFindItem(element) != null) {
toUpdate.add(element);
} else {
if (!treeLimited || viewer.getTree().getItemCount() < elementLimit) {
toAdd.add(element);
}
}
} else {
toRemove.add(element);
}
}
for (final Object element : toRemove) {
removeElement((ErlangSearchElement) element);
}
for (final Object element : toAdd) {
addElement((ErlangSearchElement) element);
}
viewer.update(toUpdate.toArray(), null);
viewer.remove(toRemove.toArray());
viewer.refresh();
}