I’m working on a Eclipse RCP Application. In a class which extends MultiPageEditorPart, I’m trying to set the focus to a text field. But the setFocus Method always returns false.
What am I doing wrong?
The MultiPageEditor has various pages and inside these pages, there are Composite – classes. These classes contain the text field.
Here is the snippet: (errorPage is an int, the Pagenumber on which my validation found the error)
if(!dataValid) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Fehler bei der Dateneingabe", stringBuilder.toString());
this.setActivePage(errorPage);
Composite errorComposite = (Composite) this.getControl(errorPage);
Control[] children = errorComposite.getChildren();
for (Control child : children) {
if(child instanceof Form) {
Form form = (Form) child;
Composite body = form.getBody();
Control[] formChildren = body.getChildren();
for (Control formChild : formChildren) {
if(formChild.equals(errorControl))
formChild.setFocus();
return dataValid;
}
}
}
}
The setFocus() may return false on the following situations:
So I would better check, (1) am I setting focus on the right control, (2) is the control visible, maybe the form containing the control is not in the current selected tab. (3) is any other modal dialog open.