Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » JFace Modeless Dialog
JFace Modeless Dialog [message #12969] Tue, 09 June 2009 09:33
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
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
Previous Topic:SWTException: Invalid thread access when binding in non-UI thread
Next Topic:WizardDialog, WizardPage Back, Next, Finish, Cancel Event Hooks
Goto Forum:
  


Current Time: Fri Apr 26 16:23:33 GMT 2024

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

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

Back to the top