FilteredTree的性能改进

时间:2015-09-28 22:47:13

标签: java eclipse swt rcp treeviewer

我使用FilteredTree类来过滤我的TreeViewer内容,但由于现在有很多数据,当我输入要过滤数据的内容时,它会在我输入下一个字母之前挂起。有什么办法可以改善表现。

1 个答案:

答案 0 :(得分:0)

缓解慢速过滤器的一种方法是增加运行过滤器之间的延迟。这允许用户在重新运行过滤器之前键入多个字符。

在FilteredTree的子类中,重写getRefreshJobDelay()。默认值是200毫秒,也许允许500-800毫秒更适合您的用例?

例如,考虑Eclipse PDE of a filtered tree中的用例:

@Override
protected long getRefreshJobDelay() {
    // Prolonged job delay time is required because of the attribute search being more costly in nature.
    // This can block input to the filter text severely. Thus it shouldn't happen when typing slowly.
    // The delay of 1500ms is bypassed by some actions that use the filter text to initiate searches or clear the text.
    long delay = (fBypassFilterDelay) ? 0 : REFRESHJOB_DELAY_TIME;
    setBypassFilterDelay(false); // reset afterwards
    return delay;
}

REFRESHJOB_DELAY_TIME是1200毫秒。

如果您希望加快过滤器的实施,或者发布它会有帮助吗?