Thursday, August 30, 2007

New Europa default presentation

An internal note in the WorkbenchPage code lead me to think that our legacy code was broken due to a valid API change. Boris Bokowski has correctly pointed out that it is a bug 202280.

Eclipse Europa has a new default presentation that includes a new minimize/maximize behavior and new tab treatments.

I like the new feature but was a bit puzzled at the API changes made to IWorkbenchPage. Calls to IWorkbenchPage.html#isPageZoomed() always return false. Our application would never call IWorkbenchPage.html#toggleZoom(IWorkbenchPartReference) and our users became a bit bewildered by a view taking up the whole view stack.

IWorkbenchPage page = workbench.getActiveWorkbenchWindow().
                                getActivePage();
if (page.isPageZoomed()) {
    page.toggleZoom(workbenchPartReference);
}

Instead you need to call IWorkbenchPage.html#getPartState(IWorkbenchPartReference). It returns one of the following states.

IWorkbenchPage.STATE_MINIMIZED
State of a view in a given page when the page is zoomed in on the view stack. (int)0
IWorkbenchPage.STATE_MAXIMIZED
State of a view in a given page when the view stack is minimized. (int)1
IWorkbenchPage.STATE_RESTORED
State of a view in a given page when the view stack is in it's normal state. (int 2)

In our case a simple call to restore the view to its original state is all thats needed.

IWorkbenchPage page = workbench.getActiveWorkbenchWindow().
                                getActivePage();
page.setPartState(workbenchPartReference, 
                  IWorkbenchPage.STATE_RESTORED);

2 comments:

Boris Bokowski said...

Hi David,

Please file a bug if the changes to the Workbench API broke your application. We need to know about these cases!

Thanks,
Boris

David Kyle said...

A note in the source code lead me to think that it was not a bug.

I've now added it as a bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=202280.