Finally displayed virtual folder hierarchy up to second level
[pithos] / web_client / src / gr / grnet / pithos / web / client / QuitDialog.java
1 /*\r
2  * Copyright (c) 2011 Greek Research and Technology Network\r
3  */\r
4 package gr.grnet.pithos.web.client;\r
5 \r
6 import com.google.gwt.core.client.GWT;\r
7 import com.google.gwt.dom.client.NativeEvent;\r
8 import com.google.gwt.event.dom.client.ClickEvent;\r
9 import com.google.gwt.event.dom.client.ClickHandler;\r
10 import com.google.gwt.event.dom.client.KeyCodes;\r
11 import com.google.gwt.user.client.Event.NativePreviewEvent;\r
12 import com.google.gwt.user.client.ui.Button;\r
13 import com.google.gwt.user.client.ui.DialogBox;\r
14 import com.google.gwt.user.client.ui.HTML;\r
15 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
16 import com.google.gwt.user.client.ui.HorizontalPanel;\r
17 import com.google.gwt.user.client.ui.VerticalPanel;\r
18 \r
19 /**\r
20  * The 'quit' dialog box.\r
21  */\r
22 public class QuitDialog extends DialogBox {\r
23 \r
24         /**\r
25          * The widget's constructor.\r
26          */\r
27         public QuitDialog() {\r
28                 Configuration conf = (Configuration) GWT.create(Configuration.class);\r
29                 String service = conf.serviceName();\r
30                 setText("Quit " + service);\r
31 \r
32                 VerticalPanel outer = new VerticalPanel();\r
33                 HorizontalPanel buttons = new HorizontalPanel();\r
34 \r
35                 HTML text = new HTML("Are you sure you want to quit " + service + "?");\r
36                 text.setStyleName("pithos-AboutText");\r
37                 outer.add(text);\r
38 \r
39                 // Create the 'Quit' button, along with a listener that hides the dialog\r
40                 // when the button is clicked and quits the application.\r
41                 Button quit = new Button("Quit", new ClickHandler() {\r
42                         @Override\r
43                         public void onClick(ClickEvent event) {\r
44                                 hide();\r
45                                 GSS.get().logout();\r
46                         }\r
47                 });\r
48                 buttons.add(quit);\r
49                 buttons.setCellHorizontalAlignment(quit, HasHorizontalAlignment.ALIGN_CENTER);\r
50                 // Create the 'Cancel' button, along with a listener that hides the\r
51                 // dialog when the button is clicked.\r
52                 Button cancel = new Button("Cancel", new ClickHandler() {\r
53                         @Override\r
54                         public void onClick(ClickEvent event) {\r
55                                 hide();\r
56                         }\r
57                 });\r
58                 buttons.add(cancel);\r
59                 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
60                 buttons.setSpacing(8);\r
61                 outer.add(buttons);\r
62                 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
63                 setWidget(outer);\r
64         }\r
65 \r
66         @Override\r
67         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
68                 super.onPreviewNativeEvent(preview);\r
69 \r
70                 NativeEvent evt = preview.getNativeEvent();\r
71                 if (evt.getType().equals("keydown"))\r
72                         // Use the popup's key preview hooks to close the dialog when either\r
73                         // enter or escape is pressed.\r
74                         switch (evt.getKeyCode()) {\r
75                                 case KeyCodes.KEY_ENTER:\r
76                                         hide();\r
77                                         GSS.get().logout();\r
78                                         break;\r
79                                 case KeyCodes.KEY_ESCAPE:\r
80                                         hide();\r
81                                         break;\r
82                         }\r
83         }\r
84 \r
85 \r
86 }\r