Hi All,
How can I add to my Tree in the TreeViewer a popup menu?
thanks,
HBC.
Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg
public void open() {
final Display display = new Display();
final Shell shell = new Shell();
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
shell.setLayout(gridLayout);
shell.setText("SWT Application");
{
final TreeViewer treeViewer = new TreeViewer(shell, SWT.BORDER);
final Tree tree = treeViewer.getTree();
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
{
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
buildContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(tree);
tree.setMenu(menu);
}
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void buildContextMenu(IMenuManager manager) {
IAction action = new Action("Test action") {
public void run() {
System.out.println("Test action executed!");
}
};
manager.add(action);
}
Users browsing this forum: No registered users and 1 guest