Community
Participate
Working Groups
Bugzilla – Bug 209333
[Trim] [Trim] NPE in IWorkbenchPage.setPartState(IWorkbenchPartReference, IWorkbenchPage.STATE_RESTORED);
Last modified: 2009-08-27 14:53:11 EDT
Created attachment 82535 [details] Demonstrates the bug. When trying to restore a view from minimized state, the platform throws a NullPointerException: try { IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IWorkbenchPartReference ref = page.findViewReference(View.ID); page.setPartState(ref, IWorkbenchPage.STATE_RESTORED); } catch (Throwable e) { e.printStackTrace(); // NullPointerException caught } The attached project is a small demonstration. It was created using the "Hello RCP application with a view" wizard by adding to commands: DoIt and UndoIt. Selecting "DoIt" minimizes the view with the code: IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IWorkbenchPartReference ref = page.findViewReference(View.ID); page.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED); Selecting "UndoIt" tries to restore the view with the code: IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); IWorkbenchPartReference ref = page.findViewReference(View.ID); page.setPartState(ref, IWorkbenchPage.STATE_RESTORED); You should see a stack trace in the Eclipse console with the location where the NPE occured.
I'm using eclipse 3.4.0 build I20071101-2000 Once the view has been minimized once, the method getIdForRef(IViewReference ref) of the class org.eclipse.ui.internal.FastViewManager returns true and it should not as the view is not a FastView (the Map idToFastViewsMap contains the view id so the method return true). Hope it helps...
First, thanks for the patch! I'm looking at this right now and should be able to come up with something... Sorry for leaving on the back burner, it was marked 'minor'.
OK, the basic issue is that once the stack containing the view becomes minimized it effectively becomes a 'fast view'. What this means is that the 'setState' event is being re-routed to the FastViewPane's PartSite. This is incorrect in that that handler expects the fastview to be currently open and it isn't, leading to the NPE. This is definitely incorrect. Most likely it should direct the state change to the current 'owner' of the part, the TrimStack. I'm currently trying to find a workaround. Would maximizing/restoring the EditorArea work for you? In the given scenario it would behave identically since maximizing the editor area would cause the view stack to minimize. The advantage is that here we're talking to the part that doesn't change into a TrimStack but rather to the one that is still part of the main presentation area. BTW, this is not going to find its way into a 3.4.x maintenance build (only 'stop ship' defects are considered at this point) so if I need to add code to make this happen it'll only be available in 3.5...
Created attachment 125582 [details] Patch to provide a 'setEditorAreaState' API in WorkbenchPage Apparently there's no existing public (API) mechanism to be able to control the state of the editor area. This precludes RCP applications from writing operations to maximize or restore the editor area. This patch has an initial (and naive) implementation. For example, it should have a different behavior if the old min/max story is being used (i.e. don't use the upper right stack but the one containing the active editor, if any).
*** Bug 274909 has been marked as a duplicate of this bug. ***
Marking as major since the code to reproduce this is 'correct' by any sane analysis. Note that this is unlikely to make it into the 3.5 build since we're in RC lockdown but I'd certainly consider this as a 3.5.1 candidate...
I'm interested in this also
I managed to work around this problem by essentially finding out how the "restore" button on the fast view pane works.. Basically before trying to restore my view that has been minimized I call the following; page.getActivePerspective().getFastViewManager().removeViewReference(<view to restore>, true, true); and then call page.setPartState(<view to restore>,IWorkbenchPage.STATE_RESTORED); This works for me with no problems other than the fact that most of the calls are to internal Eclipse API, but I'm happy with this until a real fix makes it in to 3.5.1. Hope this info is useful to someone. Thanks, Rob
(In reply to comment #8) > I managed to work around this problem by essentially finding out how the > "restore" button on the fast view pane works.. > > Basically before trying to restore my view that has been minimized I call the > following; > > page.getActivePerspective().getFastViewManager().removeViewReference(<view to > restore>, true, true); > > and then call > > page.setPartState(<view to restore>,IWorkbenchPage.STATE_RESTORED); > > This works for me with no problems other than the fact that most of the calls > are to internal Eclipse API, but I'm happy with this until a real fix makes it > in to 3.5.1. > > Hope this info is useful to someone. > > Thanks, > > Rob > Thanks, sounds like a work-around but I don't see getActivePerspective() off of the active page.
My fault, I have a local variable with the "page" in it.. anyway the full API call would be ((WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()).getActivePerspective().getFastViewManager().removeViewReference(<view to restore>, true, true); I've also attached my simple demo to show the workaround.. you only really need to look at the View class.
Created attachment 136782 [details] Demonstrates the workaround for restoring views minimized to the fastview pane
(In reply to comment #10) > My fault, I have a local variable with the "page" in it.. anyway the full API > call would be > > ((WorkbenchPage) > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()).getActivePerspective().getFastViewManager().removeViewReference(<view > to > restore>, true, true); > > I've also attached my simple demo to show the workaround.. you only really need > to look at the View class. > Thanks for your efforts. I realized "page" was your variable name. What I'm saying is that on 3.4.1 and 3.4.2, Eclipse tells me that getActivePerspective() is undefined for IWorkbenchPage. There is a getPerspective() but it does not have getFastViewManager().
reply to comment #12) > What I'm > saying is that on 3.4.1 and 3.4.2, Eclipse tells me that getActivePerspective() > is undefined for IWorkbenchPage. > > There is a getPerspective() but it does not have getFastViewManager(). From comment 10, you can see there is a cast to WorkbenchPage (internal non-API type) and the invocation is not being performed with an IWorkbenchPage (API).
(In reply to comment #13) > reply to comment #12) > > What I'm > > saying is that on 3.4.1 and 3.4.2, Eclipse tells me that getActivePerspective() > > is undefined for IWorkbenchPage. > > > > There is a getPerspective() but it does not have getFastViewManager(). > > From comment 10, you can see there is a cast to WorkbenchPage (internal non-API > type) and the invocation is not being performed with an IWorkbenchPage (API). > Ah ok I totally missed the cast, now I see. I just tried it and it works great! Unfortunately it is an internal non-API approach which means I can't use it.
I'm tagging this for a try at a fix in 3.5.1...
Created attachment 143779 [details] Patch to allow calling 'setState' on a minimized view reference If the reference is to a 'true' fast view (i.e. in the FastViewBar) then teh effect is to ensure that the FV is open (to avoid the NPE). If the reference is to a view in a minimized stack then it will react to the new state this way: MINIMIZED - No-op (it's already minimized) RESTORED - restores the stack to the presentation MAXIMIZED - restores the stack to the presentation and then maximizes it Note that this behavior manifests even if a minimized (rather than a 'true' fast) view is open. This difference is necessary because we can't 'restore' the FastViewBar.
Committed in >20090807. Applied the patch.
Verified in M20090826-1100.