使用命令添加并显示一个新的FormPage到FormEditor [英] Add and display a new FormPage to a FormEditor using a command

查看:506
本文介绍了使用命令添加并显示一个新的FormPage到FormEditor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Eclipse 3.6的Eclipse RCP独立应用程序。



我已经实现了FormEditor和FormPage(多页)FormEditor。在第一个FormPage是一个Button,它有一个命令,计算一些数据,并应该打开一个第二个FormPage与结果。



计算结果,第二个FormPage显示结果并正确添加到FormEditor中。



我的问题是FormEditor中只出现一个新标签。我想要第二个FormPage立即显示。相反,您必须单击该选项卡才能看到第二个页面。



以下是将FormPage添加到编辑器的Handler代码。

  IWorkbenchWindow window = PlatformUI.getWorkbench()。getActiveWorkbenchWindow(); 
IWorkbenchPage page = window.getActivePage();

(IEditorReference引用:page.getEditorReferences()){
if(reference .getId()。equals(my.project.MyFormEditor)){
EditorPart part =(EditorPart)reference.getEditor(true);
MyFormEditor editor =(MyFormEditor)part;
editor.addResultPage();
}
}

这个工作正常,但是我需要把ResultPage到现在。所以我试图调用ResultPage的setFocus()方法:

  IFormPage resultPage = editor.findPage(my.project .ResultPage); 
resultPage.setFocus();

并且已经覆盖了ResultFile的setFocus()方法:

  public void setFocus(){
this.getPartControl()。setFocus();
}

但是当Method setFocus尝试获取PartControl时,会导致NullPointer Exeption。看来ResultPage在这个时间点没有加载。

所以我试图通过asyncExec调用setFocus()方法,如下所示:

  Display.getDefault()。asyncExec(new Runnable(){
public void run(){
//...call the setFocus()方法。 ...
}
}

但这会导致相同的NullpointerException通过添加一个等待到Runnable它会导致一个IllegalMonitorState异常。



所以我尝试了几种方式,搜索互联网的解决方案,但找不到一个,所以我希望这可能可以帮助我。



有没有一个干净的方法来将特定的FormPage带到前景?调用setFocus()方法错误?应该像toForeground ()?或者FormEditor / FormPage UI Elements不是这样吗?



最好的问候



Matthias

解决方案

在您的EditorPart中尝试((CTabFolder)getCont ainer())。setSelection(2);


I have an Eclipse RCP Standalone Application using Eclipse 3.6.

I have implemented a FormEditor and a FormPage for that (multipage) FormEditor. On that first FormPage is a Button that has a Command which calculate some data and should open a second FormPage with the results.

The results are calculated and the second FormPage is showing the results and added to the FormEditor properly.

My problem is that only a new tab appears in the FormEditor. I want that the second FormPage is shown immediately. Instead you have to click on the tab in order to see the second page.

Here is the code of the Handler which adds the FormPage to the Editor.

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();

for(IEditorReference reference : page.getEditorReferences()){
  if(reference .getId().equals("my.project.MyFormEditor")){
    EditorPart part = (EditorPart) reference.getEditor(true);
    MyFormEditor editor = (MyFormEditor)part;
    editor.addResultPage();
  }
}

This works fine, but I need to bring the ResultPage to the Foreground now. So I tried to call the setFocus() Method of the ResultPage with:

IFormPage resultPage = editor.findPage("my.project.ResultPage");
resultPage.setFocus();

and have overritten the setFocus() Method of the ResultPage like this:

public void setFocus(){
 this.getPartControl().setFocus();
}

But that causes a NullPointer Exeption when the Method setFocus tries to get the PartControl. It seems that the ResultPage isn't loaded at that point of time.
So I tried to call the setFocus() Method via asyncExec like this:

Display.getDefault().asyncExec(new Runnable() {
 public void run() {
 //...call the setFocus() Method ....
 }
}

But that causes the same NullpointerException. And by adding a wait to the Runnable it causes a IllegalMonitorState Exception.

So I tried several ways and search the internet for a solution but could't find one. So I hope that maybe you can help me.

Is there a clean way to bring a specific FormPage to the Foreground? Is calling the setFocus() Method wrong? Should it something like toForeground()? Or isn't this possible with the FormEditor/FormPage UI Elements?

Best Regards

Matthias

解决方案

Try in your EditorPart ((CTabFolder) getContainer()).setSelection(2);

这篇关于使用命令添加并显示一个新的FormPage到FormEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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