Skip to content

Commit d764a05

Browse files
committed
Add a DialogBox
1 parent 3cb36ab commit d764a05

13 files changed

+172
-4
lines changed

ReadMe.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ Click on `Run project` or type F6.
4848

4949
= Debug the application =
5050

51+
== In Maven ==
52+
53+
- `mvn compile` only compiles Java sources.
54+
- `mvn gwt:compile` only compiles GWT module and writes extras.
55+
5156
== In NetBeans ==
5257

5358
1. Define breakpoints if needed.
5459
2. Click on `Debug Project` or type Ctrl+F5.
5560
3. In the project custom menu, click on `Run GWT code server`.
56-
4. Visit the url said by the code server to install the bookmarklet.
61+
4. Visit the url said by the code server to install the bookmarklet.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* About dialog from GWT 'mail' example.
3+
*
4+
* gwt/mail/src/com/google/gwt/sample/mail/client/AboutDialog.java
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
* use this file except in compliance with the License. You may obtain a copy of
8+
* the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations under
16+
* the License.
17+
*/
18+
package com.hellogwt.client;
19+
20+
import com.google.gwt.core.client.GWT;
21+
import com.google.gwt.dom.client.NativeEvent;
22+
import com.google.gwt.event.dom.client.ClickEvent;
23+
import com.google.gwt.event.dom.client.KeyCodes;
24+
import com.google.gwt.uibinder.client.UiBinder;
25+
import com.google.gwt.uibinder.client.UiField;
26+
import com.google.gwt.uibinder.client.UiHandler;
27+
import com.google.gwt.user.client.Event.NativePreviewEvent;
28+
import com.google.gwt.user.client.ui.Button;
29+
import com.google.gwt.user.client.ui.DialogBox;
30+
import com.google.gwt.user.client.ui.Widget;
31+
import com.hellogwt.client.i18n.ClientMessages;
32+
33+
/**
34+
* A simple example of an 'about' dialog box.
35+
*/
36+
public class AboutDialog extends DialogBox {
37+
38+
interface Binder extends UiBinder<Widget, AboutDialog> {
39+
}
40+
private static final Binder binder = GWT.create(Binder.class);
41+
private ClientMessages clientMsg = GWT.create(ClientMessages.class);
42+
43+
@UiField
44+
Button closeButton;
45+
46+
public AboutDialog() {
47+
// Use this opportunity to set the dialog's caption.
48+
setText(clientMsg.aboutDialogTitle());
49+
setWidget(binder.createAndBindUi(this));
50+
51+
setAnimationEnabled(true);
52+
setGlassEnabled(true);
53+
}
54+
55+
@Override
56+
protected void onPreviewNativeEvent(NativePreviewEvent preview) {
57+
super.onPreviewNativeEvent(preview);
58+
59+
NativeEvent evt = preview.getNativeEvent();
60+
if (evt.getType().equals("keydown")) {
61+
// Use the popup's key preview hooks to close the dialog when either
62+
// enter or escape is pressed.
63+
switch (evt.getKeyCode()) {
64+
case KeyCodes.KEY_ENTER:
65+
case KeyCodes.KEY_ESCAPE:
66+
hide();
67+
break;
68+
}
69+
}
70+
}
71+
72+
@UiHandler("closeButton")
73+
void onSignOutClicked(ClickEvent event) {
74+
hide();
75+
}
76+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
About dialog from GWT 'mail' example.
3+
4+
gwt/mail/src/com/google/gwt/sample/mail/client/AboutDialog.ui.xml
5+
-->
6+
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
7+
xmlns:g='urn:import:com.google.gwt.user.client.ui'
8+
ui:generateFormat="com.google.gwt.i18n.rebind.format.PropertiesFormat"
9+
ui:generateKeys="com.google.gwt.i18n.server.keygen.MD5KeyGenerator"
10+
ui:generateLocales="fr,en">
11+
12+
<ui:image field='logo' src='gwt-logo.png'/>
13+
14+
<ui:style>
15+
.panel {
16+
padding: 10px;
17+
}
18+
19+
.aboutText {
20+
text-align: left;
21+
}
22+
23+
@sprite .logo {
24+
gwt-image: 'logo';
25+
float: left;
26+
padding-right: 1em;
27+
}
28+
29+
.buttons {
30+
text-align: right;
31+
}
32+
</ui:style>
33+
34+
<g:HTMLPanel width='24em' styleName='{style.panel}'>
35+
<div class='{style.logo}'/>
36+
37+
<div class='{style.aboutText}'>
38+
<ui:msg key="aboutText">This sample application demonstrates step by step the construction of a Maven-Spring-GWT-Hibernate application.</ui:msg>
39+
</div>
40+
41+
<div class='{style.buttons}'>
42+
<g:Button ui:field='closeButton'>
43+
<ui:msg key="closeButton">Close</ui:msg>
44+
</g:Button>
45+
</div>
46+
</g:HTMLPanel>
47+
</ui:UiBinder>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated from com.hellogwt.client.AboutDialogBinderImplGenMessages
2+
# for locale en
3+
4+
aboutText=This sample application demonstrates step by step the construction of a Maven-Spring-GWT-Hibernate application.
5+
6+
closeButton=Close
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated from com.hellogwt.client.AboutDialogBinderImplGenMessages
2+
# for locale fr
3+
4+
aboutText=Cette application exemple présente étape par étape la construction d''une application Maven-Spring-GWT-Hibernate.
5+
6+
closeButton=Fermer

src/main/java/com/hellogwt/client/HelloGWTWidget.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.gwt.uibinder.client.UiHandler;
2525
import com.google.gwt.user.client.Window;
2626
import com.google.gwt.user.client.rpc.AsyncCallback;
27+
import com.google.gwt.user.client.ui.Anchor;
2728
import com.google.gwt.user.client.ui.Button;
2829
import com.google.gwt.user.client.ui.Composite;
2930
import com.google.gwt.user.client.ui.FlexTable;
@@ -42,7 +43,7 @@ interface HelloGWTWidgetUiBinder extends UiBinder<SplitLayoutPanel, HelloGWTWidg
4243
private static HelloGWTWidgetUiBinder uiBinder = GWT.create(HelloGWTWidgetUiBinder.class);
4344

4445
private GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
45-
46+
4647
private ClientMessages clientMsg = GWT.create(ClientMessages.class);
4748

4849
final AsyncCallback<String> textbox_callback = new AsyncCallback<String>() {
@@ -93,13 +94,15 @@ public void onSuccess(Void result) {
9394
SpanElement statusMessage;
9495
@UiField
9596
SpanElement persistenceClassName;
97+
@UiField
98+
Anchor aboutLink;
9699

97100
public HelloGWTWidget() {
98101
initWidget(uiBinder.createAndBindUi(this));
99102
greetingService.persistenceClassName(new AsyncCallback<String>() {
100103
@Override
101104
public void onFailure(Throwable caught) {
102-
statusMessage.setInnerHTML(clientMsg.error() + caught.getLocalizedMessage());
105+
statusMessage.setInnerHTML(clientMsg.error() + caught.getLocalizedMessage());
103106
}
104107
@Override
105108
public void onSuccess(String result) {
@@ -120,7 +123,7 @@ public void onSuccess(String result) {
120123
void handleNameTextBoxKeyUp(KeyUpEvent keyUpEvent) {
121124
greetingService.greet(nameTextBox.getText(), textbox_callback);
122125
}
123-
126+
124127
@UiHandler("addButton")
125128
void handleAddButtonClick(ClickEvent clickEvent) {
126129
if (!authorTextBox.getText().isEmpty() && !textTextBox.getText().isEmpty()) {
@@ -158,6 +161,18 @@ void handleDeleteButtonClick(ClickEvent clickEvent) {
158161
greetingService.deleteGreeting(textTextBox.getText(), btn_callback);
159162
}
160163

164+
@UiHandler("aboutLink")
165+
/**
166+
* When the 'About' item is selected, show the AboutDialog.
167+
*
168+
* Note that showing a dialog box does not block -- execution continues normally, and the dialog fires an event when it is closed.
169+
*/
170+
void handleAboutLinkClick(ClickEvent event) {
171+
AboutDialog dlg = new AboutDialog();
172+
dlg.show();
173+
dlg.center();
174+
}
175+
161176
private void refreshGreetingsTable() {
162177
greetingService.getGreetings(new AsyncCallback<List<Greeting>>() {
163178
@Override

src/main/java/com/hellogwt/client/HelloGWTWidget.ui.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ removing the package prefix "com.hellogwt.client.".
8080
<a href="?locale=en">English</a>
8181
</p>
8282
</g:HTML>
83+
<g:Anchor href='javascript:;' ui:field='aboutLink'>
84+
<ui:msg key="about">About</ui:msg>
85+
</g:Anchor>
8386
</g:FlowPanel>
8487
</g:south>
8588
</g:SplitLayoutPanel>

src/main/java/com/hellogwt/client/HelloGWTWidgetHelloGWTWidgetUiBinderImplGenMessages_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Generated from com.hellogwt.client.HelloGWTWidgetHelloGWTWidgetUiBinderImplGenMessages
22
# for locale en
33

4+
about=About
5+
46
# Description: Text on button
57
add=Add
68

src/main/java/com/hellogwt/client/HelloGWTWidgetHelloGWTWidgetUiBinderImplGenMessages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated from com.hellogwt.client.HelloGWTWidgetHelloGWTWidgetUiBinderImplGenMessages
22
# for locale fr
33

4+
about=À propos
45
# Description: Default status message.
56
defaultStatusMessage=L''application est charg\u00e9e.
67
authorLabel=Auteur :
9.72 KB
Loading

src/main/java/com/hellogwt/client/i18n/ClientMessages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
@DefaultLocale("en")
2727
public interface ClientMessages extends Messages {
2828

29+
@DefaultMessage("About the sample application")
30+
public String aboutDialogTitle();
31+
2932
@DefaultMessage("Author")
3033
public String author();
3134

src/main/java/com/hellogwt/client/i18n/ClientMessages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Generated from com.hellogwt.client.i18n.ClientMessages
22
# for locale default
33

4+
aboutDialogTitle=About the sample application
5+
46
author=Author
57

68
editError=ERROR\: Cannot edit greetings\!

src/main/java/com/hellogwt/client/i18n/ClientMessages_fr.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Generated from com.hellogwt.client.i18n.ClientMessages
22
# for locale fr
33

4+
aboutDialogTitle=À propos de l''application exemple
5+
46
author=Auteur
57

68
editError=Erreur\u00a0\: impossible de modifier les vœux\u00a0\!

0 commit comments

Comments
 (0)