import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class DialogExample extends ApplicationWindow {
public DialogExample(Shell parentShell) {
super(parentShell);
}
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout());
final Button btnOpenDialog = new Button(composite, SWT.PUSH);
btnOpenDialog.setText("Dialog öffnen");
btnOpenDialog.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
new Dialog1(getParentShell()).open();
}
});
return super.createContents(parent);
}
public static void main(String[] args) {
ApplicationWindow window = new DialogExample(null);
window.setBlockOnOpen(true);
window.open();
}
class Dialog1 extends TitleAreaDialog
{
public Dialog1(Shell parentShell) {
super(parentShell);
}
@Override
protected Control createContents(Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText("Dies ist Dialog 1");
Button btnOpenDialog2 = new Button(parent, SWT.PUSH);
btnOpenDialog2.setText("Dialog 2 öffnen");
btnOpenDialog2.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
new Dialog2(getParentShell()).open();
}
});
return parent;
}
}
class Dialog2 extends TitleAreaDialog
{
public Dialog2(Shell parentShell) {
super(parentShell);
}
@Override
protected Control createContents(Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText("Dies ist Dialog 2");
return parent;
}
}
}