Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 348069

Summary: Closing an additional window of an Eclipse 4 application doesn't unrender it
Product: [Eclipse Project] Platform Reporter: Remy Suen <remy.suen>
Component: UIAssignee: Remy Suen <remy.suen>
Status: VERIFIED FIXED QA Contact: Eric Moffatt <emoffatt>
Severity: critical    
Priority: P3 CC: emoffatt, m.stier, Mike_Wilson, pwebster, tom.schindl
Version: 4.2Flags: Mike_Wilson: pmc_approved+
tom.schindl: review+
emoffatt: review+
Target Milestone: 4.2 M6   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 371087    
Attachments:
Description Flags
Window unrendering patch v1
none
Window unrendering patch v2
none
Window unrendering patch v3 none

Description Remy Suen CLA 2011-06-02 10:32:15 EDT
It seems that the @PD methods of parts in a closed window are not getting called when the request is invoked through the 'X' button in the trim of the shell.
Comment 1 Remy Suen CLA 2011-06-02 11:29:53 EDT
Created attachment 197237 [details]
Window unrendering patch v1

We change the renderer to always override the SWT request to close the window and then internally have the rendering engine unrender the window if the user confirms that this action should go through.

I don't feel comfortable removing the window from its parent unless it is the application because detached windows, certainly from a perspective point of view, should stick around.

The rendering engine's stop() method previous call to shell's stop() method ultimately meant that the windows would all be removed on shutdown, this is obviously not what we want to happen.
Comment 2 Remy Suen CLA 2011-06-02 11:30:42 EDT
(In reply to comment #1)
> Created attachment 197237 [details]
> Window unrendering patch v1

Eric, can you look at this patch?
Comment 3 Eric Moffatt CLA 2011-06-02 12:42:21 EDT
This looks fine to me as long as you're sure that it won't affect the current 4.1 code flow...(or unless it is fixing a leak in 4.1).
Comment 4 Remy Suen CLA 2011-06-02 13:18:32 EDT
Created attachment 197251 [details]
Window unrendering patch v2

(In reply to comment #3)
> This looks fine to me as long as you're sure that it won't affect the current
> 4.1 code flow...(or unless it is fixing a leak in 4.1).

Looking back at the original attachment, there is some amount of risk involved here so I'm attaching a newer one.

This new patch only changes the default IWindowCloseHandler implementation in the WBWRenderer. In WorkbenchWindow's setup() method, we set our own compatibility implementation into the context so the default handler is overridden so this does not affect the code path of the SDK at all.

Because windows are removed from the application now, a CME may occur in the rendering engine's stop() method (it gets thrown in the tests). While swapping it out for removeGui(MUIElement) is the proper way to close it, since the stop() method is called by the workbench on restart and other scenarios, I think it's best to leave the method as is and just wrap the returned list in an array list to prevent the CME and let it continue to do what it has always done.
Comment 5 Remy Suen CLA 2011-06-02 13:19:10 EDT
(In reply to comment #4)
> Created attachment 197251 [details]
> Window unrendering patch v2

Eric or Paul, could you review this new patch?
Comment 6 Paul Webster CLA 2011-06-03 07:56:38 EDT
Looks safer.
PW
Comment 7 Remy Suen CLA 2011-06-03 08:02:21 EDT
(In reply to comment #6)
> Looks safer.

Thanks, patch released to CVS HEAD.
Comment 8 Remy Suen CLA 2011-06-06 09:53:51 EDT
Verified with I20110604-2201 on Windows XP.

The new test is also in the build's test results page.
Comment 9 Thomas Schindl CLA 2011-06-10 03:46:06 EDT
This changes causes an e4 application to not restore after the first shutdown. I think the removal and setting of rendering to false should only happen when a window is closed manually and not as part of the shutdown of the application.

I me thinks we should rollback the change and live with the none removal of windows and fix it in 4.2 and/or 4.1.2
Comment 10 Remy Suen CLA 2011-06-10 06:40:02 EDT
(In reply to comment #9)
> This changes causes an e4 application to not restore after the first shutdown.
> I think the removal and setting of rendering to false should only happen when a
> window is closed manually and not as part of the shutdown of the application.

How embarrassing. We should actually be calling removeGui(*) on the windows instead of just closing the shells (or at least dispose the shells so that an SWT.Close event is not sent). I guess my first patch was better.

> I me thinks we should rollback the change and live with the none removal of
> windows and fix it in 4.2 and/or 4.1.2

Not automatically removing the windows is a minor nuisance to me but leaking the entire structure of a window is rather disturbing to me.
Comment 11 Remy Suen CLA 2011-06-10 09:08:48 EDT
Created attachment 197773 [details]
Window unrendering patch v3

This patch reverts the changes from attachment 197251 [details] in WBWRenderer and PartRenderingEngine. It also removes the three tests that were added in that patch.
Comment 12 Remy Suen CLA 2011-06-10 09:09:39 EDT
(In reply to comment #11)
> Created attachment 197773 [details]
> Window unrendering patch v3

Eric and Tom, please review this patch revert, thanks.
Comment 13 Thomas Schindl CLA 2011-06-10 09:14:17 EDT
Confirm that the application can be started from a retored state.
Comment 14 Eric Moffatt CLA 2011-06-10 09:36:10 EDT
Remy, the reversion looks fine. I think I see where the original issue arose...

Rather than calling window.setToBeRendered(false) we should be calling removeGui. Also, the test to remove the window should only affect all but the last one (sort of like 'isLastEditorStack)...

Go to go from me +1
Comment 15 Mike Wilson CLA 2011-06-10 11:06:08 EDT
+1 for reverting the change. Need to provide a real fix for 4.1.1.
Comment 16 Remy Suen CLA 2011-06-10 11:13:58 EDT
(In reply to comment #11)
> Created attachment 197773 [details]
> Window unrendering patch v3

Patch released to HEAD. Thanks everyone.
Comment 17 Thomas Schindl CLA 2011-10-04 03:53:20 EDT
Just because it came up in the newsgroup today. Can we revisit this bug to properly handle @PD
Comment 18 Remy Suen CLA 2011-10-04 08:14:38 EDT
(In reply to comment #17)
> Just because it came up in the newsgroup today. Can we revisit this bug to
> properly handle @PD

Tom, when the user closes a top-level window, should it be removed from the application's list of children? And if it was removed from a window's or a perspective's list of child windows, should it be removed from that list?
Comment 19 Remy Suen CLA 2011-11-17 09:49:54 EST
Tom, what do you think about comment 18?
Comment 20 Remy Suen CLA 2012-01-23 08:56:22 EST
(In reply to comment #18)
> Tom, when the user closes a top-level window, should it be removed from the
> application's list of children? And if it was removed from a window's or a
> perspective's list of child windows, should it be removed from that list?

I would say that the window should be removed from the list in both cases. What do you think, Tom?
Comment 21 Eric Moffatt CLA 2012-02-06 09:54:23 EST
Top-level windows that are closed manually (i.e. hitting the red 'x') should be set to TBR false (to get them unrendered) and then removed from the app's list.

DW's are slightly different...it's ok for one to become TBR false if, for example, all its views are closed. In this case the choice of removing from its perspective's list should be based on whether it's 'empty' (i.e. contains no views or placeholders). If it becomes empty (the user drags the last view out of it) then it should be removed. Otherwise it has to be left in the list so that a subsequent open of a view will re-expose it...
Comment 22 Thomas Schindl CLA 2012-02-09 10:41:59 EST
I guess I agree with Eric and his conclusion - I'd like to get a fix for this in M6 to fill the EAP gap in bug #371087
Comment 23 Thomas Schindl CLA 2012-02-09 10:44:28 EST
Rereading this I'm not sure I still agree because removing it from the app-list would put us in the same situation we've run into 4.1 where on restart there's no window anymore in the application
Comment 24 Eric Moffatt CLA 2012-02-09 11:20:14 EST
I missed a condition in my previous comment...

...Except where a lop-level window closed through 'x' is the *last* top-level window. In this case it should be left as TBR true (but still have removeGui called on it.
Comment 25 Thomas Schindl CLA 2012-02-09 12:58:03 EST
That's sounds correct - this would be in alignment of the patch in bug 371087, right?
Comment 26 Thomas Schindl CLA 2012-02-10 06:28:29 EST
Just one more note on why this is important beside - this will lead to memory leaks because the clean up of instance objects in only done in the PREngine and if this code is not run the memory will be leaked.

I don't know if this also the case for the Compat Layer but for EAP-Apps this is certainly the case.
Comment 27 Remy Suen CLA 2012-02-10 15:15:46 EST
Fix pushed to master.
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=81e764b3b98e971702e955b15c6ac7f3997e071b

Thank you everyone for their patience.
Comment 28 Remy Suen CLA 2012-03-13 10:06:29 EDT
Marking as VERIFIED. Tom told me previously that it's "working like a charm".