Friday, March 9, 2012

Visualizing Piles of Money

I recently had a need to use the Column Chart 'Piles of Money' in one of my GWT projects.
 
However to be able to use it in my project I needed to create a GWT "wrapper" class as documented here.  See the bottom of my post for the Wrapper Class Code


With my new warpper in hand I am now able to create my data table:

private AbstractDataTable createMoneyTable() {
DataTable data = DataTable.create();

data.addColumn(ColumnType.STRING, "Label");
data.addColumn(ColumnType.NUMBER, "Value");
data.addRows(4);
data.setValue(0, 0, "France");
data.setValue(1, 0, "Germany");
data.setValue(2, 0, "USA");
data.setValue(3, 0, "Poland");
data.setCell(0, 1, 10, "$10,000", null);
data.setCell(1, 1, 30, "$30,000", null);
data.setCell(2, 1, 20, "$20,000", null);
data.setCell(3, 1, 7.5, "$7,500", null);
return data;
}

Once my data table is ready I can also create a select handler:

private SelectHandler createMoneySelectHandler(final PilesOfMoney chart) {
return new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
String message = "";

// May be multiple selections.
JsArray selections = chart.getSelections();

for (int i = 0; i < selections.length(); i++) {
// add a new line for each selection
message += i == 0 ? "" : "\n";

Selection selection = selections.get(i);

if (selection.isCell()) {
// isCell() returns true if a cell has been selected.

// getRow() returns the row number of the selected cell.
int row = selection.getRow();
// getColumn() returns the column number of the selected
// cell.
int column = selection.getColumn();
message += "cell " + row + ":" + column + " selected";
} else if (selection.isRow()) {
// isRow() returns true if an entire row has been
// selected.

// getRow() returns the row number of the selected row.
int row = selection.getRow();
message += "row " + row + " selected";
} else {
// unreachable
message += "Selections should be either row selections or cell selections.";
message += "  Other visualizations support column selections as well.";
}
}

Window.alert(message);
}
};
}

Create the Options method for this chart:

private PilesOfMoney.Options createMoneyOptions() {
PilesOfMoney.Options options = PilesOfMoney.Options
.create();
options.setTitle("Lots of money");
options.setCurrency("USD");
options.setCanSelect(true);
options.setMin(2);
options.setMax(70);
return options;
}

From my GWT onModuleLoad() method I can load the visualization api:
// Load the visualization api, passing the onLoadCallback to be called
// when loading is done.
VisualizationUtils.loadVisualizationApi(onLoadCallback,
CoreChart.PACKAGE);

Define my onLoadCallback:
// Create a callback to be called when the visualization API
// has been loaded.
Runnable onLoadCallback = new Runnable() {
public void run() {
Panel panel = RootPanel.get();

PilesOfMoney pom = new PilesOfMoney(createMoneyTable(),
createMoneyOptions());

pom.addSelectHandler(createMoneySelectHandler(pom));
panel.add(pom);

}

A couple of other things are still required
Modify your module.gwt.xml file and add the following import to support Visualizations:
  <inherits name='com.google.gwt.visualization.Visualization'>

Modify the GWT applications web page and add the following code:

    

Once you have everything done your visualization should be ready to go:
Stacks of Money Demo











You can also click on the stacks of cash and get a window alert showing the row of data that you clicked:
Stacks of Money with select event
















And finally the all important Wrapper Class for the Piles of Money chart:

/**
 * 
 */
package com.mynumnum.vis.client;


import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Element;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.AbstractDrawOptions;
import com.google.gwt.visualization.client.Selectable;
import com.google.gwt.visualization.client.Selection;
import com.google.gwt.visualization.client.events.Handler;
import com.google.gwt.visualization.client.events.ReadyHandler;
import com.google.gwt.visualization.client.events.SelectHandler;
import com.google.gwt.visualization.client.events.StateChangeHandler;
import com.google.gwt.visualization.client.visualizations.Visualization;


/**
 * @author Jim Hathaway
 * 
 */
public class PilesOfMoney extends Visualization implements
Selectable {


/**
* Options for drawing the chart.
*/
public static class Options extends AbstractDrawOptions {
public static Options create() {
return JavaScriptObject.createObject().cast();
}


protected Options() {
}


public final native void setTitle(String title) /*-{
this.title = title;
}-*/;


/**
* @param currency
*            String USD or EUR
*/
public final native void setCurrency(String currency) /*-{
this.currency = currency;
}-*/;


/**

* @param canSelect
*            boolean, if true (default), users can click on bars
*/
public final native void setCanSelect(boolean canSelect) /*-{
this.canSelect = canSelect;
}-*/;


public final native void setMin(int min) /*-{
this.min = min;
}-*/;


public final native void setMax(int max) /*-{
this.max = max;
}-*/;


}


public static final String PACKAGE = "pilesofmoney";


public PilesOfMoney() {
super();
}


public PilesOfMoney(AbstractDataTable data, Options options) {
super(data, options);
}


public final void addReadyHandler(ReadyHandler handler) {
Handler.addHandler(this, "ready", handler);
}


public final void addStateChangeHandler(StateChangeHandler handler) {
Handler.addHandler(this, "statechange", handler);
}


@Override
protected native JavaScriptObject createJso(Element parent) /*-{
return new $wnd.PilesOfMoney(parent);
}-*/;


public final void addSelectHandler(SelectHandler handler) {
Selection.addSelectHandler(this, handler);
}


public final JsArray getSelections() {
return Selection.getSelections(this);
}


public final void setSelections(JsArray sel) {
Selection.setSelections(this, sel);
}
}

Thursday, September 8, 2011

GWT 2.4.0 Release

Looks like it is time to upgrade GWT again. Version 2.4 of GWT is now available. See the release notes below:

Google Web Toolkit Release Notes:

'via Blog this'

Wednesday, January 12, 2011

GAE/GWT Book: Google App Engine Java and GWT Application Development

Daniel Guermeur asked me to share some information on this new GAE/GWT book.

As you might know from my GWT blog post about hosting GWT apps you can deploy your app to a simple servlet container like Tomcat.  Recently Google App Engine started supporting GWT applications for deployment, so this gives you the ability to use Google's massive infrastructure to deploy your GWT application.  There are some things that you will need to do differently however when deploying to GAE vs a standard servlet container, and the book 
Google App Engine Java and GWT Application Development is there to help you though the process of building your GWT application and deploying it to Google App Engine.  Through the different chapters of the book you will follow the authors as they build and deploy their GWT app Connectr.


To get a feel for what to expect with this book you can download Chapter 9 - Robustness and Scalability: Transactions, Memcache,and Datastore Design - for free!


Along with the free chapter 9 content you also will find:
  • An overview of what the book covers
  • A listing of the chapters found in the book with information on what topics will be covered
  • A section introducing the two authors Daniel Guermeur and Amy Unru
You can also find a nice description of the book and its chapters here if you prefer not to download the PDF file of chapter 9.


The book is now available for order now from Amazon.com


Amazon Reviews for this book
Use the Connectr App found in the book.


If you already have this book you can also
download the code from Packt.  Enter in your email address and you will receive a link to download link for the Connectr App source as found in the book.  For those of you who are interested Connectr source code is licensed under the Apache License, Version 2.0.

The Authors blog can be found here
 where you will find code updates and errata when they become available. 

Saturday, December 4, 2010

Free online GWT/GAE Book

If you are looking for a great source on developing with the Google Web Toolkit and Google App Engine check out this free online book. Link is below.
gwt-gae-book - Project Hosting on Google Code

Thursday, October 28, 2010

GWT 2.1 Released, download now

See what is new with Version 2.1 of GWT.
Download GWT 2.1.
You can also download the latest version of GWT using the download links on the right hand of this page ->

Wednesday, October 27, 2010

Latest Trunk Build of GWT Available Now

Often I find that waiting for the next build of GWT just takes too long.  Well this is not really true, builds of GWT come out as quickly as the GWT team can produce them.

So what if you are looking for the latest trunk build of GWT?  You can always build your own copy by checking out the source, checking out the tools, installing Apache Ant and then compiling the GWT code yourself as found here.  One thing about compiling it yourself is that it takes a while to complete, like upwards of an hour.

A few weeks ago I had a chance to start using Hudson to automatically build some of my GWT projects, then the though occurred to me that I could also use Hudson to build the latest trunk of GWT when there there is a source code change and then post the resulting output file.

As of today I am happy to share that you can download the latest GWT Trunk from my google code project. The project name is horrible as it does not have anything to do with GWT, but if you are looking for the latest GWT trunk build I am sure you can look past the poor project name.
If you would like to watch for the latest build via RSS you can use this feed here to watch for the latest trunk build.

Remember trunk builds of GWT are probably not something you want to move into a production environment, but sometimes you need the latest GWT build.

Quick Links:
My Google code project download section (get GWT trunk builds here).
RSS feed of the latest GWT trunk builds.

Thursday, August 5, 2010

Instantiations purchased by Google

According to the Instantiations web site they have been purchased by Google.  Here is a little info from their site:

We’re excited to announce that Instantiations is now part of Google!
Yes it’s true. Instantiations’ award-winning Java and Ajax development tools and our incredible Eclipse team have been acquired by Google. We are all very excited about taking our technology and team to the next level - and there is no bigger step up than Google!........

They also said that you should watch the official GWT blog for more information and I assume an official announcement from Google.
Google Web Toolkit Blog

Friday, June 11, 2010

New GWT 2 Development book: Essential GWT

I recently had the opportunity to be one of the technical editors for the book Essential GWT: Building for the Web with Google Web Tookit 2.

Some of the topics in the book are:



Getting started 

  • Some background on GWT, what it is, etc.
  • Understanding the tools you will need while developing with GWT such as Eclipse
  • Client side code vs server side code
  • OOPHM, compiler options, GWT application layout.
 Client Side Coding
  • User interface programming
  • Form designing using HTML, XML, UiBinder.
  • Other GWT packages such as ExtGWT
Server Communications
  • Remote Procedure Calls 
  • Communicating with other serivces like XML and JSON
  • Sending and receiving files
Building rich internet applications
  • Integrating JavaScript and calling it from GWT
  • Exception handling
  • Using other services and APIs such as Google search, Yahoo search
  • Internationalization (i18n) and Localization (i10n)
  • Testing your GWT app with Junit and test cases
I really enjoyed being a technical editor for this book.  The author Federico Kereki did a great job covering just about every topic you would need to create a powerful GWT application.

There were a couple of topics that were not covered in much detail, but I find they are things that I use in my daily GWT development:
1. Building ANT tasks that can automate your build process.  I have built scripts that compile server side code, gwt code and deploy to my Tomcat server of choice.  
2. Using GWT app engine with your GWT application.  You can either pay to have Tomcat hosting on the internet or you can use GWT app engine to host your GWT project for free.

I highly recommend this book, you can pickup a copy from Amazon:



Thursday, December 10, 2009

Upgrading GWT code from version 1.7 to version 2.0

I have already starting converting several of my GWT apps from older version of GWT to version 2.0.  According to this link the steps are as follows.

There are 3 tasks involved when upgrading a GWT 1.7 project to a GWT 2.0 project:
  • Download GWT 2.0 and update your launch configurations
  • HostedMode has been replaced by DevMode, so you will need to update your Eclipse project settings accordingly.
  • Tests now run in HtmlUnit by default. You will need to modify some of your tests to work with HtmlUnit.


So far I have not run into any issues with upgrading.  As of this post I have not seen any mention of a GWT 2.0 Incubator file, but my apps seem happy with the older version gwt-incubator-july-14-2009.jar.  I have seen several warnings however while compiling with this version such as:



         [WARN] Line 102: Referencing deprecated class 'com.google.gwt.widgetideas.table.client.overrides.HTMLTable'
         [WARN] Line 103: Referencing deprecated class 'com.google.gwt.widgetideas.table.client.overrides.Grid'
         [WARN] Line 104: Referencing deprecated class 'com.google.gwt.widgetideas.table.client.overrides.Grid'
         [WARN] Line 104: Referencing deprecated class 'com.google.gwt.widgetideas.table.client.overrides.HTMLTable'

GWT 2.0.0 is here. Get your copy today!

You can now download and start using GWT version 2.0.  If you are using Eclipse the links are below, and of course if you are already using Eclipse then you should be able to update to the latest plugin and GWT version automatically.

Eclipse 3.5 (Galileo)
http://dl.google.com/eclipse/plugin/3.5
Eclipse 3.4 (Ganymede)
http://dl.google.com/eclipse/plugin/3.4
Eclipse 3.3 (Europa)
http://dl.google.com/eclipse/plugin/3.3

If you would like to download the latest version of GWT without using Eclipse you can find the download here.


Some of the new changes:
Speed Tracer
Speed Tracer is a Chrome Extension that allows you to pinpoint performance problems in your web applications.
Downloading & getting started with Speed Tracer for Google Chrome


Speed tracer tutorial video


What's New in GWT 2.0?


New Features
  • Development Mode
  • Speed Tracer
  • Developer Guided Code Splitting
  • Compiler Optimizations
  • Draft Compile
  • Declarative User Interfaces
  • Layout Panels
  • Bundled Resources via ClientBundle
  • HtmlUnit for Testing
Video of changes in GWT Version 2.0:



Google Web Toolkit Gallery


Google Web Toolkit Showcase of Features





Wednesday, October 7, 2009

Announcing GWT 2.0 Milestone 1

If you are like me I am sure you have been patiently waiting for the release of GWT 2.0.  If you are ready to start some early testing of GWT 2.0 you can download a copy of the Milestone 1 release here.  It is interesting to note that you no longer need to download the appropriate version for you development environment.  Now you simply download this single version and then GWT will download the appropriate plugins for your browser. There are lots of changes in this Milestone 1 release so your best bet is to take a look at the release notes and also the GWT 2.0 Milestone 1 announcement  in the GWT group here.
Be on the lookout for bugs and you probably don't want to attempt to use this version in your GWT production environment at this time.

Saturday, August 1, 2009

GWT Google Plugin for Eclipse 1.1.0

For those of you using the GWT Eclipse plugin there is a new version. Of course if you installed in Eclipse and have automatic updates enabled then you probably know about this update already.

Here are some of the main features of this release:
- Support for Eclipse 3.5 (Galileo)
- GWT RPC interface validation with quick fixes
- App Engine DataNucleus enhancer console no longer steals focus on save

The GWT group thread on this new version is here.

Depending on your version of Eclipse you have different URLs for installation:

- Eclipse 3.5 (Galileo) - http://dl.google.com/eclipse/plugin/3.5
- Eclipse 3.4 (Ganymede) - http://dl.google.com/eclipse/plugin/3.4
- Eclipse 3.3 (Europa) - http://dl.google.com/eclipse/plugin/3.3

Thursday, June 4, 2009

GWT Tetris - Great Puzzle Game from the 80s



I am sure there are some of you out there that have never heard of the puzzle game Tetris. Seems like the 1980s was just a few years ago, ah how time flys. I first played the game Tetris on my Tandy Color Computer 3, and played and played. I absolutly loved the game! Funny, I still love the Color Computer too. Here is a screen shot of Tetris on the Color Computer:

Some time ago I tought it would be a fun little project to take the game Tetris and write a GWT version of it. Well now someone has already done it. A few days ago on the Google Web Toolkit Group I noticed a post about Tetris. I had to give it a try, and I was quite impressed with the result:

I had a chance to talk to the author Janusz Prokulewicz and asked him a few questions about the development of this game.

Some time ago Janusz created a Java version of his Tetris game. Having created the same game as a linux shell application over 4 years ago he was able to get his Java version working in three days. So the real question, how hard was it to convert to GWT and how long did it take? To quote Janusz: "It took me 2 and a half days (or rather nights) to do it".

So we have an existing Java application that Janusz was able to convert it to GWT in two nights. The game can now be played in any modern browser with no special plug-ins and no goofy browser quirks to worry about. Write it once in GWT and compile and you are ready to go.

Unfortunately at this time he does not have a web site that contains his other work, maybe in the future he can set something up.

He used GWT version 1.6.4 with no additional libraries.
The game is deployed with a PHP backend using JSON to get/send data to the server.

Janusz's web site is here.

Update June-8-2009: Janusz now has a blog setup. You can see his site here.


Wednesday, April 8, 2009

GWT support in Google Apps Engine AND GWT 1.6

Big news today for GWT!

First GWT 1.6 is available for download. Please see the official blog entry from Google here.

Second big annoucement for GWT is that the Google Apps Engine now supports Java. One thing to be aware of is that google has said that they are only allowing the first 10,000 developers. Better sign up fast. Here is the link to signup.

The also ask that you provide feedback, here is that link.

To find out more please see the official blog post from Google here on Google App Engine supporting Java.

For those of you using Eclipse for Java development (and I highly recommend you use it) there is now a GWT/App engine plugin for Eclipse.
For more information on the plugin see this Blog post.

The quick start guide to install the GWT/Google App Engine Eclipse plugin is here.

If you are already an eclipse user and know how to install plugins here are the shortcuts you need:

Eclipse 3.3 (Europa)
http://dl.google.com/eclipse/plugin/3.3

Eclipse 3.4 (Ganymede)
http://dl.google.com/eclipse/plugin/3.4

Friday, February 13, 2009

GWT 1.6 Milestone 1 available for download

This is the latest GWT release, it is a milestone release so be sure to only use it for testing.
If you are like me and use Eclipse to develope your GWT application there is a nice change that is part of this release. You no longer need to run these commands to create a new GWT Eclipse project:

C:\Program Files\gwt-windows-1.5.3>applicationCreator.cmd -eclipse MyGWTProject -out c:\MyGWTProject com.mynumnum.client.MyClass
Created directory c:\MyGWTProject\src
Created directory c:\MyGWTProject\src\com\mynumnum
Created directory c:\MyGWTProject\src\com\mynumnum\client
Created directory c:\MyGWTProject\src\com\mynumnum\public
Created file c:\MyGWTProject\src\com\mynumnum\MyClass.gwt.xml
Created file c:\MyGWTProject\src\com\mynumnum\public\MyClass.html
Created file c:\MyGWTProject\src\com\mynumnum\public\MyClass.css
Created file c:\MyGWTProject\src\com\mynumnum\client\MyClass.java
Created file c:\MyGWTProject\MyClass.launchCreated file c:\MyGWTProject\MyClass-shell.cmd
Created file c:\MyGWTProject\MyClass-compile.cmd

C:\Program Files\gwt-windows-1.5.3>projectCreator.cmd -eclipse MyGWTProject -out c:\MyGWTProject

Created directory c:\MyGWTProject\test
Created file c:\MyGWTProject\.project
Created file c:\MyGWTProject\.classpath


Now all you need to do is run the command webAppCreator:

C:\Program Files\gwt-windows-1.6.0>webAppCreator.cmd -out c:\MyGWT16Project com.
mynumnum.MyClass
Created directory c:\MyGWT16Project\src
Created directory c:\MyGWT16Project\war
Created directory c:\MyGWT16Project\war\WEB-INFCreated directory c:\MyGWT16Project\src\com\mynumnum
Created directory c:\MyGWT16Project\src\com\mynumnum\client
Created directory c:\MyGWT16Project\src\com\mynumnum\server
Created file c:\MyGWT16Project\src\com\mynumnum\MyClass.gwt.xml
Created file c:\MyGWT16Project\war\MyClass.html
Created file c:\MyGWT16Project\war\MyClass.cssCreated file c:\MyGWT16Project\war\WEB-INF\web.xml
Created file c:\MyGWT16Project\src\com\mynumnum\client\MyClass.java
Created file c:\MyGWT16Project\src\com\mynumnum\client\EchoService.java
Created file c:\MyGWT16Project\src\com\mynumnum\client\EchoServiceAsync.java
Created file c:\MyGWT16Project\src\com\mynumnum\server\EchoServiceImpl.java
Created file c:\MyGWT16Project\build.xml
Created file c:\MyGWT16Project\.projectCreated file c:\MyGWT16Project\.classpath
Created file c:\MyGWT16Project\MyClass.launch

Your new GWT 1.6 Project will be ready for import into Eclipse. Also you will notice that a simple client and server class is created in the example that demonstrates how to send and receive RPC requests.

Errors when launching your Eclipse GWT project in the GWT shell

You must create a lib folder in your 'project folder'/war/WEB-INF folder and copy gwt-servlet.jar into that folder.
After this is done you should be able to launch your new Project without this nasty error message:


2009-02-13 12:22:51.760::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2009-02-13 12:22:51.901::INFO: jetty-6.1.x
2009-02-13 12:22:52.229::WARN: failed echoServlet
java.lang.NoClassDefFoundError: com/google/gwt/user/client/rpc/RemoteService
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)



Monday, December 22, 2008

Another GWT Powered Web Site sendMeHome.com

It seems that these question always comes up on Google-Web-Toolkit group :
  • Who is using GWT?
  • Is GWT ready for prime time?
  • Why would anyone use GWT when they can use language X and toolkit Y?
  • Does Google even use GWT for their web pages?

I have been using GWT in a 24x7x365 day production environment for over two years now and I can tell you that GWT is ready to deliver on the promise of easy and reliable Ajax web development.

As for the question of 'who is using GWT?' I would like to share some information from the guys over at SendMeHome.com

Their site uses GWT and the GWT incubator project. I spoke with one of their developers and he was nice enough to share some details of their experience with GWT, what GWT widgets they are using, and their overall opinion on the Google Web Toolkit. Please see the details below:

SendMeHome was developed over the course of four months. We chose GWT to create SendMeHome as it allowed us to code in a familiar language (Java), provided a wide array of widgets, and could deliver the type of end user experience we wanted to provide.

Although the GWT compiler is quite intelligent and removes any unused functions and libraries at compile-time we wanted to keep SendMeHome as small as possible as some of our users may be accessing the site on a dial-up connection. To do this we consciously tried to only use widgets in the gwt jar file, these include:

  • Text Box / Password Text Box / Text Area / Rich Text Area
  • Radio Buttons and CheckBoxes
  • File Upload
  • Tree
  • iFrame
  • Toggle and Push Buttons
  • Grids and FlexTables
  • Just about every panel available, including the Tab, Decorator, Disclosure and Popup Panels

We initially broke our own rule when we discovered the Glass Panel from the incubator. We used it to create a “Lightbox Effect” for our login and error messages. However, we really began using Google’s other API’s when we developed our Stories feature. Stories allows you to track where a physical item travels to and lets you collect stories from the people it meets. To enhance Stories we integrated with Google Maps and YouTube and the process was stunningly simple. We now host all of our videos on YouTube and our users never have to visit YouTube.com or even have a YouTube account.

The only complaint we’ve had with GWT is that browsers cannot remember a user’s email and password easily. Otherwise it was been an absolute joy to work with and we are surprised that there aren’t more GWT apps out there!



Sunday, December 21, 2008

Eight Queens Puzzle Solution GWT style

I have deployed a very 'rough' GWT application, you can check it out here.  This is an Eight Queens Puzzle solution using GWT.  Hosting is with Mochahost using Tomcat.  Technically there is no reason to host this application with a Tomcat instance, but I thought it would be fun to take the same Java code and let Tomcat run the Eight Queens solution on the server and then let GWT compile the Java code to Javascript and run it on your client browser.

With a fast processor and Google Chrome I don't see why someone out there cannot beat the calculation time for the puzzle on their browser!  The bulk of the time on the browser is spent building the chess boards and populating the queens onto the board.  The Eight Queens Puzzle solution just takes a few seconds, or in the case of Crome miliseconds.

Lots more to come including:
  • Source code
  • Make the web page look better

Some other ideas I had:
  • Capture user agent information and store calculation times based on browser type and OS
  • Add a selection box so the user can select their processor speed and save this data with the solution time.
  • Build a report showing data based on cpu speed, browser type, bowser version, and OS
For more information on how to setup GWT with Tomcat hosting using Mochahost please see my previous post on GWT hosting.

Please leave me any feedback here.  Thanks!

Tuesday, December 2, 2008

Calling all GWT web sites!

I would love to hear from anyone currently using GWT for a web site or anyone that is in the process or using GWT for a new web site. Please post comments here with your site address and description. If you really feel nice you can also add in all the other libraries or technologies that you incorporated in building your GWT powered site. BTW - my favorite GWT combination is GWT 1.5 + GWT Incubator + Eclipse + Apache Tomcat 5.5

Thanks!

Sunday, October 19, 2008