简体   繁体   English

Java插件弹出菜单

[英]Java plugin pop-up menu

I have a plugin which adds a view. 我有一个添加视图的插件。 This view contains a table which contains on each row some informations. 该视图包含一个表,该表的每一行均包含一些信息。 I would like to have a popup menu when I press the right mouse click. 当我单击鼠标右键时,我想要一个弹出菜单。 How can I add the extension org.eclipse.ui.menus and after creating the menuContribution to see it in the view ? 我如何添加扩展名org.eclipse.ui.menus并创建menuContribution之后在视图中查看它?

In your ViewPart use this code: 在您的ViewPart使用以下代码:

MenuManager contextMenu = new MenuManager();

contextMenu.setRemoveAllWhenShown(true);

getSite().registerContextMenu(contextMenu, viewer);

Control control = viewer.getControl();
Menu menu = contextMenu.createContextMenu(control);
control.setMenu(menu);

where viewer is your TableViewer . viewer是您的TableViewer

The context menu this creates has the same id as your view so you contribute to it with: 此创建的上下文菜单与您的视图具有相同的ID,因此您可以通过以下方式对其进行贡献:

  <menuContribution
        locationURI="popup:your.view.id">
     ....
  </menuContribution>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM