Bug 348954 - Active Part is incorrect and does not have focus on a restart
Summary: Active Part is incorrect and does not have focus on a restart
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.1   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.4 M6   Edit
Assignee: Wojciech Sudol CLA
QA Contact: Wojciech Sudol CLA
URL:
Whiteboard: candidate43
Keywords: usability
: 328703 378645 384023 (view as bug list)
Depends on:
Blocks: 435421
  Show dependency tree
 
Reported: 2011-06-09 16:16 EDT by Eric Moffatt CLA
Modified: 2014-05-21 12:54 EDT (History)
10 users (show)

See Also:


Attachments
Patch with an initial cut at using the model's 'selectedElement' info (2.19 KB, patch)
2011-06-09 16:43 EDT, Eric Moffatt CLA
no flags Details | Diff
EPartService patch v2 (1.78 KB, patch)
2011-06-10 12:24 EDT, Remy Suen CLA
no flags Details | Diff
Remy's patch with code to attempt to re-active the last active part (3.36 KB, patch)
2011-06-10 14:31 EDT, Eric Moffatt CLA
no flags Details | Diff
New patch using tags to identify the active part (3.55 KB, patch)
2011-08-11 14:06 EDT, Eric Moffatt CLA
no flags Details | Diff
New patch that activates using the old PartService code (2.90 KB, patch)
2011-08-11 15:33 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 Eric Moffatt CLA 2011-06-09 16:16:40 EDT

    
Comment 1 Eric Moffatt CLA 2011-06-09 16:21:35 EDT
To reproduce:

open an inner, open an editor, make it the active part

shut down and restart

Note that the Package Explorer's stack indicates that it's the active part rather than the one that was active on the shutdown. Also, even though active the Tree doesn't have focus (it's actually on the Package Explorer stack's minimize button...

We should be to at least determine the part that was active on shutdown by following the MApplication's 'selectedElement' chain down to either an MPart or MPlaceholder.

Alternatively it may be OK (better?) to check if we can activate an open Editor.

This will surely be noticed by folks...
Comment 2 Eric Moffatt CLA 2011-06-09 16:43:30 EDT
Created attachment 197740 [details]
Patch with an initial cut at using the model's 'selectedElement' info
Comment 3 Remy Suen CLA 2011-06-10 10:55:43 EDT
(In reply to comment #2)
> Created attachment 197740 [details]
> Patch with an initial cut at using the model's 'selectedElement' info

I can confirm that this patch fixes the problem although it introduces a test failure.

When the perspective switching code was implemented I didn't want perspective switches to cause that window to become the active window as it didn't seem like such an operation should affect which part was the active part. It seems in 3.x switching perspectives of a window in the background will actually activate it and bring it to the foreground. I don't know if this is the behaviour we want in Eclipse 4 or not.
Comment 4 Remy Suen CLA 2011-06-10 12:24:11 EDT
Created attachment 197800 [details]
EPartService patch v2

This new patch removes the check so that the test no longer fails. I also removed the extra code that was added in PartActivationHistory as I am not comfortable with making changes in that code so late in the cycle.
Comment 5 Eric Moffatt CLA 2011-06-10 14:24:01 EDT
I'm OK with the patch as far as it goes but I think that we really should at least try to re-activate the part that was active on shutdown since it's an obvious flaw if we don't.

I do respect your concerns about changes in important code area like activationHistory...so I'll attach a patch with the 'selectedElement' code in it and we'll let McQ make the call...;-).
Comment 6 Eric Moffatt CLA 2011-06-10 14:31:19 EDT
Created attachment 197806 [details]
Remy's patch with code to attempt to re-active the last active part
Comment 7 Eric Moffatt CLA 2011-06-10 14:35:58 EDT
Remy I've +1'd your patch, could you take another look at mine (both to ensure that it contains your changes as well as the new code in PAH)?

The only real change from my original code is that I now fall through with null should the part that I find be TBR == false for whatever reason...
Comment 8 Eric Moffatt CLA 2011-06-10 14:46:59 EDT
It should be noted that the approach taken in the code in the PAH will *not* find the last active part if it was in a Detached window but will instead fall through to the old code...(at least we tried...;-).
Comment 9 Remy Suen CLA 2011-06-10 14:47:39 EDT
(In reply to comment #6)
> Created attachment 197806 [details]
> Remy's patch with code to attempt to re-active the last active part

If you minimize a view first and then have it activated and then go 'File > Restart', you will get the focus on a tool item when the workbench comes up again.
Comment 10 Eric Moffatt CLA 2011-06-10 15:12:33 EDT
kk, McQ's fine with your approach so we'll just skip mine (for now, we should revisit this post 4.1...)
Comment 11 Mike Wilson CLA 2011-06-10 15:17:27 EDT
-1 for putting this in for 4.1, we can think about it a bit more and do the right thing in 4.1.1
Comment 12 Eric Moffatt CLA 2011-06-10 15:35:44 EDT
Sure, no need to review my patch in that case...
Comment 13 Eric Moffatt CLA 2011-08-11 14:06:01 EDT
Created attachment 201339 [details]
New patch using tags to identify the active part
Comment 14 Remy Suen CLA 2011-08-11 14:14:11 EDT
(In reply to comment #13)
> Created attachment 201339 [details]
> New patch using tags to identify the active part

When I run the tests I get a test failure.

junit.framework.AssertionFailedError: expected:<org.eclipse.e4.ui.model.application.ui.basic.MWindow eclipse context> but was:<org.eclipse.e4.ui.model.application.ui.basic.MWindow eclipse context>
	at junit.framework.Assert.fail(Assert.java:47)
	at junit.framework.Assert.failNotEquals(Assert.java:283)
	at junit.framework.Assert.assertEquals(Assert.java:64)
	at junit.framework.Assert.assertEquals(Assert.java:71)
	at org.eclipse.e4.ui.tests.application.EPartServiceTest.testSwitchPerspective05(EPartServiceTest.java:10160)
Comment 15 Remy Suen CLA 2011-08-11 14:33:23 EDT
The active part doesn't come back if you have multiple workbench windows it seems.
Comment 16 Eric Moffatt CLA 2011-08-11 15:33:25 EDT
Created attachment 201346 [details]
New patch that activates using the old PartService code


Remy, this makes the test suite happy...

Why do we seem to have so many different (and subtle) ways to active something ??
Comment 17 Eric Moffatt CLA 2011-08-11 15:34:36 EDT
OK, second try...
Comment 18 Remy Suen CLA 2011-08-11 16:34:22 EDT
(In reply to comment #16)
> Created attachment 201346 [details]
> New patch that activates using the old PartService code
> 
> 
> Remy, this makes the test suite happy...

Confirmed on my end.

> Why do we seem to have so many different (and subtle) ways to active something
> ??

That code is to prevent an inactive window switching perspectives from becoming the active window.

(In reply to comment #15)
> The active part doesn't come back if you have multiple workbench windows it
> seems.

Please open a new bug for this issue if you don't intend to have it covered by this bug.

Otherwise, the code looks fine to me. I am not sure about declaring the tag as API. Do you expect clients to use this tag?
Comment 19 Paul Webster CLA 2011-11-01 12:14:15 EDT
Eric, should this still be considered for 4.1.2?

PW
Comment 20 Karl Weber CLA 2012-03-04 06:41:54 EST
As I understand, this is still not part of 4.2. I am not sure whether I understand the effect of this bug, but my pure e4 application is loosing SWT events:

If an MPart is dynamically created from an MPartDescriptor, the created composite receives the focus through the framework, i,e, one doesn't have to call composite.setFocus() oneself, neither in buildUI() nor in the @Forus method. In this case everything works as expected.

When the application is restarted, this MPart is fully visible, but neither the @Focus method nor the composite.setFocus() are called. Hence, the first SWT event, i.e. a click on a button in the composite, gets lost (I mean that, e.g., the SelectionListeners are not called). This first click only effects, that the @Focus method and the composite.setFocus() are called. Hence, one has to click twice on the button for, e.g., the SectionListeners to be called once. This is quite counterintuitive.
Comment 21 Remy Suen CLA 2012-03-12 11:29:19 EDT
(In reply to comment #20)
> When the application is restarted, this MPart is fully visible, but neither the
> @Focus method nor the composite.setFocus() are called. Hence, the first SWT
> event, i.e. a click on a button in the composite, gets lost (I mean that, e.g.,
> the SelectionListeners are not called). This first click only effects, that the
> @Focus method and the composite.setFocus() are called. Hence, one has to click
> twice on the button for, e.g., the SectionListeners to be called once. This is
> quite counterintuitive.

I just pushed a change to master, Karl. It fixes a problem where the @Focus is not called on startup. It may or may not solve the problem for you. If your application is still not working with this change, please open a new bug.
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=5926c3e628bd808c130379a1bcfd17322a729528
Comment 22 Dani Megert CLA 2012-04-18 03:53:03 EDT
It is a major usability issue if one does not see the focus after restart and if one can e.g. not continue typing in the editor one was in when exiting.

Can you please consider this for 4.2?
Comment 23 Lars Vogel CLA 2012-04-27 11:34:45 EDT
I agree with Dani, very inconvenient. I'm not sure but I think that would also impact Mylyn. Adding Steffen.
Comment 24 Oleg Besedin CLA 2012-05-07 09:49:27 EDT
*** Bug 378645 has been marked as a duplicate of this bug. ***
Comment 25 Eric Moffatt CLA 2012-06-22 10:38:51 EDT
commit e332177f7a8176558b5324bcadfff1475a42a25d (in pwebster/start_421)

Works for all cases where the part is in the main WBW's presentation.

Doesn't work if the active part is in a minimized stack or a DW yet...
Comment 26 Lars Vogel CLA 2012-07-02 06:26:41 EDT
Search seem to have problems with focus too, maybe the following bug is related: Bug 384023
Comment 27 Dani Megert CLA 2012-07-02 07:03:04 EDT
*** Bug 384023 has been marked as a duplicate of this bug. ***
Comment 28 Eric Moffatt CLA 2013-11-04 14:01:30 EST
Also see Bug 329458...editors should get precedence over views on startup...
Comment 29 Dani Megert CLA 2013-11-05 04:09:39 EST
*** Bug 328703 has been marked as a duplicate of this bug. ***
Comment 30 Wojciech Sudol CLA 2013-12-13 11:45:28 EST
The initial fix introduced by Eric has been later 'broken' by changes provided as fixes for two bugs:
1. bug 340695 - class org.eclipse.ui.internal.CoolBarToTrimManager
2. bug 375576 - class org.eclipse.jface.text.TextViewer
The changes are independent and both (separately) breaks Eric's fix. The breaking change from the bug 340695 has been already fixed in bug 416746.
Now I am trying to figure out whether the change introduced in the bug 375576 is the real cause of the problem or it only uncovered a problem located somewhere else.
Comment 31 Eric Moffatt CLA 2014-02-14 15:13:54 EST
Note: while working on this make sure to check that it correctly handles the initial state of split editors (bug 423894)...
Comment 32 Wojciech Sudol CLA 2014-02-20 09:01:43 EST
It turns out that the reason of the problem is similar to the one in bug 375576. When opening a shell in WBWRenderer, the layout of the shell is outdated because of multiple deferred layouts. As a result, the shell is being detected by SWT/OS as invisible, thus focus cannot restored. To force update of the layout I revert all deffered layouts and immediatelly restore them - the same fix is applied in the bug 375576.
As mentioned in the bug 375576, the root cause of the problems is extensive use of deferred layouts and optionally can be 'fixed' in SWT (BTW. is there any bug open for this issue?)

Review URL: https://git.eclipse.org/r/22302
Comment 33 Eric Moffatt CLA 2014-02-24 15:06:52 EST
Nice one Wojciech ! I've pushed this change:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=5479fbcb2d0fc973f1279341eb87570555a12c8c

The only thing we may want to do is to either remove the 'static' from the 'forceLayout' method or make it public (in case others need to force a layout), what do you think ?
Comment 34 Wojciech Sudol CLA 2014-02-24 16:07:41 EST
+1 for removing static. The fix is a kind of workaround, so I think the method should not be public. Also, I wonder if restoring the reverted deferred layout (the second loop) should be done after opening the shell. I will investigate it.
Comment 35 Eric Moffatt CLA 2014-02-25 15:52:56 EST
Please do investigate...I haven't seen anything bad with the new code so I feel pretty sure that it's OK but if the 'deferred' count goes up whenever we use a layout call with SWT.DEFERRED my guess is that it should go down once that layout has actually been done (meaning that we might be winding the stack up too much).

This might be worth making a SWT app based on one of the samples and having it be able to do both 'setlayoutDeferred' calls *and* having some composites that get their layouts with SWT.DEFER. Might be best to invent you own layout as well so that you can see when it actually runs...

Does it run when the deferred count goes to 0 ?
Comment 36 Dani Megert CLA 2014-02-26 07:10:48 EST
I agree that the fix can get some more polish, but wanted to mention that it works in N20140225-2000.
Comment 37 Eric Moffatt CLA 2014-02-26 10:33:57 EST
Thanks Dani... I'll remove the 'static' and mark this one fixed. 

 	
Wojciech, I've removed the 'static':

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=70990c140dfbcbba1f2bbf94840e795b48095f1c

Thanks for the fix :)

I'll mark this as fixed...if we discover anything bad about the unwinding / winding the 'deferred' state we'll re-open to fix it here...
Comment 38 Wojciech Sudol CLA 2014-02-26 13:21:35 EST
It is worth to mention that the bug did not occur with non-text editors (at least some of them). Forcing layout in the fix for the bug 375576, uncovered this bug.
Comment 39 Wojciech Sudol CLA 2014-03-04 03:57:18 EST
Verified in I20140303-2000.
Comment 40 Iwao AVE! CLA 2014-05-19 05:31:11 EDT
The fix seems to cause another bug 431966.
I am not sure where it should be fixed in, but would appreciate if you could take a look!