eclipse-rcp problem : context menu added by viewerContribution not work

ぃ、小莉子 提交于 2019-12-12 04:59:44

问题


 <extension
       point="org.eclipse.ui.popupMenus">
    <viewerContribution
          id="com.amarsoft.sysconfig.plugin.ConnectionsViewPopupContribution"
          targetID="com.amarsoft.sysconfig.plugin.views.ConnectionsView">
       <action
             class="com.amarsoft.sysconfig.plugin.actions.OpenConnectionAction"
             id="com.amarsoft.sysconfig.plugin.actions.OpenConnectionAction"
             label="打开"
             menubarPath="additions">
       </action>
    </viewerContribution>
 </extension>

but when I open the com.amarsoft.sysconfig.plugin.views.ConnectionsView view right click ,nothing happened...

I will edit my post to add any information needed , as now I dont know what may cause this problem.


回答1:


In order for org.eclipse.ui.popupMenus or org.eclipse.ui.menus (preferred) to be able to contribute to a view context menu, that view must register the menu with the framework, usually in createPartControl(Composite). ex:

MenuManager contextManager = new MenuManager();
contextManager.setRemoveAllWhenShown(true);
Menu contextMenu = contextManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(contextMenu);
getSite().registerContextMenu(contextManager, viewer);

You can create a sample plugin and generate the view template, and it will provide an example of hooking up to a TreeViewer. If you don't use JFace viewers, then you need to provide an implementation of org.eclipse.jface.viewers.ISelectionProvider.




回答2:


Unless you're targeting Eclipse 3.3 or before, consider moving to the new extension points. See this blog entry for more information...

UPDATED_ link



来源:https://stackoverflow.com/questions/6340109/eclipse-rcp-problem-context-menu-added-by-viewercontribution-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!