According to another discussion here, I try to open a modal view like so:
public void widgetSelected(SelectionEvent e) {
final Shell dialogShell = new Shell(ApplicationRunner.getApp()
.getShell().getDisplay(), SWT.PRIMARY_MODAL | SWT.SHEET);
dialogShell.setLayout(new FillLayout());
Button closeButton = new Button(dialogShell, SWT.PUSH);
closeButton.setText("Close");
closeButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
dialogShell.dispose();
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
});
dialogShell.setDefaultButton(closeButton);
dialogShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
System.out.println("Modal dialog closed");
}
});
dialogShell.pack();
dialogShell.open();
}
It opens the desired window, but it’s not modal. I can access the main shell and open another instance of the same modal dialog. Can anybody point me in the right direction?
Thanx, Marcus
I would highly recommend creating your own JFace Dialog by extending
org.eclipse.jface.dialogs.Dialograther than creating your own shell with buttons.Here is a really good tutorial on this.
Within the contructor you can call
setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.APPLICATION_MODAL);which will make this dialog completely modal, if you call the constructor with your main shell as the parameter. Like this:where
parentShellis the main shell of your GUI.