root / src / gr / ebs / gss / client / ConfirmationDialog.java @ 4cef6f04
History | View | Annotate | Download (3.7 kB)
1 | 67b7ce51 | koutsoub | /*
|
---|---|---|---|
2 | 67b7ce51 | koutsoub | * Copyright 2009 Electronic Business Systems Ltd.
|
3 | 5b2a2809 | pastith | *
|
4 | 5b2a2809 | pastith | * This file is part of GSS.
|
5 | 5b2a2809 | pastith | *
|
6 | 5b2a2809 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 5b2a2809 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 5b2a2809 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 5b2a2809 | pastith | * (at your option) any later version.
|
10 | 5b2a2809 | pastith | *
|
11 | 5b2a2809 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 5b2a2809 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 5b2a2809 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 5b2a2809 | pastith | * GNU General Public License for more details.
|
15 | 5b2a2809 | pastith | *
|
16 | 5b2a2809 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 5b2a2809 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 67b7ce51 | koutsoub | */
|
19 | 67b7ce51 | koutsoub | package gr.ebs.gss.client; |
20 | 67b7ce51 | koutsoub | |
21 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.dom.client.NativeEvent; |
22 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickEvent; |
23 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickHandler; |
24 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.KeyCodes; |
25 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.user.client.Event.NativePreviewEvent; |
26 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
27 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.Button; |
28 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.DialogBox; |
29 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.HTML; |
30 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
31 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.HorizontalPanel; |
32 | 67b7ce51 | koutsoub | import com.google.gwt.user.client.ui.VerticalPanel; |
33 | 67b7ce51 | koutsoub | |
34 | 67b7ce51 | koutsoub | |
35 | 67b7ce51 | koutsoub | /**
|
36 | fdfec871 | pastith | * A dialog for requesting confirmation from the user.
|
37 | 67b7ce51 | koutsoub | *
|
38 | fdfec871 | pastith | * @author kman
|
39 | 67b7ce51 | koutsoub | */
|
40 | 67b7ce51 | koutsoub | public abstract class ConfirmationDialog extends DialogBox { |
41 | 67b7ce51 | koutsoub | |
42 | 67b7ce51 | koutsoub | /**
|
43 | 67b7ce51 | koutsoub | * The widget's constructor.
|
44 | fdfec871 | pastith | *
|
45 | fdfec871 | pastith | * @param message the message to display
|
46 | fdfec871 | pastith | * @param buttonLabel the label of the confirmation button
|
47 | 67b7ce51 | koutsoub | */
|
48 | 5c6b4b2c | Panagiotis Astithas | public ConfirmationDialog(String message, String buttonLabel) { |
49 | fdfec871 | pastith | // Set the dialog's caption.
|
50 | fdfec871 | pastith | setText("Confirmation");
|
51 | 67b7ce51 | koutsoub | setAnimationEnabled(true);
|
52 | fdfec871 | pastith | // Create a VerticalPanel to contain the label and the buttons.
|
53 | fdfec871 | pastith | VerticalPanel outer = new VerticalPanel();
|
54 | fdfec871 | pastith | HorizontalPanel buttons = new HorizontalPanel();
|
55 | 67b7ce51 | koutsoub | |
56 | 6e6e914e | Panagiotis Astithas | HTML text = new HTML("<table><tr><td rowspan='2'>" + |
57 | 6e6e914e | Panagiotis Astithas | AbstractImagePrototype.create(MessagePanel.images.warn()).getHTML() + |
58 | 6e6e914e | Panagiotis Astithas | "</td><td>" + message + "</td></tr></table>"); |
59 | 67b7ce51 | koutsoub | text.setStyleName("gss-warnMessage");
|
60 | 67b7ce51 | koutsoub | outer.add(text); |
61 | 67b7ce51 | koutsoub | |
62 | 6e6e914e | Panagiotis Astithas | // Create the 'Update' button, along with a listener that hides the
|
63 | 6e6e914e | Panagiotis Astithas | // dialog when the button is clicked and renames the file.
|
64 | afd3a0ef | Giannis Koutsoubos | Button ok = new Button(buttonLabel, new ClickHandler() { |
65 | 67b7ce51 | koutsoub | |
66 | afd3a0ef | Giannis Koutsoubos | @Override
|
67 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
68 | 67b7ce51 | koutsoub | confirm(); |
69 | 67b7ce51 | koutsoub | hide(); |
70 | 67b7ce51 | koutsoub | } |
71 | 67b7ce51 | koutsoub | }); |
72 | 67b7ce51 | koutsoub | buttons.add(ok); |
73 | 67b7ce51 | koutsoub | buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
74 | 67b7ce51 | koutsoub | // Create the 'Cancel' button, along with a listener that hides the
|
75 | fdfec871 | pastith | // dialog when the button is clicked.
|
76 | afd3a0ef | Giannis Koutsoubos | Button cancel = new Button("Cancel", new ClickHandler() { |
77 | 67b7ce51 | koutsoub | |
78 | afd3a0ef | Giannis Koutsoubos | @Override
|
79 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
80 | 67b7ce51 | koutsoub | hide(); |
81 | 67b7ce51 | koutsoub | cancel(); |
82 | 67b7ce51 | koutsoub | } |
83 | 67b7ce51 | koutsoub | }); |
84 | 67b7ce51 | koutsoub | buttons.add(cancel); |
85 | 67b7ce51 | koutsoub | buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
86 | 67b7ce51 | koutsoub | buttons.setSpacing(8);
|
87 | 67b7ce51 | koutsoub | buttons.setStyleName("gss-warnMessage");
|
88 | 67b7ce51 | koutsoub | outer.setStyleName("gss-warnMessage");
|
89 | 67b7ce51 | koutsoub | outer.add(buttons); |
90 | 67b7ce51 | koutsoub | outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); |
91 | 67b7ce51 | koutsoub | outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
92 | 67b7ce51 | koutsoub | setWidget(outer); |
93 | 67b7ce51 | koutsoub | } |
94 | 67b7ce51 | koutsoub | |
95 | fdfec871 | pastith | @Override
|
96 | afd3a0ef | Giannis Koutsoubos | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
97 | afd3a0ef | Giannis Koutsoubos | super.onPreviewNativeEvent(preview);
|
98 | afd3a0ef | Giannis Koutsoubos | NativeEvent evt = preview.getNativeEvent(); |
99 | afd3a0ef | Giannis Koutsoubos | if (evt.getType().equals("keydown")) |
100 | afd3a0ef | Giannis Koutsoubos | // Use the popup's key preview hooks to close the dialog when either
|
101 | afd3a0ef | Giannis Koutsoubos | // enter or escape is pressed.
|
102 | afd3a0ef | Giannis Koutsoubos | switch (evt.getKeyCode()) {
|
103 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ENTER:
|
104 | afd3a0ef | Giannis Koutsoubos | hide(); |
105 | afd3a0ef | Giannis Koutsoubos | confirm(); |
106 | afd3a0ef | Giannis Koutsoubos | break;
|
107 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ESCAPE:
|
108 | afd3a0ef | Giannis Koutsoubos | hide(); |
109 | afd3a0ef | Giannis Koutsoubos | cancel(); |
110 | afd3a0ef | Giannis Koutsoubos | break;
|
111 | afd3a0ef | Giannis Koutsoubos | } |
112 | 67b7ce51 | koutsoub | } |
113 | 67b7ce51 | koutsoub | |
114 | 67b7ce51 | koutsoub | public abstract void confirm(); |
115 | 67b7ce51 | koutsoub | |
116 | 67b7ce51 | koutsoub | public abstract void cancel(); |
117 | 67b7ce51 | koutsoub | } |