root / src / gr / ebs / gss / client / QuitDialog.java @ a60ea262
History | View | Annotate | Download (3.3 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client; |
20 |
|
21 |
import com.google.gwt.core.client.GWT; |
22 |
import com.google.gwt.dom.client.NativeEvent; |
23 |
import com.google.gwt.event.dom.client.ClickEvent; |
24 |
import com.google.gwt.event.dom.client.ClickHandler; |
25 |
import com.google.gwt.event.dom.client.KeyCodes; |
26 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
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; |
33 |
|
34 |
/**
|
35 |
* The 'quit' dialog box.
|
36 |
*/
|
37 |
public class QuitDialog extends DialogBox { |
38 |
|
39 |
/**
|
40 |
* The widget's constructor.
|
41 |
*/
|
42 |
public QuitDialog() {
|
43 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
44 |
String service = conf.serviceName();
|
45 |
setText("Quit " + service);
|
46 |
|
47 |
VerticalPanel outer = new VerticalPanel();
|
48 |
HorizontalPanel buttons = new HorizontalPanel();
|
49 |
|
50 |
HTML text = new HTML("Are you sure you want to quit " + service + "?"); |
51 |
text.setStyleName("gss-AboutText");
|
52 |
outer.add(text); |
53 |
|
54 |
// Create the 'Quit' button, along with a listener that hides the dialog
|
55 |
// when the button is clicked and quits the application.
|
56 |
Button quit = new Button("Quit", new ClickHandler() { |
57 |
@Override
|
58 |
public void onClick(ClickEvent event) { |
59 |
hide(); |
60 |
GSS.get().logout(); |
61 |
} |
62 |
}); |
63 |
buttons.add(quit); |
64 |
buttons.setCellHorizontalAlignment(quit, HasHorizontalAlignment.ALIGN_CENTER); |
65 |
// Create the 'Cancel' button, along with a listener that hides the
|
66 |
// dialog when the button is clicked.
|
67 |
Button cancel = new Button("Cancel", new ClickHandler() { |
68 |
@Override
|
69 |
public void onClick(ClickEvent event) { |
70 |
hide(); |
71 |
} |
72 |
}); |
73 |
buttons.add(cancel); |
74 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
75 |
buttons.setSpacing(8);
|
76 |
outer.add(buttons); |
77 |
outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
78 |
setWidget(outer); |
79 |
} |
80 |
|
81 |
@Override
|
82 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
83 |
super.onPreviewNativeEvent(preview);
|
84 |
|
85 |
NativeEvent evt = preview.getNativeEvent(); |
86 |
if (evt.getType().equals("keydown")) |
87 |
// Use the popup's key preview hooks to close the dialog when either
|
88 |
// enter or escape is pressed.
|
89 |
switch (evt.getKeyCode()) {
|
90 |
case KeyCodes.KEY_ENTER:
|
91 |
hide(); |
92 |
GSS.get().logout(); |
93 |
break;
|
94 |
case KeyCodes.KEY_ESCAPE:
|
95 |
hide(); |
96 |
break;
|
97 |
} |
98 |
} |
99 |
|
100 |
|
101 |
} |