简体   繁体   中英

How to read data from a node in Tree in SWT on double click?

I am writing code to create a tree in SWT RCP. In this tree, I want to implement a functionality - When I double on a node, The name of the node should be displayed. The wrote for that purpose is -

private void addDoubleClickListener() {
    // TODO Auto-generated method stub
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent e) {
            ISelection selection = e.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object item = ((IStructuredSelection) selection)
                        .getFirstElement();
                if (item == null) {
                    return;
                } else {
                    System.out.println(item.toString());
                }
            }
        }
    });

}

It is working fine . But, my problem is, the nodes in my tree are editable. So, after a node is edited, when I double click on the node, it still displays the old data. Is there any solution for that?

Thanks!

I have solved this problem.

Just added this line -

System.out.println(tree.getSelection()[0].getText());

instead of

 System.out.println(item.toString());

Because while renaming the nodes, I was setting the text value to this node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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