0

I am using tree viewer to display a list of elements on the selection changed listener I want to get the name of the selected node. Here is my selection listener

 treeViewerSwaComponents.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            IStructuredSelection sel = (IStructuredSelection) event.getSelection();

            if (sel.isEmpty())
                return;

            Component component = (Component) sel.getFirstElement();
            notifyComponentSelection(component);
        }

    });

How can I get the name of the selected node as a string.

Thanks

Wearybands
  • 2,438
  • 8
  • 34
  • 53

1 Answers1

0

Assuming your label provider implements ILabelProvider you can use:

ILabelProvider provider = (ILabelProvider)treeViewerSwaComponents.getLabelProvider();

String name = provider.getText(sel.getFirstElement());
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I want to get the text of the label before I cast it to component Object because on the basis of the text of label I will decide if I have to cast it or not – Wearybands Sep 15 '14 at 09:51