Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320655 - Closing last perspective hoses editor area if it has an editor
Summary: Closing last perspective hoses editor area if it has an editor
Status: RESOLVED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 1.0 RC3   Edit
Assignee: Eric Moffatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-22 13:48 EDT by Remy Suen CLA
Modified: 2010-07-27 13:41 EDT (History)
2 users (show)

See Also:
remy.suen: review+
susan: review+


Attachments
Don't hide the last editor stack on a perspective close (1.67 KB, patch)
2010-07-22 15:59 EDT, Eric Moffatt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2010-07-22 13:48:07 EDT
1. Wipe your deltas.
2. Launch your inner.
3. File > New > Untitled Text File
4. Window > Close Perspective
5. Window > Open Perspective > Other... > Java
6. The perspective returns without an editor area.

java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon$2.handleEvent(MinMaxAddon.java:131)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:41)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:188)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:198)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:139)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:73)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
	at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java:134)
	at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java:1)
	at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:2358)
	at org.eclipse.ui.internal.WorkbenchWindow.openPage(WorkbenchWindow.java:1516)
	at org.eclipse.ui.handlers.ShowPerspectiveHandler.openPerspective(ShowPerspectiveHandler.java:150)
	at org.eclipse.ui.handlers.ShowPerspectiveHandler.openOther(ShowPerspectiveHandler.java:118)
	at org.eclipse.ui.handlers.ShowPerspectiveHandler.execute(ShowPerspectiveHandler.java:57)
Comment 1 Remy Suen CLA 2010-07-22 13:51:15 EDT
This is also reproducible on I20100721-2056. Resetting does _not_ help.
Comment 2 Susan McCourt CLA 2010-07-22 14:10:08 EDT
Confirmed on Win7, I20100721-2056.
It seems as if it doesn't matter how many perspectives you have open, etc.
If you close the last one and it has an editor in it, you are hosed.
Comment 3 Susan McCourt CLA 2010-07-22 14:22:11 EDT
Remy, recall that in bug 319870 comment 7, we had a case where closing all perspectives left the editor area hanging around.  Could our fix for that bug have introduced this?
Comment 4 Remy Suen CLA 2010-07-22 14:29:33 EDT
(In reply to comment #3)
> Could our fix for that bug have introduced this?

The old code just closed parts without ever removing the editor area (which is why it stuck around) so it is technically possible that might've changed something.
Comment 5 Susan McCourt CLA 2010-07-22 14:41:11 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > Could our fix for that bug have introduced this?
> 
> The old code just closed parts without ever removing the editor area (which is
> why it stuck around) so it is technically possible that might've changed
> something.

This is definitely a regression.  It didn't completely work before, but it was better.  I just tried I20100718-2237 (because I happen to have the zip lying around) and here's what happens.

1. Wipe your deltas.
2. Launch your SDK.
3. Open a file
4. Window > Close Perspective
5. Window > Open Perspective > Other... > Java
6. The perspective returns *with an empty editor area*

(you can still open the file again, etc.  not too hosed.)
Comment 6 Eric Moffatt CLA 2010-07-22 15:59:52 EDT
Created attachment 175017 [details]
Don't hide the last editor stack on a perspective close


This is a corner case where the last perspective has already unhooked its shared elements (in this case including the EA). This causes a deep search starting from the window to fail to find the shared EA (and consequently any of its stacks).

In the interests of the least code change I've left the original search in place and handle this corner in new code specifically invoked under this condition.

Note that if you split the editor area before the close all stacks but one will be closed / removed.
Comment 7 Remy Suen CLA 2010-07-22 16:22:54 EDT
(In reply to comment #6)
> Created an attachment (id=175017) [details]
> Don't hide the last editor stack on a perspective close

The inlined comment doesn't seem to match what's happening in the code.

// So we'll try to walk up to the top of the editor stack's containment
// model and search there
if (editorStacks.size() == 0) {
  MUIElement container = element;
  while (container.getParent() != null) {
    container = container.getParent();
  }

In the code above, we don't actually "walk up to the top" of the containment model because if container.getParent() isn't null, the while loop will just run once and it'll be done.

Could you fix the inlined comment, Eric? Thanks.
Comment 8 Susan McCourt CLA 2010-07-22 16:47:05 EDT
+1 for RC3.
I agree with the approach to just search again (surgical fix), but I'd like to see the bug number included in the comment that explains why we are doing this.

(In reply to comment #7)

> The inlined comment doesn't seem to match what's happening in the code.
> 
> // So we'll try to walk up to the top of the editor stack's containment
> // model and search there
> if (editorStacks.size() == 0) {
>   MUIElement container = element;
>   while (container.getParent() != null) {
>     container = container.getParent();
>   }
> 
> In the code above, we don't actually "walk up to the top" of the containment
> model because if container.getParent() isn't null, the while loop will just run
> once and it'll be done.
> 
> Could you fix the inlined comment, Eric? Thanks.

???
I read this as doing just what it says.  It will walk up the parent refs until it reaches a null parent.  So it will search from the top of the stack's containment model.  If container.getParent() isn't null, container will be reassigned to the parent until the walk continues.  

(Or do I need more caffeine?)
Comment 9 Eric Moffatt CLA 2010-07-22 16:49:41 EDT
Remy, we have to walk all the way up to the 'shared element' (whose 'getParent' == null because it's not in the children list) because we could be dealing with an editor stack some number of sashes deep in a split editor area...

I'll change it to something like:

Walk up the containment hierachy, getParent == null indicates that this is the MpartSashContainer representing the EA.
Comment 10 Eric Moffatt CLA 2010-07-22 16:51:33 EDT
Committed in >20100722. Applied the patch.
Comment 11 Eric Moffatt CLA 2010-07-22 16:52:09 EDT
Marking as fixed.
Comment 12 Remy Suen CLA 2010-07-22 16:53:09 EDT
(In reply to comment #8)
> I read this as doing just what it says.

I think when I was debugging it only "looped" once which was causing my confusion. But yes, after looking at the code again, the code matches the comment.
Comment 13 Eric Moffatt CLA 2010-07-22 16:53:44 EDT
Susan, I've added the bug number to the comment...
Comment 14 Eric Moffatt CLA 2010-07-27 13:41:57 EDT
Verified on XP in I20100726-2152.