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