Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / ConfirmationDialog.java @ bddcde7b

History | View | Annotate | Download (3.7 kB)

1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.client;
20

    
21
import com.google.gwt.dom.client.NativeEvent;
22
import com.google.gwt.event.dom.client.ClickEvent;
23
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.event.dom.client.KeyCodes;
25
import com.google.gwt.user.client.Event.NativePreviewEvent;
26
import com.google.gwt.user.client.ui.AbstractImagePrototype;
27
import com.google.gwt.user.client.ui.Button;
28
import com.google.gwt.user.client.ui.DialogBox;
29
import com.google.gwt.user.client.ui.HTML;
30
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
31
import com.google.gwt.user.client.ui.HorizontalPanel;
32
import com.google.gwt.user.client.ui.VerticalPanel;
33

    
34

    
35
/**
36
 * A dialog for requesting confirmation from the user.
37
 *
38
 * @author kman
39
 */
40
public abstract class ConfirmationDialog extends DialogBox {
41

    
42
        /**
43
         * The widget's constructor.
44
         *
45
         * @param message the message to display
46
         * @param buttonLabel the label of the confirmation button
47
         */
48
        public ConfirmationDialog(String message, String buttonLabel) {
49
                // Set the dialog's caption.
50
                setText("Confirmation");
51
                setAnimationEnabled(true);
52
                // Create a VerticalPanel to contain the label and the buttons.
53
                VerticalPanel outer = new VerticalPanel();
54
                HorizontalPanel buttons = new HorizontalPanel();
55

    
56
                HTML text = new HTML("<table><tr><td rowspan='2'>" +
57
                                AbstractImagePrototype.create(MessagePanel.images.warn()).getHTML() +
58
                                "</td><td>" + message + "</td></tr></table>");
59
                text.setStyleName("gss-warnMessage");
60
                outer.add(text);
61

    
62
                // Create the 'Update' button, along with a listener that hides the
63
                // dialog when the button is clicked and renames the file.
64
                Button ok = new Button(buttonLabel, new ClickHandler() {
65

    
66
                        @Override
67
                        public void onClick(ClickEvent event) {
68
                                confirm();
69
                                hide();
70
                        }
71
                });
72
                buttons.add(ok);
73
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
74
                // Create the 'Cancel' button, along with a listener that hides the
75
                // dialog when the button is clicked.
76
                Button cancel = new Button("Cancel", new ClickHandler() {
77

    
78
                        @Override
79
                        public void onClick(ClickEvent event) {
80
                                hide();
81
                                cancel();
82
                        }
83
                });
84
                buttons.add(cancel);
85
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
86
                buttons.setSpacing(8);
87
                buttons.setStyleName("gss-warnMessage");
88
                outer.setStyleName("gss-warnMessage");
89
                outer.add(buttons);
90
                outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
91
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
92
                setWidget(outer);
93
        }
94

    
95
        @Override
96
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
97
                super.onPreviewNativeEvent(preview);
98
                NativeEvent evt = preview.getNativeEvent();
99
                if (evt.getType().equals("keydown"))
100
                        // Use the popup's key preview hooks to close the dialog when either
101
                        // enter or escape is pressed.
102
                        switch (evt.getKeyCode()) {
103
                                case KeyCodes.KEY_ENTER:
104
                                        hide();
105
                                        confirm();
106
                                        break;
107
                                case KeyCodes.KEY_ESCAPE:
108
                                        hide();
109
                                        cancel();
110
                                        break;
111
                        }
112
        }
113

    
114
        public abstract void confirm();
115

    
116
        public abstract void cancel();
117
}