1

I have a really basic FormEditor and FormPage:

public class CustomFieldSetVersionEditor extends FormEditor {

    @Override
    protected void addPages() {
        try {
            addPage(new MyFormPage(this), getEditorInput());
        } catch (final PartInitException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void doSave(final IProgressMonitor monitor) {}

    @Override
    public void doSaveAs() {}

    @Override
    public boolean isSaveAsAllowed() { return false; }
}

class MyFormPage extends FormPage {

    public MyFormPage(final FormEditor editor) {
        super(editor, "id", "Title");
    }

    @Override
    protected void createFormContent(final IManagedForm managedForm) { }

}

This admittedly complex and exotic use case brings the following exception:

java.lang.StackOverflowError at org.eclipse.swt.widgets.Widget.getData(Widget.java:525) at org.eclipse.ui.part.MultiPageEditorPart.getEditor(MultiPageEditorPart.java:599) at org.eclipse.ui.part.MultiPageEditorPart.getActiveEditor(MultiPageEditorPart.java:523) at org.eclipse.ui.forms.editor.FormEditor.getActiveEditor(FormEditor.java:430) at org.eclipse.ui.forms.editor.FormEditor$FormEditorSelectionProvider.getSelection(FormEditor.java:84) at org.eclipse.ui.forms.editor.FormEditor$FormEditorSelectionProvider.getSelection(FormEditor.java:89) at org.eclipse.ui.forms.editor.FormEditor$FormEditorSelectionProvider.getSelection(FormEditor.java:89) at org.eclipse.ui.forms.editor.FormEditor$FormEditorSelectionProvider.getSelection(FormEditor.java:89) ...

However, if I use addPage(IFormPage) instead of addPage(IEditorPart, IEditorInput) it works. There is even a "bug" report for this problem: Bug 283039 (it's no bug, because... there is no reason given).

We don't need to discuss if this is a bug, but what I want to know is: How do I add a FormPage to a FormEditor while still defining the IEditorInput?

Stefan S.
  • 3,950
  • 5
  • 25
  • 77

1 Answers1

2

The FormPage is being initialized twice, the second time with the same IEditorSite as the main FormEditor. This results in the same selection provider being used for the FormPage as the main editor, this selection provider does not expect this and gets in to a loop.

You can stop the second initialization by overriding the isEditor method of FormPage and return true:

@Override
public boolean isEditor() {
  return true;
}

Also note that if you use the addPage(IFormPage) call the page is still initialized with the editor input (as long as isEditor returns false).

greg-449
  • 109,219
  • 232
  • 102
  • 145