This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 411750 - [Contributions] IFocusService not working with dialog when closing with ESC or red X
Summary: [Contributions] IFocusService not working with dialog when closing with ESC o...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8.2   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: 4.4 M3   Edit
Assignee: Paul Webster CLA
QA Contact: Daniel Rolka CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-27 05:12 EDT by Markus Krüger CLA
Modified: 2013-10-29 13:58 EDT (History)
1 user (show)

See Also:


Attachments
bug.app (14.80 KB, application/x-zip-compressed)
2013-06-27 05:12 EDT, Markus Krüger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Krüger CLA 2013-06-27 05:12:14 EDT
Created attachment 232832 [details]
bug.app

We use the IFocusService within dialogs and wizards to enanble or diable commands within its tables or trees. No we noticed, that the focus tracking does lead to not wanted behavior when closing a dialog or wizard with ESC or the red X.

As an example I attached an RCP demo:
There is commandId "bug.app.command.focusid" and two handlers for it.
The behavior of the first handler is to open a dialog which adds a focustracker on a text control and the behavior of the second handler using the activeFocusControlId of the text control is to print "FocusIdHandler2".
Now if you open the dialog by using the context menu to execute the first handler the dialog opens and the focus is on the text control which activates the second handler. If you close the dialog with ESC or the red X and afterwards click on the hander in the contextmenu again then the second handler is still active and prints "FocusIdHandler2".

I found the reasen for that by digging a little deeper into "org.eclipse.ui.internal.menus.FocusControlSourceProvider".
The FocusControlSourceProvider uses "focusLost" to reset the current focus control and its id. Using the buttons of the dialog triggers the focus lost event and so everthing works fine. Since using ESC or the red X of the dialog does not trigger a focus lost event the current focus control and its id will not be cleared. 
There is also a DisposeListener in the FocusControlSourceProvider which gets triggered, but it does just remove the disposed control form a map and does not reset the current focus control and its id.

The solution is to change the code in widgetDisposed to:

String id = controlToId.remove(control);
if (currentId == id) {
	currentId = null;
	currentControl = null;
	fireSourceChanged(ISources.ACTIVE_MENU, getCurrentState());
}


Hope that was not too much text :-)
Comment 2 Paul Webster CLA 2013-10-29 13:58:28 EDT
In 4.4.0.I20131028-2000

PW