问题
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
回答1:
Try in your EditorPart ((CTabFolder) getContainer()).setSelection(2);
来源:https://stackoverflow.com/questions/6447324/add-and-display-a-new-formpage-to-a-formeditor-using-a-command