package ontop.test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainDlg {

    private Display display;

    private Shell shell;

    private OnTopDlg otd1 = null;

    private OnTopDlg otd2 = null;

    public MainDlg() {
        display = new Display();
        shell = new Shell(display, SWT.RESIZE | SWT.DIALOG_TRIM);
    }

    private void run() {
        GridLayout gl = new GridLayout(1, false);
        gl.horizontalSpacing = 0;
        shell.setLayout(gl);
        shell.setText("Main Dialog");

        shell.setSize(600, 400);

        createButtons();

        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

        display.dispose();
    }

    private void createButtons() {
        Button onTop1Btn = new Button(shell, SWT.PUSH);
        onTop1Btn.setText("On Top 1");
        onTop1Btn.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (otd1 == null || otd1.isDisposed()) {
                    otd1 = new OnTopDlg(shell, "1");
                    otd1.open();
                }
            }
        });

        Button onTop2Btn = new Button(shell, SWT.PUSH);
        onTop2Btn.setText("On Top 2");
        onTop2Btn.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (otd2 == null || otd2.isDisposed()) {
                    otd2 = new OnTopDlg(shell, "2");
                    otd2.open();
                }
            }
        });

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        MainDlg md = new MainDlg();
        md.run();

    }

}
