Hello guys,
how can I create a popup window? Currently I'm doing something like this:
public abstract class PopupWindow {
public void open()
{
final Shell shell = new Shell(SWT.NONE);
shell.setLayout(new FillLayout(SWT.VERTICAL));
createContent(shell);
shell.addShellListener(new ShellAdapter(){
@Override
public void shellDeactivated(ShellEvent e) {
shell.close();
}
});
shell.open();
}
protected abstract void createContent(Shell shell);
}
Is this correct way?
And another question: I want to open few popup windows in different places on the screen. When user clicks anywhere on the screen beside those popup windows then all popup windows should disappear. I thought about iterating over all shells from Display.getCurrent().getShells() other than my shells and if any of those is activated, then close my shells, like this (treat it as pseudo-code, I haven't tested it yet, I'm just wondering):
final Shell[] myShells = new Shell[5];
//open all the shells
for(final Shell shell: Display.getCurrent().getShells())
{
boolean notMine = true;
for(Shell myshell: myShells)
if(shell==myshell){
notMine = false;
}
if(notMine){
ShellAdapter adapter = new ShellAdapter(){
@Override
public void shellActivated(ShellEvent e) {
for(Shell myshell: myShells)
{
myshell.close();
shell.removeShellListener(this);
}
}
};
}
}