从Eclipse中的CNF(Common Navigator Framework)中删除popUpMenus

时间:2009-08-17 18:12:09

标签: eclipse eclipse-plugin eclipse-rcp rpc eclipse-3.4

通过配置plugin.xml文件,我已经部分成功地从Commons Navigator Framework中删除了几乎所有的popUp菜单。
有两个拒绝的菜单:

  • group.edit
  • group.reorganize

我的plugin.xml配置如下所示:

<extension
          point="org.eclipse.ui.navigator.viewer">
       <viewer
             viewerId="org.eclipse.ui.example.navigator.view">
             <popupMenu allowsPlatformContributions="false">
                <insertionPoint
                    name="group.edit" />

                <insertionPoint
                    name="group.reorganize" />
             </popupMenu>
       </viewer>
       <viewerContentBinding
             viewerId="org.eclipse.ui.thermo.navigator.view">
          <includes>
             <contentExtension
                   pattern="org.eclipse.ui.navigator.resourceContent"/>
          </includes>
       </viewerContentBinding> 
</extension>

allowsPlatformContribution设置为false将停止贡献添加到上下文菜单以外的group.editgroup.reorganize ...这已开始显示对我来说就像一个小虫。

显而易见的解决方案是从我的<popUpMenu>中删除插入点,但没有它们,应用程序会抛出异常:

Throwable: java.lang.IllegalArgumentException: Group not found: group.edit

java.lang.IllegalArgumentException: Group not found: group.edit
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup.fillContextMenu(EditActionGroup.java:74)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider.fillContextMenu(EditActionProvider.java:50)
at org.eclipse.ui.navigator.NavigatorActionService.addCommonActionProviderMenu(NavigatorActionService.java:205)
at org.eclipse.ui.navigator.NavigatorActionService.fillContextMenu(NavigatorActionService.java:172)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager.fillContextMenu(CommonNavigatorManager.java:258)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager$4.menuAboutToShow(CommonNavigatorManager.java:273)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:335)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:463)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:459)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:485)

它会为重组组件抛出相同的异常。

3 个答案:

答案 0 :(得分:4)

我成功删除了“group.edit”操作(复制/粘贴),并且我已经这样做了,使用Common Navigator扩展点:

   <extension
         point="org.eclipse.ui.navigator.viewer">
      <viewerActionBinding
            viewerId="org.eclipse.ui.navigator.ProjectExplorer">
         <includes>
            <actionExtension
                  pattern="my.app.client.actions.MyAppEditActionExtension">
            </actionExtension>
         </includes>
      </viewerActionBinding>    
   </extension>
   <extension
         point="org.eclipse.ui.navigator.navigatorContent">
      <actionProvider
            class="my.app.client.workshop.MyPasteActionProvider"
            id="my.app.client.actions.MyAppEditActionExtension"
            overrides="org.eclipse.ui.navigator.resources.actions.EditActions"
            priority="highest">
         <enablement>
         <!-- A hack to allways be enabled -->
         <not>
            <systemTest
                  property="MyApp"
                  value="WONT-EVER-BE-SET">
            </systemTest>
         </not>
         </enablement>
     </actionProvider>
   </extension>

并且,在我的插件依赖项中添加了“org.eclipse.ui.navigator.resources”,我实现了“MyPasteActionProvider”,如下所示:

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider;

/**
 * Create the Edit actions (Cut/Copy/Paste) 
 * and register then globally in the workbench using EditActionProvider.
 * <p/>
 * Then, removes the Copy/Paste contributions in the pop-up menu.
 */
public class MyPasteActionProvider extends EditActionProvider {
   public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu);
   // remove Copy/Paste contributions
   IContributionItem copyItemRemoved = menu.remove("org.eclipse.ui.CopyAction");
   IContributionItem pasteItemRemoved = menu.remove("org.eclipse.ui.PasteAction");
   }
}

嗯,这是一个“气馁的访问”,但我让自己气馁;-) JM.D

答案 1 :(得分:1)

thread suggests用于删除导致菜单项首先出现的内容:

他们可能处于行动集中,因此如果您能够识别导致攻击性贡献的动作集,您可以在WorkbenchAdvisor中执行以下操作:

    ActionSetRegistry reg = WorkbenchPlugin.getDefault()
            .getActionSetRegistry();


    IActionSetDescriptor[] actionSets = reg.getActionSets();
    String[] removeActionSets = new String[] {
        "org.eclipse.ui.cheatsheets.actionSet",
        "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
       "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
          "org.eclipse.ui.WorkingSetActionSet",
        "org.eclipse.update.ui.softwareUpdates", };


    for (int i = 0; i < actionSets.length; i++)
    {
        boolean found = false;
        for (int j = 0; j < removeActionSets.length; j++)
        {
            if (removeActionSets[j].equals(actionSets[i].getId()))
                found = true;
        }


        if (!found)
            continue;
        IExtension ext = actionSets[i].getConfigurationElement()
                .getDeclaringExtension();
        reg.removeExtension(ext, new Object[] { actionSets[i] });
    }

我发现的最近的错误是145233: Make more obvious way to specify input (for RCP apps)similar hack Bug 143430 (CommonNavigator requires initialInput to be Adaptable)是一个更普遍的,并且表明CNF已经使用eclipse3.5(Galileo)进行了改进。
那么你也有这个问题与3.5和自定义CNF类?


正如文章“ Eclipse CNF: Navigator Content Extensions ”中所提到的,CNF已经与eclipse3.5一起发展,本文似乎有一些树具有真正的自定义上下文菜单条目。

alt text

答案 2 :(得分:1)

通常,您应该将Command Framework与最新版本的Eclipse(3.3或更高版本)一起使用,这取代了在Common Navigator中提供弹出菜单的机制。