view jface/user/PopUp.d @ 149:80f47186dc48

more dialogs
author Frank Benoit <benoit@tionex.de>
date Sat, 16 Aug 2008 22:24:25 +0200
parents 5f508f322464
children cc2a8879c8b7
line wrap: on
line source

module user.PopUp;
import tango.util.log.Trace;

import dwt.dwthelper.utils;
import dwt.DWT;

import dwt.layout.GridLayout;
import dwt.layout.GridData;
import dwt.layout.FillLayout;

import dwt.graphics.Image;

import dwt.widgets.Text;
import dwt.widgets.Control;
import dwt.widgets.Composite;
import dwt.widgets.Group;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Listener;
import dwt.widgets.Event;
import dwt.widgets.Button;
import dwt.widgets.Label;

import dwtx.jface.dialogs.PopupDialog;
import dwtx.jface.dialogs.ErrorDialog;
import dwtx.jface.dialogs.MessageDialogWithToggle;
import dwtx.jface.dialogs.MessageDialog;
import dwtx.jface.dialogs.IDialogConstants;
import dwtx.jface.dialogs.TitleAreaDialog;
import dwtx.jface.dialogs.InputDialog;
import dwtx.jface.dialogs.IMessageProvider;
import dwtx.jface.dialogs.DialogTray;

import dwtx.jface.window.ApplicationWindow;
import dwtx.core.runtime.IStatus;
import dwtx.core.runtime.Status;
import dwtx.core.runtime.MultiStatus;

version(JIVE) import jive.stacktrace;

class App : ApplicationWindow {

    this(){
        super(null);
        setBlockOnOpen(true);
    }
    protected override Control createContents(Composite parent) {
        Composite comp = cast(Composite)super.createContents(parent);
        getShell().setText("Test PopupDialog");

        comp.setLayout(new GridLayout(1, false));


        with( new Button( comp, DWT.PUSH )){
            addListener( DWT.Selection, dgListener( & doPopUp ));
            setText( "PopUp" );
        }
        with( new Button( comp, DWT.PUSH )){
            addListener( DWT.Selection, dgListener( & doErrorDlg ));
            setText( "Error DLG" );
        }
        with( new Button( comp, DWT.PUSH )){
            addListener( DWT.Selection, dgListener( & doInputDlg ));
            setText( "Input DLG" );
        }
        with( new Button( comp, DWT.PUSH )){
            addListener( DWT.Selection, dgListener( & doMessageDialogWithToggleDlg ));
            setText( "MessageDialogWithToggle" );
        }
        with( new Button( comp, DWT.PUSH )){
            addListener( DWT.Selection, dgListener( & doTitleAreaDialog ));
            setText( "TitleAreaDialog" );
        }
        return comp;
    }
    void doPopUp( Event e ){
        auto pu = new PopupDialog(
            getShell(),
            PopupDialog.HOVER_SHELLSTYLE ,
            true,
            true,
            true,
            true,
            true,
            "Title",
            "Info line...");
        pu.open();
    }
    void doErrorDlg( Event e ){
        auto status = new MultiStatus( "plugin-ID", 0, "MultiStatus message", null );
        status.add( new Status( Status.ERROR, "plugin-ID", "Status message 'error'"/+, new RuntimeException("bla")+/ ) );
        status.add( new Status( Status.WARNING, "plugin-ID", "Status message 'warning'" ) );
        auto dlg = new ErrorDialog(
            getShell(),
            "Title",
            "Dialog message",
            status,
            IStatus.ERROR|IStatus.WARNING);
        dlg.open();
    }
    void doMessageDialogWithToggleDlg( Event e ){
        auto dlg = new MessageDialogWithToggle(
            getShell(),
            "Title",
            null,
            "Dialog message",
            MessageDialog.INFORMATION,
            [ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL ],
            0,
            "Toggle message",
            true);
        dlg.open();
    }
    void doInputDlg( Event e ){
        auto dlg = new InputDialog(
            getShell(),
            "Title",
            "Dialog message",
            "42",
            null );
        dlg.open();
    }

    void doTitleAreaDialog( Event e ){
        auto dlg = new MyTitleAreaDialog(
            getShell());
        dlg.open();
    }

}

    class MyTitleAreaDialog : TitleAreaDialog {
        this( Shell shell ){
            super(shell);
        }
        protected override void configureShell(Shell newShell){
            super.configureShell(newShell);
            newShell.setText( "Application Name" );
        }
        protected override bool isResizable(){
            return true;
        }
        protected override Control createContents(Composite parent) {
            auto comp = cast(Composite) super.createContents(parent);
            openTray( new MyTray() );
            setTitle( "Title" );
            setMessage( "A custom message", IMessageProvider.INFORMATION );
            return comp;
        }
        protected override Control createDialogArea(Composite parent){
            auto comp = cast(Composite) super.createDialogArea(parent);
            //comp.setLayout( new FillLayout());
            auto lbl = new Label( comp, DWT.None );
            lbl.setText( "Dialog Area" );
            auto gd = new GridData( GridData.FILL, GridData.FILL, true, false );
            gd.verticalIndent = 5;
            gd.horizontalIndent = 5;
            lbl.setLayoutData( gd );
            return comp;
        }
    }
    class MyTray : DialogTray {
        protected Control createContents(Composite parent){
            auto comp = new Composite(parent, DWT.NONE );
            comp.setLayout( new GridLayout( 1, false ));
            with( new Label( comp, DWT.NONE )){
                auto gd = new GridData( GridData.FILL, GridData.FILL, true, false );
                gd.verticalIndent = 5;
                gd.horizontalIndent = 5;
                setLayoutData( gd );
                setText( "Tray" );
            }
            return comp;
        }
    }


void main(){
    auto d = new Display();
    auto app = new App();
    app.open();
}