Bug 528251 - View tab not highlighted due to another view with a CTabFolder
Summary: View tab not highlighted due to another view with a CTabFolder
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.7.3   Edit
Assignee: Simeon Andreev CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-12-07 05:17 EST by Simeon Andreev CLA
Modified: 2018-02-20 11:36 EST (History)
6 users (show)

See Also:


Attachments
A plug-in with which the problem can be reproduced. (5.14 KB, application/zip)
2017-12-07 05:17 EST, Simeon Andreev CLA
no flags Details
A selected tab, with a view that defines a CTabFolder component. (42.80 KB, image/png)
2017-12-07 05:18 EST, Simeon Andreev CLA
no flags Details
Selecting another view's tab results in no highlighting. (46.36 KB, image/png)
2017-12-07 05:18 EST, Simeon Andreev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Andreev CLA 2017-12-07 05:17:31 EST
Created attachment 271803 [details]
A plug-in with which the problem can be reproduced.

The problem is observed if a view in a view part stack defines a CTabFolder child. See attached screenshots.

The view with the CTabFolder is highlighted as expected. Other views in the same part stack however will not be highlighted on click.

Pressing a button (e.g. print screen) or some clicks in a not-highlighted (but active) view will highlight the view tab.


Steps to reproduce:

1. Import plug-in from attachment.
2. Debug Eclipse.
3. Open "Sample View" and another view in the same part stack.
4. Click on the "Sample View", then on the other view.
5. Observe that the other view is not highlighted.

Or:

1. Create plug-in with default Sample View for 4.x
2. Add a CTabFolder to the view contents.
3. Debug Eclipse.
4. Open "Sample View" and another view in the same part stack.
5. Click on the "Sample View", then on the other view.
6. Observe that the other view is not highlighted.

Note that "theming" must be disabled to reproduce the problem (Window -> Preferences -> General -> Appearance -> ensure enable theming is off, restart Eclipse).


Environment:

RHEL 7.2, GTK 3.14 (gtk3-3.14.13-16.el7.x86_64)

Eclipse SDK

Version: Photon (4.8)
Build id: I20171129-2000
Comment 1 Simeon Andreev CLA 2017-12-07 05:18:06 EST
Created attachment 271804 [details]
A selected tab, with a view that defines a CTabFolder component.
Comment 2 Simeon Andreev CLA 2017-12-07 05:18:44 EST
Created attachment 271805 [details]
Selecting another view's tab results in no highlighting.
Comment 3 Simeon Andreev CLA 2017-12-07 05:20:23 EST
The Console / Sample Views tabs in the bottom part stack are the interesting part of the screenshot. I forgot to mark the area in the screenshots.
Comment 4 Simeon Andreev CLA 2017-12-07 05:25:16 EST
During debugging I observed that the CTabFolder of the part stack will normally (without a CTabFolder in the view) receive an onActivate(), onPaint(), onDeactivate(), onPaint() sequence.

I'm guessing the onActivate() and onPaint() are for the tab which was clicked, and the onDeactivate() and onPaint() come for the tab which is no longer active. 


With a CTabFolder in the active view, the CTabFolder of the part stack will receive only onActivate(), onDeactivate(), onPaint(). I.e. it doesn't repaint the (now) active tab.
Comment 5 Simeon Andreev CLA 2017-12-07 05:27:49 EST
View code:

public class SampleView {
	private CTabFolder subtabs;

	@PostConstruct
	public void createPartControl(Composite parent) {
		subtabs = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT);
	}

	@Focus
	public void setFocus() {
		subtabs.setFocus();
	}
}

Note that delegating the focus to the child CTabFolder is essential to observe the problem.
Comment 6 Simeon Andreev CLA 2017-12-07 08:48:06 EST
Disregard comment #4, the not-highlighted tab doesn't receive CTabFolder.onActivation.

Switching from one Eclipse to the other Eclipse (due to breakpoint activation) resulted on an onActivation call.
Comment 7 Alexander Kurtakov CLA 2017-12-07 10:57:02 EST
Mickael, this is smth you worked on. Please investigate.
Comment 8 Simeon Andreev CLA 2017-12-07 11:05:16 EST
Hi Alexander, Mickael,

the fix for Bug 474444 introduces this regression.

Our application has a number of views which make use of CTabFolders. If one of those views is active, clicking on another view in the same part stack does not result in a highlight.

This is very awkward: the view becomes active and works as expected, but the user is uncertain if this is the case.

After some debugging, we saw that a CTabFolder will propagate all the way to the part stack tab folder, whether tabs should be highlighted. This is part of the changes introduced cor Bug 474444. Namely, in org.eclipse.swt.custom.CTabFolder:

void onDeactivate(Event event) {
	if (!highlightEnabled) {
		return;
	}
	Composite current = this;
	while (current != null) {
		if (current instanceof CTabFolder) {
			((CTabFolder) current).highlight = false;
		}
		current = current.getParent();
		current = null;
	}
	redraw();
}

void onActivate(Event event) {
	if (!highlightEnabled) {
		return;
	}
	Composite current = this;
	while (current != null) {
		if (current instanceof CTabFolder) {
			((CTabFolder) current).highlight = true;
		}
		current = current.getParent();
		current = null;
	}
	redraw();
}


Switching to another tab deactivates CTabFolders in the current view. However the tab folder of the part stack itself does not become activated. This seems to be done in org.eclipse.swt.widgets.Shell.setActiveControl:

void setActiveControl (Control control, int type) {
	if (control != null && control.isDisposed ()) control = null;
	if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
	if (lastActive == control) return;

	/*
	* Compute the list of controls to be activated and
	* deactivated by finding the first common parent
	* control.
	*/
	Control [] activate = (control == null) ? new Control[0] : control.getPath ();
	Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
	lastActive = control;
	int index = 0, length = Math.min (activate.length, deactivate.length);
	while (index < length) {
		if (activate [index] != deactivate [index]) break;
		index++;
	}

	/*
	* It is possible (but unlikely), that application
	* code could have destroyed some of the widgets. If
	* this happens, keep processing those widgets that
	* are not disposed.
	*/
	for (int i=deactivate.length-1; i>=index; --i) {
		if (!deactivate [i].isDisposed ()) {
			deactivate [i].sendEvent (SWT.Deactivate);
		}
	}
	for (int i=activate.length-1; i>=index; --i) {
		if (!activate [i].isDisposed ()) {
			Event event = new Event ();
			event.detail = type;
			activate [i].sendEvent (SWT.Activate, event);
		}
	}
}

The result is as described. A nested tab will tell the part stack tabs to not show highlighting.

Clicking on other part stacks and back shows highlighting as expected. This is an issue only within a single part stack.

What can be done here to fix the regression?


Best regards,
Simeon
Comment 9 Alexander Kurtakov CLA 2017-12-07 11:08:48 EST
Right a Junit test to verify that once fixed this doesn't get broken again. A patch which fixes it would be nice too.
Comment 10 Eclipse Genie CLA 2017-12-11 05:45:04 EST
New Gerrit change created: https://git.eclipse.org/r/113138
Comment 11 Andrey Loskutov CLA 2017-12-11 07:42:47 EST
It would be nice to get this into 4.7.3.
Comment 12 Alexander Kurtakov CLA 2017-12-11 08:00:46 EST
Eric, would you please review this one?
Comment 13 Mickael Istria CLA 2017-12-11 08:11:09 EST
IIRC, the use-case in bug 474444 comment 25 is the one that was worth the most care when implementing/reviewing.
Comment 14 Mickael Istria CLA 2017-12-11 08:14:38 EST
I also have the impression that the issue you see happens because the Deactivate events happen after the Activate events (so deactivate removes highlights set by activate). Is it something we should expect in general or could it be a deeper bug in the event creation/processing?
Comment 15 Andrey Loskutov CLA 2017-12-11 08:19:20 EST
(In reply to Mickael Istria from comment #13)
> IIRC, the use-case in bug 474444 comment 25 is the one that was worth the
> most care when implementing/reviewing.

Right now (SWT master) exact the opposite use case is broken. As soon as we have plugin editor opened (we have "tabs in tabs"), switching to another editor in the same editor area *disables* the editor tab highlighting. With the proposed patch everything seems to work again.
Comment 16 Andrey Loskutov CLA 2017-12-11 08:26:46 EST
In general, the original part of the patch which traverses all CTabFolder parents and changes their ".highlight" flags is a "no go" inside SWT from my point of view. 

A child widget should not make any changes to the parents, this is something out of the child scope. This could easily lead to all kinds of unexpected side effects including stack overflows and endless repaints. Just put few of such "clever" children to a common parent and the results could be unpredictable.

Such changes could be done in the application code, where we render something in a specific context (activate a view in a stack), but not inside the concrete widget, which should never know if it is in a stack or not.
Comment 17 Eric Williams CLA 2017-12-11 10:05:19 EST
(In reply to Alexander Kurtakov from comment #12)
> Eric, would you please review this one?

Will do.
Comment 18 Eclipse Genie CLA 2017-12-12 14:36:01 EST
New Gerrit change created: https://git.eclipse.org/r/113210
Comment 20 Eric Williams CLA 2017-12-12 15:47:41 EST
(In reply to Eclipse Genie from comment #19)
> Gerrit change https://git.eclipse.org/r/113138 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=23a636dd535cf5d034a32c01f3b70238ac237533

In master now, thanks for the patch!
Comment 21 Andrey Loskutov CLA 2017-12-12 15:48:35 EST
I would like to backport the patch to 4.7.3.
Comment 22 Eric Williams CLA 2017-12-12 15:51:51 EST
(In reply to Andrey Loskutov from comment #21)
> I would like to backport the patch to 4.7.3.

Please prepare a patch against the maintenance branch. 

I'd like the current fix to sit in master for about a week just to make sure there are no unforeseen issues. Then I would be happy to merge the backport.
Comment 23 Eclipse Genie CLA 2017-12-13 02:30:15 EST
New Gerrit change created: https://git.eclipse.org/r/113297
Comment 24 Andrey Loskutov CLA 2017-12-13 02:31:23 EST
(In reply to Eric Williams from comment #22)
> (In reply to Andrey Loskutov from comment #21)
> > I would like to backport the patch to 4.7.3.
> 
> Please prepare a patch against the maintenance branch. 

Here is it: https://git.eclipse.org/r/113297

> I'd like the current fix to sit in master for about a week just to make sure
> there are no unforeseen issues. Then I would be happy to merge the backport.

Sure.
Comment 25 Eclipse Genie CLA 2017-12-13 02:49:12 EST
New Gerrit change created: https://git.eclipse.org/r/113301
Comment 27 Eric Williams CLA 2017-12-13 11:43:12 EST
(In reply to Eclipse Genie from comment #26)
> Gerrit change https://git.eclipse.org/r/113210 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=fc22ad835b303358b44053dbf13b338315828ee6

Test cases have been merged.
Comment 29 Eclipse Genie CLA 2018-01-04 10:49:00 EST
New Gerrit change created: https://git.eclipse.org/r/114953
Comment 32 Eric Williams CLA 2018-01-05 10:21:12 EST
(In reply to Eclipse Genie from comment #31)
> Gerrit change https://git.eclipse.org/r/113297 was merged to
> [R4_7_maintenance].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=08ea543810619de5ab631ec2caca8ea2b5f5b7bc

Changes have been backported to 4.7.3.
Comment 33 Lakshmi P Shanmugam CLA 2018-02-16 01:05:35 EST
Andrey/Eric, can you please verify the fix with the latest 4.7.3 M-build?
Comment 34 Dani Megert CLA 2018-02-20 11:25:10 EST
(In reply to Lakshmi Shanmugam from comment #33)
> Andrey/Eric, can you please verify the fix with the latest 4.7.3 M-build?

Ping!
Comment 35 Dani Megert CLA 2018-02-20 11:26:52 EST
(In reply to Dani Megert from comment #34)
> (In reply to Lakshmi Shanmugam from comment #33)
> > Andrey/Eric, can you please verify the fix with the latest 4.7.3 M-build?
> 
> Ping!

I just saw you marked it as VERIFIED. Usually we add a comment where we say with which build it was verified.
Comment 36 Eric Williams CLA 2018-02-20 11:36:41 EST
(In reply to Dani Megert from comment #35)
> (In reply to Dani Megert from comment #34)
> > (In reply to Lakshmi Shanmugam from comment #33)
> > > Andrey/Eric, can you please verify the fix with the latest 4.7.3 M-build?
> > 
> > Ping!
> 
> I just saw you marked it as VERIFIED. Usually we add a comment where we say
> with which build it was verified.

Verified in M20180214-1700.