Showing posts with label Demos. Show all posts
Showing posts with label Demos. Show all posts

Thursday, May 6, 2010

GAE – GWT – JDO – Demo Application

Well my posts are getting a little more dispersed which is probably a function of two things.  1) My demo applications are getting longer and; 2) I just moved house, I hate packing.
Well today, or last night, I put the finishing rough touches to an application which demonstrates three key features of developing with GWT.  It demonstrates developing on the GWT framework, using Google App Engine framework, and saving and retrieving data from the BigTable database using JDO.
ShamelessPlug
The application utilises two of the demo applications that come with GWT, Sticky and Showcase, and is therefore a mish mash of those, stripped out with their core functionality and then interjected with some UIBinder code.  Doing in this way enabled me to really learn what is happening in the application and get to grips with creating my own application.
The Showcase application demos, rather excellently, a good framework for developing an application.  It encapsulates different features into different packages and shows a great way of how an application might flow.  it doesn’t use MVP as I didn’t want to introduce too many new concepts at once, but it does illustrate a constructive and useful beginning.
I used Sticky application components for its use of JDO with GWT.  It demonstrates the need for client and server models, and how to process data from and back to the client.
In summary what does the demo application demonstrate:
  1. How to login to the application using a Google account.
  2. Conversion of GWT Showcase application to a UiBinder equivalent.
  3. Use of Google App Engine (GAE) and Google Web Toolkit (GWT)
  4. Use of JDO in the GAE environments.
  5. Saves and retrieves records using RPC calls in GWT.
Warning: This application is a little rough around the edges, but is great if you wanna see working code in one place that demonstrates many features of the application.
I have called this demonstration SohoScheduler as it is the beginning of my replacement for my scheduling application Soho Scheduler.  Soho Scheduler is a Small Office Home Office scheduling application for small businesses.  It allows business users to book clients into a scheduling application at a currently, free, environment.  The application www.sohoappspot.com was built on Google App Engine with Python, but after seeing the power of GWT I quickly realised that this was the way forward for building web applications.  There was just one small problem, I need to learn Java and GWT.  Well after three months of learning and an enrolment in a SCJP developer course I am finally beginning to see headway in this application.
Demo will be added to the repository in due course.

Tuesday, March 23, 2010

Sample 8 – Shoji - Panels

Shoji are a type of panel used in Japanese style houses, you know the ones with paper walls.

shoji_screen_1So I thought it was fitting that our next sample which examines Panels in GWT should use a similar name.  I have started by examining the DockLayoutPanel in a very primitive sense.  It utilizes all the components of  this panel, North, South, East, West and Center and shows how an application can be designed at the highest level.  Since the building of any application starts really with its layout I thought this would be a good place to get going.  This project is likely to get large very quickly as there are many panel types in GWT, so I will re-release the project code at interesting juncture points.  For now we start with this but incrementally we hope to showcase many features of the panel.

Get the code from the Download Section – Sample 8 – Shoji.

Monday, March 15, 2010

Sample 7 – GreenTea - Learning GWT 2.0 and RPC

Anonymous wrote on GWT Sushi telling us about a blog post which had a simple but great example of Remote Procedure Calls with GWT (I found earlier today from the Google videos that the acronym is pronounced Gwit).  The tutorial is really good because it just examines one useful feature, making a call to the server to get some data, and displaying the data.  This Sample, number 7 is called GreenTea, it adds two numbers and returns the result:

GreenTea

Thanks to Chad for writing the post over at Giant Flying Saucer.

The new code sample is in the Google Code repository.  Click the Downloads tab for more info.

Sunday, March 14, 2010

Sample 5 Problems [Update] - Fixed!

Original problem highlighted here.
Thanks to Hendrik Thieß (@Turayen) for helping us solve this one.
@gwtsushi myField is not initialized.Remove "Hidden" in the constructor of MyPanel.Hint: if u use provided=true set the attribut as final :)
Which led us to changing MyPanel.Java from:
@UiField(provided=true)
Hidden myField;

public MyPanel(String someText) {
Hidden myField = new Hidden();
myField.setValue(someText);
initWidget(uiBinder.createAndBindUi(this));
}

to

@UiField(provided=true) final Hidden myField = new Hidden();

public MyPanel(String someText) {
//Hidden myField = new Hidden();
this.myField.setValue(someText);
initWidget(uiBinder.createAndBindUi(this));
}

I have just one word to say – AWESOME and thanks!

Sample 6 Added – Passing Objects To Widgets

I have just completed the last of Jeff Douglas’s tutorials on the basics of GWT and am happy to say that Sample 6 as been added to the demo library.  The original article is here and the code is in the usual place.

This demo examines the construction of an argument as a class object and passes it around various widgets.  Good basic grounding and examples of GWT, and using the @UiFactory annotation.

Saturday, March 13, 2010

Sample 5 Problems

Well what a Friday.  I have been bashing y head against the wall all day today I am sure my inability to solve this one is due to my inexperience with GWT, so I am putting it out into the community and hopefully someone can solve this one.

I followed the example here: http://blog.jeffdouglas.com/2010/02/05/gwt-uibinder-passing-parameters-to-widgets/

However when I go into debug mode I get an error straight away "Fail Unable to load module".

I have added the sample to the download library it is Sample 5 - Sample 5 - Cucumber Roll - Passing Parameters to Widgets.  And the issue for it is listed here.

If anyone from the community of GWTSushiers can help me out I would be eternally grateful and would generously write an article on here profiling your excellent abilities.

Cheers
Gene

Friday, March 12, 2010

Yet Another Great Demo Website (YAGDW)

I get demos and here is another great demo compilation: http://ow.ly/1hLwV

Sample 4 - Embed UI Binder Controls

I have been working on Jeff Douglas's examples and incorporating them into the demo archive.  This example Sample 4, is a great example of using UI Binder Controls in other controls.  This is interesting because in order to work from REST principles it allows you to easily see how we can reuse your page elements elsewhere in the application.

New Rules For Demo Files
Well in the interests of keeping the download file size small and giving you something to do when you download the samples I have removed the following items from the source code as the size was getting huge!

So there files / folders will no longer be in the source:
  • Any *.jar files
  • Any third party libraries - however there will be a directory and ReadMe.txt file to indicate where and how to get the data.
  • \war\WEB-INF\classes\*
  • \war\WEB-INF\lib\*
The file archive was getting to be 86Mb for four examples which is (In a Jon Stewart Style) R-i-d-c-u-l-o-u-s.  After doing the above it was reduced to 0.5 Mb - A-w-e-s-o-m-e.


Thursday, March 11, 2010

Your G.W.T. Community Needs You

At this blog we are collecting Hello World type samples that show off individual pieces of GWT 2.0+ functionality.  With version 2.0 Google has added the UIBinder model which separates the visual layer from the code.  This allows for better management of your code as well as a more visual representation of the visual widgets you are developing. 

In order to provide more examples to the community we are adding samples and articles to this blog and call on all our fellow developers to point us into the direction of good articles and downloadable sample source code.

Drop us a line here or on twitter @gwtsushi and we will be in contact to get your samples added to the repository.


Jeff Douglas – Technology, Coding and Bears… [article]

Jeff Douglas has some great articles covering various aspects of getting to grips with GWT.

WT UiBinder Hello World Tutorial
I’ve been working on a new project the past couple of weeks that (fortunately) requires Google Web Toolkit (GWT) and I wanted to use the new UiBinder  that was released with GWT 2.0 in early December for a number of reasons (clean separation of UI and code, easier collaboration with designers, easier testing, etc ). However, I was having a hard time getting my head wrapped around it given that the GWT site has very little documentation and only a few examples. I’ve combed through the message boards, the docs and the sample Mail application that comes with the SDK and after finally groking the new functionality, I put together a little Hello World app, the kind that would have helped me out originally. 

Full Article Here


GWT UiBinder – Passing Parameters to Widgets
I received a number of emails regarding my last post, GWT UiBinder Hello World Tutorial, specifically how to pass values into widgets using the new GWT 2.0 UiBinder. Here’s a small tutorial on one of the ways in which you could do that. I plan on another tutorial on passing multiple objects using the @UiFactory method. 

Full Article Here


GWT UiBinder – Passing Objects to Widgets
A couple of weeks ago I wrote a GWT 2.0 tutorial for passing simple values to a widget and this is the (promised) follow up on how to pass an object to a widget. For more info on working with the new UiBinder, see Declarative Layout with UiBinder at the GWT site. 

Full Article Here

Monday, March 8, 2010

Baby Steps – Converting The Hello World Project to a UIBinder Model

As I step out onto the icy lake of GWT abandoning all I know about .Net I make my first foray into the UIBinder model.  One of the attractions of the latest version of GWT 2.0 is the inclusion of the UIBinder model.  At present there aren’t too many examples using this new methodology so documentation is scarce.  In an effort to reduce the amount of factors that prevent me from learning this technology, i.e. reducing the amount of things that can go wrong in a project, without having the knowledge yet to quickly fix them.  Did I mention that I am also learning Java too?  I am attempting to convert the standard Hello World project to use the UI Binder model.

The standard project is pretty cool, when you create a GWT project a Hello World application comes pre created which places a text box on the screen and after pressing a button throws a dialog telling you what you just pressed.  It send’s the input to the server and shows the returned message.  It’s simple enough to allow most people to follow the code.  Since there aren’t many UIBinder examples I thought why not convert this application to a UI Binder so it looks exactly the same.  So here goes..

Step 1 : Create a nEW PROJECT

Create a new Google App Engine Project in Eclipse.  I have assumed that you know how to install Eclipse and all the required Google SDKs for GWT and Google App Engine.  So go ahead and create a project and debug it.  You should see an application that looks something like the picture below:

Pic1 

Step 2 : Create UI BindER PACAKGE

Start as you mean to go on by creating an easy to understand project.  Lets create a new package for our UIBinder controls.  Since my company is called Live For Now Studios lets call it: 

com.livefornowstudios.demos.helloworld.client.uibinder



STEP 3 : Create new UIBINDER CONTROL



From File –> New –> UIBinder select this item and see the image below for the elements added to it:



Pic2In the image the package is: com.livefornowstudios.demos.helloworld.client.uibinder



After clicking finish this should create two files in your new UIBinder package these files will be:




  • LandingPage.java  (The behind the scenes code)


  • LandingPage.ui.xml (The visual component)





step 4 : Create the VISUAL CODE



In the file LangingPage.ui.xml we are going to complete the visual components of the Hello World application.   Since I am new to this I am going to explain the elements I know, but it took a bit of fiddling to get this working.  Visually it doesn’t look as identical to the Hello World application as I would like but if faithfully replicates what is happening.  So it is a good starting point for me and hopefully for yourself.  See the main visual code sections below:



    <g:VerticalPanel >

<g:HTML>
<h1>Web Application Starter Project</h1>
<b>Please enter your name:</b>
</g:HTML>

<g:HorizontalPanel>
<g:TextBox ui:field="nameField"></g:TextBox>
<g:Button ui:field="sendButton" text="Send" />
</g:HorizontalPanel>

<g:DialogBox ui:field="dialogBox">
<g:HTMLPanel>
<b>Sending name to the server:</b>
<g:Label ui:field="textToServerLabel"></g:Label>
<br /><b>Server replies:</b>
<g:Label ui:field="serverResponseLabel"></g:Label>
<g:Button ui:field="closeButton" text="Close" />
</g:HTMLPanel>
</g:DialogBox>
</g:VerticalPanel>


Vertical Panel: This is the main wrapper for the control which ensures that the items placed in it appear in a consistent vertical arrangement. 



Header:  This is the first element wrapped in the <h:HTML> tags.  This allows us to enter real HTML to add a header to the control.



HorizontalPanel: This panel ensures that anything added to it flows horizontally across the screen.



TextBox,Button: The <g:TextBox> controls are GWT implementation of a Text Box they are in ASP.Net terms the equivalent of <ASP:TextBox>.  Here we have added a Text Box and a button to initiate the postback.



DialogBox: This is the dialog box that is displayed once the message is received from the server.



step 4 : Add the CODE BEHIND



Most of this code is replacing what the EntryPoint code was doing in the original HelloWorld.  However now it is nicely encapsulated in a UIBinder Object and could be used throughout your application.



Step 1: Declare UI Objects



Somewhere near the top declare the objects in the UI xml declaration:



    @UiField Button sendButton;
@UiField PopupPanel dialogBox;
@UiField TextBox nameField;
@UiField Label textToServerLabel;
@UiField Label serverResponseLabel;
@UiField Button closeButton;



Step 2: Create constructor



Set the default behaviour of the objects in the contructor:



    public LandingPageHeader(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
sendButton.setText(firstName);
dialogBox.setVisible(false);
}


Step 3: Add event clicks



    @UiHandler("sendButton")
void sendButton_onClick(ClickEvent e) {
sendNameToServer();
}

@UiHandler("closeButton")
void closeButton_onClick(ClickEvent e) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}


Step 4 : Handle Server-Client Interaction



/**
* Send the name from the nameField to the server and wait for a response.
*/
private void sendNameToServer() {
sendButton.setEnabled(false);
String textToServer = nameField.getText();
textToServerLabel.setText(textToServer);
serverResponseLabel.setText("");
greetingService.greetServer(textToServer,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
dialogBox.setTitle("Remote Procedure Call - Failure");
serverResponseLabel.addStyleName("serverResponseLabelError");
serverResponseLabel.setText(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}

public void onSuccess(String result) {
dialogBox.setTitle("Remote Procedure Call");
serverResponseLabel.removeStyleName("serverResponseLabelError");
serverResponseLabel.setText(result);
dialogBox.center();
closeButton.setFocus(true);
}
});
}


Step 5 : Change EntryPoint Code



Step 1 : Declare new control



private LandingPageHeader landingPageHeader = new LandingPageHeader("Hello"); 


Step 2: Change OnModuleLoad Control



    public void onModuleLoad() {

// Use RootPanel.get() to get the entire body element
// Add the new UIBinder version of this control to the web page.
RootPanel.get().add(landingPageHeader);

}


Final Thoughts



These changes highlight what needs to be done to change the UIBinder.  If you have any questions please drop me a line.



The full code can be downloaded here project title “HelloWorld” - http://code.google.com/p/gwt-20-demos/

Friday, February 26, 2010

GWT Demos and Samples

I am not sure about you but the best way to learn for me is by example.  Luckily Google Web Toolkit and Google App Engine have plenty of examples to get you going. 

GWT Examples.
These are located in the GWT SDK at this path:
\gwt-2.0.0\samples\
on my machine this translates to this directory:
C:\Program Files\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.2.0.0_2.0.0.v200912062003\gwt-2.0.0\samples

GAE Examples
Similarly located here:
C:\Program Files\eclipse\plugins\com.google.appengine.eclipse.sdkbundle.1.3.0_1.3.0.v200912141120\appengine-java-sdk-1.3.0\demos