Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311462 - Timer does not run when FileDialog is open
Summary: Timer does not run when FileDialog is open
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.6 RC1   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-03 21:28 EDT by Silenio Quarti CLA
Modified: 2010-05-04 12:06 EDT (History)
1 user (show)

See Also:
skovatch: review+


Attachments
partial fix (1.01 KB, patch)
2010-05-03 21:49 EDT, Silenio Quarti CLA
no flags Details | Diff
fix (1.23 KB, patch)
2010-05-04 09:50 EDT, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Silenio Quarti CLA 2010-05-03 21:28:02 EDT
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;


public class PRxx {
public static void main(String[] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout(1, false));

	display.timerExec(100, new Runnable() {
		public void run() {
			System.out.println("timer");
			display.timerExec(100, this);
		}
	});

	shell.pack();
	shell.open();
	
	FileDialog dialog = new FileDialog(shell, SWT.NONE);
	dialog.open();
	
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}
Comment 1 Silenio Quarti CLA 2010-05-03 21:49:26 EDT
Created attachment 166894 [details]
partial fix

This patch fixes this testcase, but not the previous one. Not sure why.

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;


public class PRxx {
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new GridLayout(1, false));
	display.timerExec(100, new Runnable() {
		public void run() {
			System.out.println("timer");
			display.timerExec(100, this);
		}
	});
	shell.pack();
	shell.open();
	
	shell.addListener(SWT.MouseDown, new Listener() {
		public void handleEvent(Event event) {
			FileDialog dialog = new FileDialog(shell, SWT.NONE);
			dialog.open();
		}
	});
	
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}
Comment 2 Scott Kovatch CLA 2010-05-04 00:35:49 EDT
The title is a bit misleading. With your patch, the timer is running, but the Runnable isn't executing because allowTimers is always false. The only place that sets it to true is Display.sleep(). NSOpenPanel runs its own loop in NSModalPanelRunLoopMode, but our sleep() isn't being called.

We need both your patch plus we need to initialize allowTimers and runAsyncMessages to true. I'm not sure what problem you were seeing that forced the need for allowTimers in the first place. Maybe because the timers weren't being registered in all run loop modes?

Your patch fixes the second case because the readAndDispatch loop is running when the MouseDown event fires, so allowTimers gets set to true when sleep() exits.
Comment 3 Silenio Quarti CLA 2010-05-04 09:50:38 EDT
Created attachment 166955 [details]
fix

Got it. The carbon code initializes it to true as well.

The allowTimers flags is needed to avoid timers running from Display.sleep().
Comment 4 Scott Kovatch CLA 2010-05-04 11:44:01 EDT
Looks good. +1.
Comment 5 Silenio Quarti CLA 2010-05-04 12:04:42 EDT
Removing Security_Advisories flag. I am not sure how it got checked.
Comment 6 Silenio Quarti CLA 2010-05-04 12:06:10 EDT
Fixed > 20100504