如何添加透视侦听器 [英] How to add perspective listeners

查看:181
本文介绍了如何添加透视侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们有4个视图(视图1,2,3和4)和3个视角(透视图1,2和3)。

In our application, we have 4 views (View 1, 2, 3 & 4) and 3 perspectives (perspective 1, 2 and 3).

通过实现 IPerspectivefactory 构建透视图,并通过扩展viewPart构建视图。

The perspectives are built by implementing IPerspectivefactory and views are built by extending viewPart.

我们面临的情况是,如果选择了任何透视图,我们希望将焦点设置为特定视图。

We are facing a situation where we want to set the focus to a particular view in case of any of the perspective is selected.

对于ex,请将View 1视为一个常见视图,它将在所有3个视角下显示。每当我们选择任何透视图时,我们都希望将焦点设置为View1。

For ex, Consider View 1 as a common view which will be displayed under all the 3 perspectives. We want to set focus to View1 whenever we select any perspective.

如何向透视图添加侦听器?

How to add listeners to the perspectives?

我们知道我们必须添加 IPerspectiveListerner 来收听透视图更改,但我们不确定在哪里添加这样我们就可以在 IPerspectiveListener 下实现的方法中获得执行控制。

We know that we have to add IPerspectiveListerner to listen to the perspective changes but we are not sure where to add it so that we get the execution control inside the methods which we have implemented under IPerspectiveListener.

推荐答案

您可以使用以下代码:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new IPerspectiveListener() {
  @Override
  public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
    try {
      page.showView("...", null, IWorkbenchPage.VIEW_VISIBLE);
    } catch (PartInitException ex) {
      ex.printStackTrace();
    }
  }

  @Override
  public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
  }
});

编辑:因为这与view1绑定,你可以将此代码放在view1插件的Activator中。当然,直到从view1插件加载一些代码才会显示。类似于:

since this is tied to view1 you could place this code in the Activator for the view1 plugin. Of course it won't show up until some code is loaded from the view1 plugin. Something like:

Job job = new UIJob("Add Perspective listener") {
    public IStatus runInUIThread(IProgressMonitor monitor) {
        addPerspectiveListener();
        return Status.OK_STATUS;
    }
};
job.setSystem(true);
job.schedule();

这篇关于如何添加透视侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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