Automated merge with https://gss.googlecode.com/hg/
[pithos] / src / gr / ebs / gss / client / QuitDialog.java
1 /*\r
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
3  *\r
4  * This file is part of GSS.\r
5  *\r
6  * GSS is free software: you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation, either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * GSS is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
18  */\r
19 package gr.ebs.gss.client;\r
20 \r
21 import com.google.gwt.core.client.GWT;\r
22 import com.google.gwt.dom.client.NativeEvent;\r
23 import com.google.gwt.event.dom.client.ClickEvent;\r
24 import com.google.gwt.event.dom.client.ClickHandler;\r
25 import com.google.gwt.event.dom.client.KeyCodes;\r
26 import com.google.gwt.user.client.Event.NativePreviewEvent;\r
27 import com.google.gwt.user.client.ui.Button;\r
28 import com.google.gwt.user.client.ui.DialogBox;\r
29 import com.google.gwt.user.client.ui.HTML;\r
30 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
31 import com.google.gwt.user.client.ui.HorizontalPanel;\r
32 import com.google.gwt.user.client.ui.VerticalPanel;\r
33 \r
34 /**\r
35  * The 'quit' dialog box.\r
36  */\r
37 public class QuitDialog extends DialogBox {\r
38 \r
39         /**\r
40          * The widget's constructor.\r
41          */\r
42         public QuitDialog() {\r
43                 Configuration conf = (Configuration) GWT.create(Configuration.class);\r
44                 String service = conf.serviceName();\r
45                 setText("Quit " + service);\r
46 \r
47                 VerticalPanel outer = new VerticalPanel();\r
48                 HorizontalPanel buttons = new HorizontalPanel();\r
49 \r
50                 HTML text = new HTML("Are you sure you want to quit " + service + "?");\r
51                 text.setStyleName("gss-AboutText");\r
52                 outer.add(text);\r
53 \r
54                 // Create the 'Quit' button, along with a listener that hides the dialog\r
55                 // when the button is clicked and quits the application.\r
56                 Button quit = new Button("Quit", new ClickHandler() {\r
57                         @Override\r
58                         public void onClick(ClickEvent event) {\r
59                                 hide();\r
60                                 GSS.get().logout();\r
61                         }\r
62                 });\r
63                 buttons.add(quit);\r
64                 buttons.setCellHorizontalAlignment(quit, HasHorizontalAlignment.ALIGN_CENTER);\r
65                 // Create the 'Cancel' button, along with a listener that hides the\r
66                 // dialog when the button is clicked.\r
67                 Button cancel = new Button("Cancel", new ClickHandler() {\r
68                         @Override\r
69                         public void onClick(ClickEvent event) {\r
70                                 hide();\r
71                         }\r
72                 });\r
73                 buttons.add(cancel);\r
74                 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
75                 buttons.setSpacing(8);\r
76                 outer.add(buttons);\r
77                 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
78                 setWidget(outer);\r
79         }\r
80 \r
81         @Override\r
82         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
83                 super.onPreviewNativeEvent(preview);\r
84 \r
85                 NativeEvent evt = preview.getNativeEvent();\r
86                 if (evt.getType().equals("keydown"))\r
87                         // Use the popup's key preview hooks to close the dialog when either\r
88                         // enter or escape is pressed.\r
89                         switch (evt.getKeyCode()) {\r
90                                 case KeyCodes.KEY_ENTER:\r
91                                         hide();\r
92                                         GSS.get().logout();\r
93                                         break;\r
94                                 case KeyCodes.KEY_ESCAPE:\r
95                                         hide();\r
96                                         break;\r
97                         }\r
98         }\r
99 \r
100 \r
101 }\r