0
    @Override
    public Object[] getChildren(Object parentElement) {
        if (parentElement instanceof List) {
            List<?> arraysList = ((List<?>) parentElement).stream()
                    .filter(p -> p instanceof List && !((List<?>) p).isEmpty()).collect(Collectors.toList());
            datas = arraysList.toArray();
            return arraysList.toArray();
        }
        return null;
    }

getChildren() method is invoked and fill the child node data when a user tries to expand the child node. If I try to expand the child node programmatically before getChildren() get called it's showing the tree like this. So there any idea to initialize the child nodes or call getChildren() programmatically ?

when I call the item.setExpanded(true) to expand the child node and its showing like this

enter image description here

enter image description here

but if i expand any of the 1-9 node from UI it will call the getChildren() method and fill the child data for that specific node for eg: im expanding node 4 here and the next time when i click the searchAction (item.setExpanded(true)) its showing the child node of 4 only because it set data when i expanded from UI i need to set the child node data for all the nodes enter image description here

Promod Kumar
  • 121
  • 1
  • 8
  • Expanding the tree should call getChildren as required. What is supposed to be wrong in the image? What are you calling to expand the tree? – greg-449 Feb 07 '21 at 11:56
  • The first node I have opened from UI so its showing the child nodes value because when I expanded the child node it called the getChildren function and added the data other node's are not showing the child node values but its expanded – Promod Kumar Feb 07 '21 at 12:01
  • There is something wrong in your code. You need to show us a [mre] – greg-449 Feb 07 '21 at 12:18
  • There is no problem with my code, I need a solution to add the value to all the child node's without calling the getChildren() method or call getChildren() method explicitly in code to fill all child node – Promod Kumar Feb 07 '21 at 13:03
  • Sorry, but if you are not going to show us an [mre] I cannot help further. – greg-449 Feb 07 '21 at 13:30
  • @greg-449 i have edited the description , Hope you can understand the situation now ? Thanks in advance – Promod Kumar Feb 07 '21 at 14:03
  • If you are using TreeViewer you must *NEVER* call Tree or TreeItem APIs, you must only use the TreeViewer APIs. TreeViewer is in control of the tree and calling the lower level APIs will cause incorrect behaviour like this. In this case one of the TreeViewer `expandToLevel` methods is probably appropriate – greg-449 Feb 07 '21 at 15:48
  • The same applies to setting items colors, use a label provider implementing `IColorProvider` or one of the many styled label providers. – greg-449 Feb 07 '21 at 15:50
  • I want to implement a search feature in the tree if any of the rows contains search text I want to expand those parent nodes and their child node and need to highlight the whole row, so which method in treeviewer are you suggesting, and I have tried calling expandToLevel already but its not working – Promod Kumar Feb 07 '21 at 16:49
  • Probably `expandToLevel(Object elementOrTreePath, int level)`. You may have to use a `TreePath` as the `elementOrTreePath` – greg-449 Feb 07 '21 at 17:25

0 Answers0