Skip to content

Commit

Permalink
Merge pull request #1 from slugmandrew/appengine
Browse files Browse the repository at this point in the history
Modified to use app engine server instead of basic jetty
  • Loading branch information
slugmandrew committed Aug 23, 2016
2 parents 0426fdc + 9a2878a commit b0df99d
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 393 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*.jar
*.war

# maven output
target/

# gwt caches and compiled units #
war/gwt_bree/
gwt-unitCache/
Expand Down
111 changes: 61 additions & 50 deletions businessenergybox-client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.usav.beb</groupId>
<artifactId>businessenergybox</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>businessenergybox-client</artifactId>
<packaging>gwt-app</packaging>

<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>businessenergybox-shared</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>businessenergybox-shared</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<configuration>
<moduleName>com.usav.beb.App</moduleName>
<moduleShortName>app</moduleShortName>
</configuration>
</plugin>
</plugins>
</build>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.usav.beb</groupId>
<artifactId>businessenergybox</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>businessenergybox-client</artifactId>
<packaging>gwt-app</packaging>

<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>businessenergybox-shared</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>businessenergybox-shared</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<configuration>
<moduleName>com.usav.beb.App</moduleName>
<moduleShortName>app</moduleShortName>
</configuration>
<executions>
<!-- Generate the module and add it to the webappDirectory/classes/... -->
<execution>
<id>generate-module</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-module</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
257 changes: 135 additions & 122 deletions businessenergybox-client/src/main/java/com/usav/beb/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,139 +20,152 @@
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class App implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
public class App implements EntryPoint
{
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";

/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);

/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
/**
* This is the entry point method.
*/
public void onModuleLoad()
{
final Button sendButton = new Button("Call the A-Team");
final TextBox nameField = new TextBox();
nameField.setText("Yo Name, Sucka!");
final Label errorLabel = new Label();

// We can add style names to widgets
sendButton.addStyleName("sendButton");
// We can add style names to widgets
sendButton.addStyleName("sendButton");

// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);

// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();
// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();

// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Remote Procedure Call");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);
// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Remote Procedure Call");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);

// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});

// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler
{
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event)
{
sendNameToServer();
}

/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event)
{
if(event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
{
sendNameToServer();
}
}

/**
* Send the name from the nameField to the server and wait for a response.
*/
private void sendNameToServer() {
// First, we validate the input.
errorLabel.setText("");
String textToServer = nameField.getText();
if (!FieldVerifier.isValidName(textToServer)) {
errorLabel.setText("Please enter at least four characters");
return;
}
/**
* Send the name from the nameField to the server and wait for a response.
*/
private void sendNameToServer()
{
// First, we validate the input.
errorLabel.setText("");
String textToServer = nameField.getText();
if(!FieldVerifier.isValidName(textToServer))
{
errorLabel.setText("Please enter at least four characters");
return;
}

// Then, we send the input to the server.
sendButton.setEnabled(false);
textToServerLabel.setText(textToServer);
serverResponseLabel.setText("");
greetingService.greetServer(textToServer,
new AsyncCallback<GreetingResponse>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
dialogBox
.setText("Remote Procedure Call - Failure");
serverResponseLabel
.addStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}
// Then, we send the input to the server.
sendButton.setEnabled(false);
textToServerLabel.setText(textToServer);
serverResponseLabel.setText("");
greetingService.greetServer(textToServer,
new AsyncCallback<GreetingResponse>()
{
public void onFailure(Throwable caught)
{
// Show the RPC error message to the user
dialogBox
.setText("Remote Procedure Call - Failure");
serverResponseLabel
.addStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}

public void onSuccess(GreetingResponse result) {
dialogBox.setText("Remote Procedure Call");
serverResponseLabel
.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(new SafeHtmlBuilder()
.appendEscaped(result.getGreeting())
.appendHtmlConstant("<br><br>I am running ")
.appendEscaped(result.getServerInfo())
.appendHtmlConstant(".<br><br>It looks like you are using:<br>")
.appendEscaped(result.getUserAgent())
.toSafeHtml());
dialogBox.center();
closeButton.setFocus(true);
}
});
}
}
public void onSuccess(GreetingResponse result)
{
dialogBox.setText("Remote Procedure Call");
serverResponseLabel
.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(new SafeHtmlBuilder()
.appendEscaped(result.getGreeting())
.appendHtmlConstant("<br><br>I am running ")
.appendEscaped(result.getServerInfo())
.appendHtmlConstant(".<br><br>It looks like you are using:<br>")
.appendEscaped(result.getUserAgent())
.toSafeHtml());
dialogBox.center();
closeButton.setFocus(true);
}
});
}
}

// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
nameField.addKeyUpHandler(handler);
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
nameField.addKeyUpHandler(handler);
}
}

0 comments on commit b0df99d

Please sign in to comment.