简体   繁体   English

在运行时eclipse插件中从树中获取子节点

[英]get Child node from tree in run time eclipse plugin

I have a tree like 我有一棵像

    final Tree tree = new Tree(composite_1, SWT.BORDER | SWT.H_SCROLL
            | SWT.V_SCROLL);

I entered tree child by TreeItem class. 我通过TreeItem类输入了树子。 Now when i am running my plugin i want to fetch the child node ( or child nodes) of parent which is selected. 现在,当我运行我的插件时,我想获取已选择的父级的子节点(或多个子节点)。 I wrote a listener for reading event occur which fire when we click on some tree node 我编写了一个侦听器,用于读取事件,当我们单击某个树节点时会触发该事件

        tree.addListener(SWT.Selection, new Listener() {
              public void handleEvent(Event e) {
                String string = "";
                TreeItem[] selection = tree.getSelection();

                for (int i = 0; i < selection.length; i++){
                  string += selection[i] + " ";
                System.out.println("Selection={" + string + "}");

                }    
              }
                System.out.println(" ============== action listener ==================== ");
              }
            }); 

Now here i checked most of method but did not find any way to get child node of any parent. 现在在这里,我检查了大多数方法,但没有找到任何方法来获取任何父级的子节点。

What have i tried :- 我尝试了什么:-

                    Control[] pqr = tree.getChildren();
                    System.out.println(pqr.toString());

TreeItem has a getItems() method which returns the children of the item. TreeItem具有getItems()方法,该方法返回该项的子项。 So you can use that with the tree.getSelection() method that your are already using. 因此,可以将其与已经在使用的tree.getSelection()方法一起使用。

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

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