就是一個根據節點類型增長不一樣菜單的例子。 java
cyper的代碼: node
private void createContextMenu(Composite parent) { final MenuManager mm = new MenuManager(); mm.setRemoveAllWhenShown(true); mm.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { IStructuredSelection selection = (IStructuredSelection) serverTree .getSelection(); if (!selection.isEmpty()) { Node node = (Node) selection.getFirstElement(); if (node instanceof TableNode) { mm.add(new QueryDataAction()); mm.add(new ExportDataAction()); mm.add(new Separator()); mm.add(new RefreshMetaDataAction()); mm.add(new Separator()); mm.add(new CodeGenerationAction()); } } } }); serverTree.getControl().setMenu(mm.createContextMenu(serverTree.getControl())); }效果以下:
一年之後。。。
eclipse