Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320249 - Switching tabs with Ctrl+PgUp/Down doesn't grant focus to the part's control
Summary: Switching tabs with Ctrl+PgUp/Down doesn't grant focus to the part's control
Status: VERIFIED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 1.0 RC3   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-19 08:36 EDT by Remy Suen CLA
Modified: 2010-07-27 13:47 EDT (History)
5 users (show)

See Also:
emoffatt: review+


Attachments
Patch (1.06 KB, patch)
2010-07-19 11:47 EDT, Thomas Schindl CLA
no flags Details | Diff
patch (1.45 KB, patch)
2010-07-19 12:29 EDT, Thomas Schindl CLA
no flags Details | Diff
patch (1.81 KB, text/plain)
2010-07-19 12:30 EDT, Thomas Schindl CLA
no flags Details
updated patch as per suggestion (1.83 KB, patch)
2010-07-21 18:41 EDT, Boris Bokowski 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-19 08:36:21 EDT
1. Open an editor.
2. Place the cursor somewhere.
3. Open another editor.
4. Place the cursor somewhere.
5. Ctrl+PgUp to go back to the first editor.
6. You cannot start typing. You have to hit 'Tab' to switch focus to the editor's actual text control.
Comment 1 Remy Suen CLA 2010-07-19 11:29:01 EDT
You can also reproduce the problem when switching editor tabs with the mouse.

It seems that SWTPartRenderer's requiresFocus(MUIElement) method is returning 'false' when you swap tabs in a tab folder. This was added to support bug 319063.
Comment 2 Thomas Schindl CLA 2010-07-19 11:47:12 EDT
Created attachment 174638 [details]
Patch

I looked around a bit and made this modification to the PartServiceImpl. I guess it should activate a part when it is changed but I could be totally wrong because I have no ideas how this internals are working.

To me this fixes the activation problem.
Comment 3 Thomas Schindl CLA 2010-07-19 12:18:00 EDT
The real problem is in the SWTRenderer#requiresFocus() implementation which returns false when AbstractPartRender#activate(MPart) is called (which calls out to PartServiceImpl#activate(MPart,requireFocus))!

The patch only fixes the symptom. One more note on this is that PartServiceImpl#activate(MPart,requireFocus)) is called twice
Comment 4 Thomas Schindl CLA 2010-07-19 12:22:34 EDT
Overloading ContributedPart/StackRender#requireFocus() and returning true fixes the problem. 

I think the problem here is that when the internal event is processed for SWT the focus control is already our Editor and so we get false.
Comment 5 Thomas Schindl CLA 2010-07-19 12:29:37 EDT
Created attachment 174648 [details]
patch
Comment 6 Thomas Schindl CLA 2010-07-19 12:30:35 EDT
Created attachment 174649 [details]
patch
Comment 7 Remy Suen CLA 2010-07-19 12:57:50 EDT
I can't comment on the patch but do feel that the fix should be in the renderer code instead of the EPS.
Comment 8 Thomas Schindl CLA 2010-07-19 13:22:08 EDT
(In reply to comment #7)
> I can't comment on the patch but do feel that the fix should be in the renderer
> code instead of the EPS.

The last patch does the fix in the renderer!
Comment 9 Remy Suen CLA 2010-07-19 13:24:10 EDT
(In reply to comment #8)
> (In reply to comment #7)
> > I can't comment on the patch but do feel that the fix should be in the renderer
> > code instead of the EPS.
> 
> The last patch does the fix in the renderer!

Yes, I realize that.

What I meant was, "I can't comment on whether your new patch is correct or not but do agree that the fix belongs in the renderer".
Comment 10 Thomas Schindl CLA 2010-07-20 03:18:51 EDT
Eric, I think we need your input on this. As described earlier the problem is that the requiresFocus calculation is wrong when the editor is already created.

I fixed this by overloading this in ContributedPartRenderer while we are processing the activation event.
Comment 11 Boris Bokowski CLA 2010-07-20 18:06:01 EDT
Wouldn't it be safer if the code was something like the following?

+	protected boolean requiresFocus(MPart element) {
+		if (element == partToActivate) {
+			return true;
+		}
+		return super.requiresFocus(element);


 			((Composite) widget).addListener(SWT.Activate, new Listener() {
 				public void handleEvent(Event event) {
-					activate((MPart) me);
+					try {
+						partToActivate = me;
+						activate((MPart) me);
+					} finally {
+						partToActivate = null;
+					}
 				}
 			});
Comment 12 Thomas Schindl CLA 2010-07-20 18:07:49 EDT
Looks good.
Comment 13 Boris Bokowski CLA 2010-07-21 18:41:23 EDT
Created attachment 174928 [details]
updated patch as per suggestion
Comment 14 Eric Moffatt CLA 2010-07-21 20:51:32 EDT
beauty +1
Comment 15 Boris Bokowski CLA 2010-07-21 20:53:13 EDT
Committed to HEAD (I'm counting comment 12 as Tom's +1)
Comment 16 Thomas Schindl CLA 2010-07-22 08:21:25 EDT
There's still one very small activation problem. When you launch an already existing workbench the correct editor tab is restored but it is not activated (tab background white, no focus transfered to editor).

Should I file an extra defect for this?
Comment 17 Remy Suen CLA 2010-07-22 08:24:14 EDT
(In reply to comment #16)
> When you launch an already
> existing workbench the correct editor tab is restored but it is not activated
> (tab background white, no focus transfered to editor).

That's a general problem due to not having activation history. See bug 300742 and bug 320476.
Comment 18 Boris Bokowski CLA 2010-07-24 17:50:36 EDT
This one can be marked as fixed, right?
Comment 19 Thomas Schindl CLA 2010-07-24 17:53:25 EDT
yes
Comment 20 Remy Suen CLA 2010-07-27 13:47:15 EDT
Verified with I20100726-2152 on Windows XP.