Question

I have a Tree generated with a help of TreeViewer. I need to add items from this tree to another component, when user double clicks it with mouse. I suppose that mouseListener has to be added for each label in the tree. But I wonder how to add mouseDoubleClick event listeners via TreeViever's providers. I've already implemented content and label providers, but I don't see any interfaces, which I can use for getting generated labels.

Was it helpful?

Solution

You add a single double click listener to the TreeViewer with the addDoubleClickListener method. The parameter is a class that implements IDoubleClickListener:

treeViewer.addDoubleClickListener(new IDoubleClickListener() {
    @Override
    public void doubleClick(final DoubleClickEvent event)
    {
      final IStructuredSelection selection = (IStructuredSelection)event.getSelection();

       // TODO deal with the selection
    }    
});

The DoubleClickEvent parameter contains the information about the selected object in the tree.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top