[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Halting SWT thread but repainting

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