Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Halting SWT thread but repainting
Halting SWT thread but repainting [message #462693] Mon, 17 October 2005 12:22 Go to next message
Hans is currently offline HansFriend
Messages: 36
Registered: July 2009
Member
[This is a follow-up question to a receent question on modal Swing
dialogs.]

I am using SWT_AWT to embed a legacy Swing application inside Eclipse.
This application opens modal (Swing) dialogs. The Swing dialogs show up
nicely and block the AWT panel correctly. However, the main Eclipse shell
is still editable, i.e. users can select menus and tool bar actions,
breaking the modalness of the Swing panel.

Question: How can I block the SWT handling as if there was a modal dialog,
so that only the Swing dialog remains editable? I tried to block the SWT
thread, but then also no repainting gets through.

Thanks,
Hans
Re: Halting SWT thread but repainting [message #462694 is a reply to message #462693] Mon, 17 October 2005 12:46 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Not sure this is doable, but couldn't you open a modal swt dialog at the
same time?

Hans wrote:
> [This is a follow-up question to a receent question on modal Swing
> dialogs.]
>
> I am using SWT_AWT to embed a legacy Swing application inside Eclipse.
> This application opens modal (Swing) dialogs. The Swing dialogs show up
> nicely and block the AWT panel correctly. However, the main Eclipse
> shell is still editable, i.e. users can select menus and tool bar
> actions, breaking the modalness of the Swing panel.
>
> Question: How can I block the SWT handling as if there was a modal
> dialog, so that only the Swing dialog remains editable? I tried to
> block the SWT thread, but then also no repainting gets through.
>
> Thanks,
> Hans
>
Re: Halting SWT thread but repainting [message #462697 is a reply to message #462694] Mon, 17 October 2005 13:25 Go to previous messageGo to next message
Hans is currently offline HansFriend
Messages: 36
Registered: July 2009
Member
Stefan Langer wrote:

> Not sure this is doable, but couldn't you open a modal swt dialog at the
> same time?

I don't see how. There are two issues here, I guess

1) Wrap the Swing dialog in a true SWT dialog. This has been suggested in
another thread, and works relatively well but means a significant
maintenance overhead (e.g. the buttons to close the dialog need to be
reimplemented in SWT, duplicating the control logic from Swing).

2) Open a "hidden" modal SWT dialog in addition to the Swing dialog. I
don't see how this could work, because the SWT dialog would get the focus
and thus block the AWT dialog.

Any other helpful minds out there? Has anyone ever used modal Swing
dialogs in an Eclipse plug-in?
Re: Halting SWT thread but repainting [message #463111 is a reply to message #462693] Wed, 26 October 2005 17:31 Go to previous messageGo to next message
Hans is currently offline HansFriend
Messages: 36
Registered: July 2009
Member
Hans wrote:
> [This is a follow-up question to a receent question on modal Swing
> dialogs.]
>
> I am using SWT_AWT to embed a legacy Swing application inside Eclipse.
> This application opens modal (Swing) dialogs. The Swing dialogs show up
> nicely and block the AWT panel correctly. However, the main Eclipse
> shell is still editable, i.e. users can select menus and tool bar
> actions, breaking the modalness of the Swing panel.
>
> Question: How can I block the SWT handling as if there was a modal
> dialog, so that only the Swing dialog remains editable? I tried to
> block the SWT thread, but then also no repainting gets through.

Just for the archive - here is the solution: use Shell.setEnabled(false)
to block it while the Swing process is running. This will reject any
use input but still handle repaint events.

So a pattern such as the following can be employed (from SWT thread,
assuming there is a boolean field "busy" in the class):


SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
// Do the Swing work, e.g. modal dialog
}
finally {
busy = false;
}
}
});

shell.setEnabled(false);
Display display = shell.getDisplay();
while (!shell.isDisposed() && busy) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
shell.setEnabled(true);


Hans
Re: Halting SWT thread but repainting [message #463115 is a reply to message #463111] Wed, 26 October 2005 20:25 Go to previous messageGo to next message
Gordon Hirsch is currently offline Gordon HirschFriend
Messages: 100
Registered: July 2009
Senior Member
Hans wrote:
>
> Just for the archive - here is the solution: use Shell.setEnabled(false)
> to block it while the Swing process is running. This will reject any
> use input but still handle repaint events.

Hans,

Wouldn't the setEnabled(false) call visually change the SWT window (i.e.
grey it out)? The javadoc seems to say so.

Also, if I may respond late to a previous post of yours on this
thread... The strategy of opening a hidden SWT modal dialog in
conjunction with the Swing dialog, while messy, can be made to work. The
trick is to add a focus handler to the hidden SWT dialog; whenever it
gains focus, you can transfer control right back to the Swing dialog.

My main concern is that some unusual event will cause this hidden modal
dialog to remain open after the Swing dialog closes. That would
permanently disable all input to my application. Not good. So, I'd
really like to find a cleaner way...

>
> So a pattern such as the following can be employed (from SWT thread,
> assuming there is a boolean field "busy" in the class):
>
>
> SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> try {
> // Do the Swing work, e.g. modal dialog
> }
> finally {
> busy = false;
> }
> }
> });
>
> shell.setEnabled(false);
> Display display = shell.getDisplay();
> while (!shell.isDisposed() && busy) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> shell.setEnabled(true);
>
>
> Hans
Re: Halting SWT thread but repainting [message #463185 is a reply to message #463115] Fri, 28 October 2005 16:48 Go to previous message
Hans is currently offline HansFriend
Messages: 36
Registered: July 2009
Member
Gordon Hirsch wrote:
> Hans wrote:
>
>>
>> Just for the archive - here is the solution: use
>> Shell.setEnabled(false) to block it while the Swing process is
>> running. This will reject any use input but still handle repaint events.
>
>
> Hans,
>
> Wouldn't the setEnabled(false) call visually change the SWT window (i.e.
> grey it out)? The javadoc seems to say so.

I tried it for the Eclipse main window and the behavior is as desired -
it is not greyed out and no longer accepts any input. On Windows at
least...

By the way, in my code snippet below, of course there has to be a line

busy = true;

at the very beginning.

Hans

>
> Also, if I may respond late to a previous post of yours on this
> thread... The strategy of opening a hidden SWT modal dialog in
> conjunction with the Swing dialog, while messy, can be made to work. The
> trick is to add a focus handler to the hidden SWT dialog; whenever it
> gains focus, you can transfer control right back to the Swing dialog.
>
> My main concern is that some unusual event will cause this hidden modal
> dialog to remain open after the Swing dialog closes. That would
> permanently disable all input to my application. Not good. So, I'd
> really like to find a cleaner way...
>
>>
>> So a pattern such as the following can be employed (from SWT thread,
>> assuming there is a boolean field "busy" in the class):
>>
>>
>> SwingUtilities.invokeLater(new Runnable() {
>> public void run() {
>> try {
>> // Do the Swing work, e.g. modal dialog
>> }
>> finally {
>> busy = false;
>> }
>> }
>> });
>> shell.setEnabled(false);
>> Display display = shell.getDisplay();
>> while (!shell.isDisposed() && busy) {
>> if (!display.readAndDispatch()) {
>> display.sleep();
>> }
>> }
>> shell.setEnabled(true);
>>
>>
>> Hans
Previous Topic:Swing-Swt bridge
Next Topic:[URGENT] Problem with swt opengl plugin
Goto Forum:
  


Current Time: Fri Apr 26 21:44:36 GMT 2024

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

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

Back to the top