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.user.client.ui.Button;
22 import com.google.gwt.user.client.ui.ClickListener;
23 import com.google.gwt.user.client.ui.DialogBox;
24 import com.google.gwt.user.client.ui.HTML;
25 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
26 import com.google.gwt.user.client.ui.HorizontalPanel;
27 import com.google.gwt.user.client.ui.KeyboardListener;
28 import com.google.gwt.user.client.ui.VerticalPanel;
29 import com.google.gwt.user.client.ui.Widget;
33 * A dialog for requesting confirmation from the user.
37 public abstract class ConfirmationDialog extends DialogBox {
40 * The widget's constructor.
42 * @param message the message to display
43 * @param buttonLabel the label of the confirmation button
45 public ConfirmationDialog(String message, String buttonLabel) {
46 // Set the dialog's caption.
47 setText("Confirmation");
48 setAnimationEnabled(true);
49 // Create a VerticalPanel to contain the label and the buttons.
50 VerticalPanel outer = new VerticalPanel();
51 HorizontalPanel buttons = new HorizontalPanel();
53 HTML text = new HTML("<table><tr><td rowspan='2'>" + MessagePanel.images.warn().getHTML() +
54 "</td><td>" + message + "</td></tr></table>");
55 text.setStyleName("gss-warnMessage");
58 // Create the 'Update' button, along with a listener that hides the dialog
59 // when the button is clicked and renames the file.
60 Button ok = new Button(buttonLabel, new ClickListener() {
62 public void onClick(Widget sender) {
68 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
69 // Create the 'Cancel' button, along with a listener that hides the
70 // dialog when the button is clicked.
71 Button cancel = new Button("Cancel", new ClickListener() {
73 public void onClick(Widget sender) {
79 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
80 buttons.setSpacing(8);
81 buttons.setStyleName("gss-warnMessage");
82 outer.setStyleName("gss-warnMessage");
84 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
85 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
90 public boolean onKeyDownPreview(final char key, final int modifiers) {
91 // Use the popup's key preview hooks to close the dialog when either
92 // enter or escape is pressed.
94 case KeyboardListener.KEY_ENTER:
98 case KeyboardListener.KEY_ESCAPE:
106 public abstract void confirm();
108 public abstract void cancel();