JFace Modeless Dialog [message #12969] |
Tue, 09 June 2009 05:33 |
Eclipse User |
|
|
|
Thought this can be helpful to anyone who wants to make existing dialogs
as modeless but without breaking any code which assumes that Dialog::open
does not return to caller till the dialog is closed.
package yourpackage;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* This acts as a modeless dialog. Essentially this has following
characteristics...
* - Lets the user interact with other UI when this dialog is open
* - Call to open() does not return control to the caller till the dialog
is closed by OK/Cancel etc.,
*/
public class ModelessDialog extends Dialog
{
public ModelessDialog(Shell parentShell) {
super(parentShell);
setBlockOnOpen(false);
}
protected void setShellStyle(int newShellStyle)
{
int newstyle = newShellStyle & ~SWT.APPLICATION_MODAL; /* turn off
APPLICATION_MODAL */
newstyle |= SWT.MODELESS; /* turn on MODELESS */
super.setShellStyle(newstyle);
}
public int open()
{
int retVal = super.open();
pumpMessages(); /* this will let the caller wait till OK, Cancel is
pressed, but
will let the other GUI responsive */
return retVal;
}
protected void pumpMessages()
{
Shell sh = getShell();
Display disp = sh.getDisplay();
while( !sh.isDisposed() ) {
if( !disp.readAndDispatch() ) disp.sleep();
}
disp.update();
}
}
Thanks,
Venkat
|
|
|
Powered by
FUDForum. Page generated in 0.06319 seconds