Bug 18303 - [Dialogs] MessageDialog: default button not honored
Summary: [Dialogs] MessageDialog: default button not honored
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Susan McCourt CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate
Depends on:
Blocks: 18072
  Show dependency tree
 
Reported: 2002-05-30 09:32 EDT by Dirk Baeumer CLA
Modified: 2007-06-28 14:53 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2002-05-30 09:32:43 EDT
F1+

I need question dialog with No as the default button. I create the dialog with

MessageDialog dialog = new MessageDialog(
	fParent, getDialogTitle(),  null,
	RefactoringMessages.getString
("SurroundWithTryCatchAction.no_exceptions"), //$NON-NLS-1$
	MessageDialog.QUESTION, 
	new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 
	1); 

But the Yes button is still the default button. Problem is that SWT set the 
focus to the first button when a shell gets opened. This also makes it the 
default button. Here is that stack trace:

Thread [main] (Suspended (breakpoint at line 747 in 
org.eclipse.swt.widgets.Decorations))
	org.eclipse.swt.widgets.Shell
(org.eclipse.swt.widgets.Decorations).setDefaultButton
(org.eclipse.swt.widgets.Button, boolean) line: 747
	org.eclipse.swt.widgets.Button.WM_SETFOCUS(int, int) line: 618
	org.eclipse.swt.widgets.Button
(org.eclipse.swt.widgets.Control).windowProc(int, int, int) line: 2714
	org.eclipse.swt.widgets.Display.windowProc(int, int, int, int) line: 
1984
	org.eclipse.swt.internal.win32.OS.SetFocus(int) line: not available 
[native method]
	org.eclipse.swt.widgets.Button
(org.eclipse.swt.widgets.Control).forceFocus() line: 566
	org.eclipse.swt.widgets.Button(org.eclipse.swt.widgets.Control).setFocus
() line: 1891
	org.eclipse.swt.widgets.Button.setFocus() line: 434
	org.eclipse.swt.widgets.Button
(org.eclipse.swt.widgets.Control).setTabItemFocus() line: 2186
	org.eclipse.swt.widgets.Button
(org.eclipse.swt.widgets.Control).setTabGroupFocus() line: 2181
	org.eclipse.swt.widgets.Shell
(org.eclipse.swt.widgets.Control).traverseGroup(boolean) line: 2523
	org.eclipse.swt.widgets.Shell.open() line: 613
	org.eclipse.jface.dialogs.MessageDialog
(org.eclipse.jface.window.Window).open() line: 534
	org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction$Query.catchRuntime
Exception() line: 68
	org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatc
hAnalyzer.endVisit(org.eclipse.jdt.core.dom.CompilationUnit) line: 81
	org.eclipse.jdt.core.dom.CompilationUnit.accept0
(org.eclipse.jdt.core.dom.ASTVisitor) line: 147
	org.eclipse.jdt.core.dom.CompilationUnit
(org.eclipse.jdt.core.dom.ASTNode).accept(org.eclipse.jdt.core.dom.ASTVisitor) 
line: 1330
	org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatc
hRefactoring.checkActivationBasics(org.eclipse.jdt.core.dom.CompilationUnit, 
org.eclipse.core.runtime.IProgressMonitor) line: 113
	org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatc
hRefactoring.checkActivation(org.eclipse.core.runtime.IProgressMonitor) line: 
130
	org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction.run
(org.eclipse.jface.text.ITextSelection) line: 90
	org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction
(org.eclipse.jdt.ui.actions.SelectionDispatchAction).dispatchRun
(org.eclipse.jface.viewers.ISelection) line: 180
	org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction
(org.eclipse.jdt.ui.actions.SelectionDispatchAction).run() line: 156
	org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction
(org.eclipse.jface.action.Action).runWithEvent(org.eclipse.swt.widgets.Event) 
line: 590
	org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection
(org.eclipse.swt.widgets.Event) line: 407
	org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent
(org.eclipse.swt.widgets.Event) line: 361
	org.eclipse.jface.action.ActionContributionItem.access$0
(org.eclipse.jface.action.ActionContributionItem, 
org.eclipse.swt.widgets.Event) line: 352
	org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEve
nt(org.eclipse.swt.widgets.Event) line: 47
	org.eclipse.swt.widgets.EventTable.sendEvent
(org.eclipse.swt.widgets.Event) line: 75
	org.eclipse.swt.widgets.MenuItem
(org.eclipse.swt.widgets.Widget).sendEvent(org.eclipse.swt.widgets.Event) line: 
825
	org.eclipse.swt.widgets.Display.runDeferredEvents() line: 1527
	org.eclipse.swt.widgets.Display.readAndDispatch() line: 1289
	org.eclipse.ui.internal.Workbench.runEventLoop() line: 1085
	org.eclipse.ui.internal.Workbench.run(java.lang.Object) line: 1068
	org.eclipse.core.internal.boot.InternalBootLoader.run(java.lang.String, 
java.net.URL, java.lang.String, java.lang.String[], java.lang.Runnable) line: 
739
	org.eclipse.core.boot.BootLoader.run(java.lang.String, java.net.URL, 
java.lang.String, java.lang.String[]) line: 432
	EclipseRuntimeLauncher.main(java.lang.String[]) line: 24
Comment 1 Tod Creasey CLA 2002-05-30 11:07:54 EDT
May be related to Bug 16254
Comment 2 Nick Edgar CLA 2002-05-30 15:00:13 EDT
Eduardo, is this the same problem that you had with the error dialog?
Please reassign to SWT if so.
Comment 3 Eduardo Pereira CLA 2002-05-30 15:33:37 EDT
Yes, this is the same problem. 

The initial attempt to fix it was to set the focus to the default button if it 
was not set to anything else. SWT should/could set the focus to the default 
button if it has to be set to a button.

See bug 14668
Comment 4 Nick Edgar CLA 2002-05-30 20:50:59 EDT
The initial focus should -not- be set to the button, even if it is the default.
Almost all our dialogs rely on the initial focus being the first control in 
the shell that can take it.
Comment 5 Mike Wilson CLA 2002-06-07 09:24:42 EDT
Not sure if there is anything we can do about this. SN to investigate. 
Comment 6 Nick Edgar CLA 2002-06-07 09:30:38 EDT
I don't think this is critical for 2.0, and is a potentially risky change to 
SWT.
I suggest we defer it.

Comment 7 Steve Northover CLA 2002-06-07 10:21:38 EDT
This is not an SWT problem.  On most platforms including Windows, when a button 
gets focus, it becomes the default button, temporarily clearing the original 
default button until focus is lost to another widget that is not a button.

Here is what SWT would have to do:  Detect the case when no initial focus has 
been set in the shell and there are only button widgets in the shell and the 
application has defined a default button, then set focus to that button.  Not a 
good thing for a portable widget toolkit to do.

The correct thing is for the application code to always set focus to the 
control that should have focus before the shell opens.  In this case, the 
control would be the default button.
Comment 8 Dirk Baeumer CLA 2002-06-07 10:35:43 EDT
Reopened and moved back to Workbench. 

IMO for message dialogs the corresponding code could set the focus to the 
provided default button and everything should work.
Comment 9 Nick Edgar CLA 2002-06-07 12:46:53 EDT
MessageDialog allows subclasses to add extra controls before the buttons by 
overriding createCustomArea.  In the SDK there are several subclasses which do 
this.
If we changed it to set focus on the default button, then that could 
potentially break the initial focus for these subclasses.

Defering to post 2.0.
Comment 10 Randy Giffen CLA 2002-08-12 10:37:28 EDT
Reopened for investigation
Comment 11 Susan McCourt CLA 2007-06-28 14:53:44 EDT
I don't see us fixing this and potentially breaking so many downstream clients.  Given the age of the bug, marking as WONTFIX.  Please reopen if you disagree.