Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to launch a dialog in syncExec?
How to launch a dialog in syncExec? [message #454108] Mon, 18 April 2005 00:47 Go to next message
wangwei is currently offline wangweiFriend
Messages: 2
Registered: July 2009
Junior Member
Hi, all!

I know that we can open a dialog in Display.asyncExec().

But now I need to keep most of my code in a non-UI thread,
and just insert a confirm dialog in the middle.
So I think I should use syncExec instead of asyncExec,
while I failed to open any dialog in syncExec().
I can see the dialog, but any input is blocked.

Any advice? thanks in advance.

ragards, wangwei
Re: How to launch a dialog in syncExec? [message #454111 is a reply to message #454108] Mon, 18 April 2005 03:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

I would guess the problem is that your message pumping code
(display.readAndDispatch()) is not getting called now. That would cause
the dialog to appear but then the app would lock up.

Perhaps switching to syncExec means that because you're now waiting for
that call to complete you're not reaching the code that pumps the messages.

Doug

wangwei wrote:

> Hi, all!
>
> I know that we can open a dialog in Display.asyncExec().
>
> But now I need to keep most of my code in a non-UI thread,
> and just insert a confirm dialog in the middle.
> So I think I should use syncExec instead of asyncExec,
> while I failed to open any dialog in syncExec().
> I can see the dialog, but any input is blocked.
>
> Any advice? thanks in advance.
>
> ragards, wangwei
>
>
Re: How to launch a dialog in syncExec? [message #454119 is a reply to message #454111] Mon, 18 April 2005 13:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Make your dialog modal, and then the open() on the dialog should run the
read/dispatch loop and not return until the dialog has been closed.


--
Thanks,
Rich Kulp
Re: How to launch a dialog in syncExec? [message #454202 is a reply to message #454119] Tue, 19 April 2005 00:51 Go to previous messageGo to next message
wangwei is currently offline wangweiFriend
Messages: 2
Registered: July 2009
Junior Member
Thanks.
So I have tried the following code, but it still dosen't work.
when I click a button on the dialog or move the dialog, it will response to
my input,
but then the whole program dies there.
so what's wrong? thanks again

final Display display = Display.getDefault();
display.asyncExec(new Runnable() {
public void run() {
final Shell shell = new Shell(display);
XYChartDialog dlg = new XYChartDialog(shell, xy);
dlg.setBlockOnOpen(false);
dlg.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
});

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote
:d40er2$hob$3@news.eclipse.org...
> Make your dialog modal, and then the open() on the dialog should run the
> read/dispatch loop and not return until the dialog has been closed.
>
>
> --
> Thanks,
> Rich Kulp
Re: How to launch a dialog in syncExec? [message #454226 is a reply to message #454202] Tue, 19 April 2005 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You should have block on open(true) and not have the read/dispatch loop.
If you set block on open true it will run the dispatch loop for you.

In other words, just:

>
> final Display display = Display.getDefault();
> display.asyncExec(new Runnable() {
> public void run() {
> XYChartDialog dlg = new XYChartDialog(null, xy);
> dlg.setBlockOnOpen(false);
> dlg.open();
> }
> });
>

should be sufficient.

But why are you creating a Shell? The jface.Window class doesn't require
to have a shell passed in on the constructor. A null will do. You only
need a shell if you want your dialog to be in front of another shell AND
have that other shell disabled while your dialog is open.

If your application has a shell that you want the dialog to be modal in
respect to, you should use that shell instead of faking one up. The
problem you will have here is that this fake shell is never disposed.
That would explain why you lock up because the shell is never disposed
so your loop is never exited.
--
Thanks,
Rich Kulp
Re: How to launch a dialog in syncExec? [message #454228 is a reply to message #454226] Tue, 19 April 2005 13:49 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Opps,
>> dlg.setBlockOnOpen(true);
>> dlg.open();

--
Thanks,
Rich Kulp
Previous Topic:ScrolledComposite and width of its content...
Next Topic:How to integrate Javadoc for SWT into Eclipse?
Goto Forum:
  


Current Time: Mon Mar 08 10:22:11 GMT 2021

Powered by FUDForum. Page generated in 0.01306 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top