0

I am creating a tree structure in RCP application. I want to able to create a pop up menu. I have been able to create a dummy menu item.

 final Menu treeMenu = new Menu(check.getShell(), SWT.POP_UP);
        MenuItem item = new MenuItem(treeMenu, SWT.PUSH);
        item.setText("Open");
        item.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                System.out.println("CAme in Open");
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                // TODO Auto-generated method stub

            }
        });

        check.setMenu(treeMenu);

this menu however does not recognize the node details. I want something that can obtain information about the node which we have opened context menu on.

greg-449
  • 102,836
  • 220
  • 90
  • 127
Praveen
  • 101
  • 12

1 Answers1

0

If you are using a TreeViewer (or TableViewer) just get the current selection:

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

Object selectedElement = sel.getFirstElement();

For a Tree use:

TreeItem [] selectedItems = tree.getSelection();
greg-449
  • 102,836
  • 220
  • 90
  • 127