Context menu for TreeViewer based on selected node - SWT

前端 未结 4 1180
逝去的感伤
逝去的感伤 2020-12-31 13:51

I need to create a context menu for a TreeViewer in an Eclipse plugin project. But, the menu should not contain constant items, they should vary depending on the type of the

4条回答
  •  心在旅途
    2020-12-31 14:44

    Suppose that you know how to create Action and you are only interested in context menu following example worked for me hope this bunch of code will help you

     private void hookContextMenu() {
        MenuManager contextMenu = new MenuManager();
        contextMenu.setRemoveAllWhenShown(true);
        contextMenu.addMenuListener(new IMenuListener() {
    
            @Override
            public void menuAboutToShow(IMenuManager manager) {
    
    
    
                IStructuredSelection sSelection = (IStructuredSelection) treeViewer.getSelection();
    
                }
                if(selectedObject instanceof A){
                manager.add(action);
                }
    
            }
        });
    

提交回复
热议问题