在运行时删除视图操作扩展

发布于 2024-12-16 10:24:02 字数 1343 浏览 1 评论 0原文

我确实创建了一个视图,这些视图用于多个产品中,我们已经交付了。 View被放置在一个feature中,而这些feature不知道产品规格,而该feature也不应该知道。

向视图贡献操作,这些操作显示在视图工具栏标题中,

  • 其他插件通过实现扩展点“org.eclipse.ui.viewActions”

具体取决于系统属性(产品规范将在运行时设置),所有贡献的视图操作应是否隐藏。

问题: 我无法找到一个类,用于删除特殊扩展点的删除扩展。我知道

  • WorkbenchPlugin.getDefault().getActionSetRegistry()

可以删除 actionSets,但是 viewActions 是否存在类似的东西?

我查看了代码并找到了解决方案,但这完全不可接受,因为当我更新 Eclipse 目标平台时,由于反射调用,它可能/将会中断。

Field privateStringField = ExtensionRegistry.class.getDeclaredField("masterToken"); //$NON-NLS-1$
privateStringField.setAccessible(true);
Object masterToken = privateStringField.get(registry);

// Reads the External Datatype Providers
IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ui.viewActions"); //$NON-NLS-1$
IConfigurationElement[] extensionPointArray = extensionPoint.getConfigurationElements();

for (int i = 0; i < extensionPointArray.length; i++) {
    IConfigurationElement element = extensionPointArray[i];
    if (element.getAttribute("targetID").equalsIgnoreCase(pPartId)) { //$NON-NLS-1$
        IConfigurationElement[] childs = element.getChildren();
        for (int j = 0; j < childs.length; j++) {
            registry.removeExtension(element.getDeclaringExtension(), masterToken);
        }
    }
}

I do have created a View and these View is used in multiple products, we already have delivered.
The View is placed in a feature and these feature does not know the product specification and the feature should not know.

Other plugins contribute actions to the view, which are shown in the view toolbar title, by implementing the extension point

  • "org.eclipse.ui.viewActions"

Depending on a system property (the product specification will set at runtime) all contributed view actions should be hidden or not.

Question:
i was not able to find a class, for removing deleting extension for a special extension point. I know that the

  • WorkbenchPlugin.getDefault().getActionSetRegistry()

can remove actionSets, but does something similuar exists for the viewActions?

I looked into the code and found a solution, but this is totally not acceptable, because it could/will break, when i update my eclipse target platform, because of the reflection call.

Field privateStringField = ExtensionRegistry.class.getDeclaredField("masterToken"); //$NON-NLS-1$
privateStringField.setAccessible(true);
Object masterToken = privateStringField.get(registry);

// Reads the External Datatype Providers
IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ui.viewActions"); //$NON-NLS-1$
IConfigurationElement[] extensionPointArray = extensionPoint.getConfigurationElements();

for (int i = 0; i < extensionPointArray.length; i++) {
    IConfigurationElement element = extensionPointArray[i];
    if (element.getAttribute("targetID").equalsIgnoreCase(pPartId)) { //$NON-NLS-1$
        IConfigurationElement[] childs = element.getChildren();
        for (int j = 0; j < childs.length; j++) {
            registry.removeExtension(element.getDeclaringExtension(), masterToken);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-12-23 10:24:02

您可以使用产品自定义在加载扩展 XML 时对其进行修改。然后,需要的产品可以使用产品定制和样式表。例如,要抑制操作:

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="actionSet[@id='org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo']">
   </xsl:template>
   <xsl:template match="node()|@*">
       <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
   </xsl:template>
 </xsl:stylesheet>

您还可以尝试 活动/功能 隐藏 viewActions。每个产品都需要包含禁用的活动,以使 viewActions 扩展消失。

You can use Product Customization to modify the extensions XML as it is loaded. Then products that need to can can use the Product Customization and a style sheet. ex, to suppress an action:

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="actionSet[@id='org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo']">
   </xsl:template>
   <xsl:template match="node()|@*">
       <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
   </xsl:template>
 </xsl:stylesheet>

You could also try Activities/Capabilities to hide the viewActions. Each product that needs to would include disabled activities to make the viewActions extensions disappear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文