2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.admin.client.ui;
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.Button;
27 import com.google.gwt.user.client.ui.DialogBox;
28 import com.google.gwt.user.client.ui.HTML;
29 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
30 import com.google.gwt.user.client.ui.HorizontalPanel;
31 import com.google.gwt.user.client.ui.VerticalPanel;
35 * A dialog for requesting confirmation from the user.
39 public abstract class ConfirmationDialog extends DialogBox {
42 * The widget's constructor.
44 * @param message the message to display
45 * @param buttonLabel the label of the confirmation button
47 public ConfirmationDialog(String message, String buttonLabel) {
48 // Set the dialog's caption.
49 setText("Confirmation");
50 setAnimationEnabled(true);
51 // Create a VerticalPanel to contain the label and the buttons.
52 VerticalPanel outer = new VerticalPanel();
53 HorizontalPanel buttons = new HorizontalPanel();
55 HTML text = new HTML("<table><tr><td rowspan='2'>" +
56 //AbstractImagePrototype.create(MessagePanel.images.warn()).getHTML() +
58 "</td><td>" + message + "</td></tr></table>");
59 text.setStyleName("gss-warnMessage");
62 // Create the 'Update' button, along with a listener that hides the dialog
63 // when the button is clicked and renames the file.
64 Button ok = new Button(buttonLabel, new ClickHandler() {
67 public void onClick(ClickEvent event) {
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() {
79 public void onClick(ClickEvent event) {
85 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
86 buttons.setSpacing(8);
87 buttons.setStyleName("gss-warnMessage");
88 outer.setStyleName("gss-warnMessage");
90 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
91 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
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:
107 case KeyCodes.KEY_ESCAPE:
114 public abstract void confirm();
116 public abstract void cancel();