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.client;
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;
36 * A dialog for requesting confirmation from the user.
40 public abstract class ConfirmationDialog extends DialogBox {
43 * The widget's constructor.
45 * @param message the message to display
46 * @param buttonLabel the label of the confirmation button
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();
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");
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() {
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();