从Eclipse窗口中删除视图->显示视图 [英] Removing a view from Eclipse Window -> Show views

查看:174
本文介绍了从Eclipse窗口中删除视图->显示视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,其中某些视图仅在附加到某些视图时才起作用. 我们想从 Window-> Show View 对话框中删除这些视图,以使用户无法将其添加到无法使用的视图中.

We have an application in which some views only work when attached to certain perspectives. We want to remove those views from the Window -> Show View dialog so that users cannot add them to perspectives where they don't work.

关于如何以编程方式或声明方式执行此操作的任何想法?

Any ideas on how to do this either programmatically or declaratively?

我尝试使用<visibleWhen />,但视图仍显示在对话框中:

I have tried using <visibleWhen />, but the views are still showing in the dialog:

  <view class="com.mycompany.ViewClass" 
        id="com.mycompany.ViewId" 
        name="View Name" 
        restorable="true">

        <visibleWhen>
            <with variable="activeWorkbenchWindow.activePerspective">
                <equals value="com.mycompany.MyPerspective"/>
            </with>
        </visibleWhen>
  </view>

我认为<visibleWhen />子句没有任何问题,所以我想知道它是否可以与View一起使用?

I don't think there is any problem with the <visibleWhen /> clause, so I'm wondering if it can be used with a View?

推荐答案

不幸的是,似乎Eclipse已经通过在内容视图"对话框的内容提供者上调用私有的ViewContentProvider.removeIntroView来为简介"视图执行此操作.克服此限制的一种方法是通过添加到org.eclipse.ui.activities扩展点来定义活动(有关如何将活动映射到UI贡献,请参见activityPatternBinding).这样做不仅会从显示视图"对话框中删除视图,还会阻止它们在透视图本身中显示.然后可以以编程方式显示视图.由于我们应用程序中的限制,我还必须启用ApplicationWorkbenchAdvisor.preStartup方法中的活动:

Unfortunately, it seems that Eclipse already does this for the Introduction view by calling the private ViewContentProvider.removeIntroView on the content provider for the Show Views dialog. A way to get around this limitation is to define activities by adding to the org.eclipse.ui.activities extension point (see activityPatternBinding on how activities can be mapped to UI contributions). Doing this will not only remove the views from the Show Views dialog, but it will also prevent them from showing in the perspectives themselves. The views can then be shown programmatically. I had to also enable the activities in the ApplicationWorkbenchAdvisor.preStartup method because of limitations in our application:

    Set<String> activityIds = new HashSet<String>();
    activityIds.add("com.my.activity.id");
    IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
    activitySupport.setEnabledActivityIds(activityIds);

在这种情况下,必须在显示对话框之前禁用活动,因此也必须修改显示视图"菜单贡献.

In this case, the activity has to be disabled before showing the dialog, so the Show Views menu contribution has to be modified to do this as well.

希望扩展点将添加到下一个Eclipse版本,以提供开发人员用于以声明方式从对话框中删除视图的选项.

Hopefully an extension point will be added to the next version of Eclipse to provide the option for developers to remove views from the dialog declaratively.

这篇关于从Eclipse窗口中删除视图-&gt;显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆