Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.temp.foundation.client.widget.dialog;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.ui.*;
import com.temp.foundation.client.handler.*;
import com.temp.foundation.client.widget.*;

/**
 * This custom dialog shows custom title, body lines (description, and
 * confirmation question) followed by a centered 'yes' & 'no' buttons
 *
 * @author ngchihou, georgs
 */
public class ConfirmationDialog<T> extends SEDIDialogBox {
    public interface Callback<T> extends ActionHandler<T> {
        void dontExecute( T value );
    }

    private ActionHandler<T> yesButtonClickedHandler;

    public ConfirmationDialog( final T obj, String title, Integer contentWidth, ButtonBase yesButton, ButtonBase noButton,
                               String... bodyTextBlocksAboveControlButtons ) {
        super( "images/dialog/warningIcon.png", contentWidth, title );

        if ( yesButton == null ) {
            yesButton = new OurPushButton( "yes" );
        }
        if ( noButton == null ) {
            noButton = new OurPushButton( "noYesSize" );
        }
        yesButton.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                processButton( obj, true );
            }
        } );
        noButton.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                processButton( obj, false );
            }
        } );

        setBody( bodyTextBlocksAboveControlButtons, yesButton, noButton );
    }

    public ConfirmationDialog( T obj, String title, String... bodyTextBlocksAboveControlButtons ) {
        this( obj, title, null, null, null, bodyTextBlocksAboveControlButtons );
    }

    public ConfirmationDialog<T> centerContent() {
        centerAllContent = true;
        return this;
    }

    public void show( ActionHandler<T> yesButtonClickedHandler ) {
        this.yesButtonClickedHandler = yesButtonClickedHandler;
        show();
    }

    @Override
    public void hide() {
        yesButtonClickedHandler = null;
        super.hide();
    }

    private void processButton( T obj, boolean yesButtonClicked ) {
        ActionHandler<T> handler = yesButtonClickedHandler;
        hide();
        if ( handler != null ) {
            if ( yesButtonClicked ) {
                handler.execute( obj );
            } else if ( handler instanceof Callback ) {
                ((Callback<T>) handler).dontExecute( obj );
            }
        }
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/foundation/client/widget/dialog/ConfirmationDialog.java

Diff revisions: vs.
Revision Author Commited Message
965 GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:20:35 +0000

!