我正在使用Eclipse RCP来构建桌面应用程序。当用户调用弹出菜单时,我想在菜单中添加一些项目。类似于针对问题采取的“建议操作”列表。弹出窗口在桌子上,它已经有命令。 实现这个的正确方法是什么?
答案 0 :(得分:1)
public void createPartControl(Composite parent) {
...
final Action a = new Action("") {};
final MenuManager mgr = new MenuManager();
mgr.setRemoveAllWhenShown(true);
mgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
final IStructuredSelection selection = (IStructuredSelection) listViewer
.getSelection();
if (!selection.isEmpty()) {
// example Action, here delete...
Action deleteAction = new Action("Delete") {
public void run() {
....
}
};
mgr.add(deleteAction);
// *** decide here which actions to add by ***
// *** evaluation of some of your variables ***
mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
});
tableViewer.getControl().setMenu(
mgr.createContextMenu(tableViewer.getControl()));
....
}