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) {
72 ok.getElement().setId("confirmation.ok");
74 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
75 // Create the 'Cancel' button, along with a listener that hides the
76 // dialog when the button is clicked.
77 Button cancel = new Button("Cancel", new ClickHandler() {
80 public void onClick(ClickEvent event) {
85 cancel.getElement().setId("confirmation.cancel");
87 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
88 buttons.setSpacing(8);
89 buttons.setStyleName("gss-warnMessage");
90 outer.setStyleName("gss-warnMessage");
92 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
93 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
98 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
99 super.onPreviewNativeEvent(preview);
100 NativeEvent evt = preview.getNativeEvent();
101 if (evt.getType().equals("keydown"))
102 // Use the popup's key preview hooks to close the dialog when either
103 // enter or escape is pressed.
104 switch (evt.getKeyCode()) {
105 case KeyCodes.KEY_ENTER:
109 case KeyCodes.KEY_ESCAPE:
116 public abstract void confirm();
118 public abstract void cancel();