简体   繁体   English

在 Jface Treeviewer 中实现搜索功能

[英]Implement search functionality in Jface Treeviewer

I'm trying to implement search functionality in Jface Treeviewer, I have tried using SearchableTreeViewer but it didn't help, I want to highlight all the columns that contain the corresponding text我正在尝试在 Jface Treeviewer 中实现搜索功能,我尝试使用 SearchableTreeViewer 但它没有帮助,我想突出显示包含相应文本的所有列

    public void searchTree(String searchtext) {
    
    viewer.collapseAll();
    final int itemCount = viewer.getTree().getItemCount();
    for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) {
        TreeItem item = viewer.getTree().getItem(itemIndex);
            if (item.getData().toString().toUpperCase().contains(searchtext.toUpperCase())) {
                viewer.expandToLevel(item.getData(), TreeViewer.ALL_LEVELS);
                item.setForeground(new Color(Display.getCurrent(), 255, 0, 0));         
            }
            else {
                item.setForeground(new Color(Display.getCurrent(), 0, 0, 0));   
            }
        }
    } 

在此处输入图像描述

Here I'm able to highlight the parent row but what I'm trying to achieve is to highlight the exact column(Symbol Name)在这里,我可以突出显示父行,但我想要实现的是突出显示确切的列(符号名称)

Any idea to highlight the child node specific columns?任何想法突出子节点特定列?

Try to do tree.setSelection to that child item before setting the foreground color.在设置前景色之前尝试对该子项执行 tree.setSelection 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM