In this article we will take a deep look into what are the files Roo generates as there is not enough documentation for a beginner.

First download SpringSource Tool Suite from http://www.springsource.org/roo/start. ( You can also try with Spring Roo Command line and Normal Eclipse Installation ). But lets stick to STS as it provides integration with all spring libraries and Maven build tool.

Once you download the installer/Archive for the STS, install it. ( I downloaded the installer exe as it was lot smaller than the archive file ). Installing the STS using the exe file should be straight forward. Just make sure you install all the default packages.

Lets start the STS.exe from the installed location. ( Just incase if you have to search for it, It should be inside sts-2.x.x-RELEASE folder inside the installed folder ). Launching the STS.exe would take a while to load ( It's a huge application with lot of eclipe plugins to be loaded). Once it launches, you will see the welcome page like below.

To install the GWT tools (including the SDK), you simply navigate to the Install Extensions Page. GWT plugin is in Language and Framework tooling sections in the Extensions Tab on the dashboard. The Extensions tab also has few interesting extensions like EclEmma, a code coverage tool, Tasktop Pro, a time tracking tool and so on. But they are optional to follow this article. You will asked to restart the STS after installing the plugins.

Now we have SpringSource Tool Suite with Google Web Toolkit with the SDK installed. You will see the google web toolkit actions on the toolbar now as shown in the diagram below.

Lets start with GWT Project creation using Roo shell from Window->Show View -> Roo Shell. ( Since we have installed GWT Plugin, you can also generate the GWT Project using Web Application Project wizard. But that doesnot use Roo's magic of generating all the boiler plate code ).

On the Roo Shell View click on "Create New Roo Project" action on the toolbar. Fill in the required information on the roo project creation like Project Name, Top level package name for the GWT Project and click on Finish on the wizard's Next Page. STS creates the Roo project with AspectJ Support, it requires AspectJ weaving support to be enabled. Enable AspectJ weaving and restart the workbench. The Roo_GWT project will be like as shown below.

Click on Open Roo Shell on the Roo Shell view and choose Roo_GWT project. The Roo shell loads the Roo_GWT project and starts the roo.

Now to create the GWT project layout on the Roo_GWT project,from the roo prompt type in gwt setup

Generated web.xml and webmvn-config.xml for the Server side configuration. The web.xml contains all the servlet mapping and Spring application context loading defined. The applicationContext.xml file gets created when you create the roo project using the New Roo Project wizard, but the file will not have any details about the persistence mechanism.

Client Scaffold Package - Roo by default generates classes for viewing the application on a Desktop browser and Mobile Browser. There will be classes with Desktop and Mobile in the class name for the UI.

Client Scaffold UI Package - Contains basic ui boxes.

Client Scaffold IOC Classes to Inject dependencies using Guice/Gin. - Contains Injector classes for Desktop and Mobile to return the respective Application as the entry point.

Now that we have the basic project structure created we can add persistence support. Roo supports adding different types of Persistence mechanism and database. For example if you want to use Hibernate with in memory database.

We can see that roo modified the applicationContext.xml with dataSource information, added a persistence.xml file with the hibernate properties, database.properties file with database details and updated the pom file with all the dependencies.

Now run the application as a Web Application ( Right Click-> Run As -> Web Application). From the development mode view double click the url which will launch the application in your default browser. You can see the application as shown below.

You can click on Create Contact and Add new contact like belowWe have written no queries, no business logic for the Contact object. But we got the Create contact , contact list, edit contact. This is where Roo comes in really handy. It generates a default set of queries, ui when we gave the commands "field string --fieldName name --notNull" Roo updates the ContactProxy object with the new field.

Where are the queries

If you look at the domain package for the Contact object ( disable all the filters on the package explorer as by default only java classes are shown for a package ) you will find .aj files with *Roo_Configurable.aj, *_Roo_Entity.aj, *_Roo_JavaBean.aj, *_Roo_ToString.aj files.

Specifically Contact_Roo_Entity.aj file will have all the query for interacting with the database.

These methods return the required data to the UI via the RequestFactory as ContactProxy Objects. ( You will understand this if you have read the GWT RequestFactory Article ). The methods in the aj files can be overwritten in the Contact entity class in which case Roo will remove the method from the .aj file. (Read more on this here http://static.springsource.org/spring-roo/reference/html-single/index.html )

Overall, Roo is pretty good at generating and maintaining all the boiler plate code which is a painful job to write. But it can only generate based on a simple application structure. Not all applications are just Master/Detail layout.

How do i use Service Layer with the Request Factory

According to GWT 2.1 you cant do this as RequestFactory is tightly bound with the Domain Driven Development approach. According to google service layer approach is going to be supported in GWT 2.1.1.

Wednesday, July 15, 2009

There are methods of maintaining a single instance of an application. Most often the application creates a lock file and holds on to it during the lifecycle of the application.

A new instance of the application will try to find this file and if it exists, the application will try to show the existing instance to the user, preventing from creating whole new instance of the application. One drawback of this approach will be if the application crashes leaving the lock file. The user has to manually delete the file (or application can try deleting this file )

The same can be achieved via opening a server socket when the application is opened. Now how do we do it for a simple RCP Application.

Now when the application is launched for the first time, it will open a server socket 5000 and will start listening on it. The next instance of the application will check the server port and if it is used already, it will create a client for that server socket and send a message to the server.

When the server receives any message from the client, it will reopen the instance which created the server socket.

The handleEvent method on the WorkbenchWindowAdvisor will have to have the following code..

Friday, July 10, 2009

Its sometimes tedious to find the real exception occured when using an eclipse based application. Since it goes under the workspace/.metadata/.log file. It takes a while to figure this out. But most of the desktop application do write to a log file of its own. So when using eclipse using two log files to know about the application is kind of not nice.

But still eclipse provides a way to listen to the log messages of its own. So if the application uses its own logging , it can listen to the eclipse log and add it to its own logger. Here we will look at connecting eclipse log messages to the log4j logger.

Monday, July 6, 2009

It took a while to understand and create a custom widget but finally i could do it. I wanted to create a custom widget to draw sequence of svg graphics. I followed the Custom widget development at the RAP help site. It helped me to get a good start but since i was trying to do SVG it didnt really work at my first attempt..(i know... nothing works at the first attempt).

The SVG support i wanted to create was something like below.

Here is what i did to create a custom widget.

1. Create a new plugin project and name it like com.xyz.project.mywidget This is not mandatory but its good to call the plugin as the widget name.

2. Create a package com.xyz.project.mywidget This package will contain the server side, client side and API resource classes. Just follow as explained in the RAP help.

3. Create the server side Widget class , i wanted a widget to send events to the server and also behave as a selection provider when a image is clicked. So i extended SWT Composite and implemented ISelectionProvider.

Now that the server side, widget is ready, we need the client side widget code, the qooxdoo javascript code. Read the qooxdoo explanation in RAP custom widget tutorial and follow it, it gives you a basic idea of what to do.

Now that, whenever the setImages method is called on the server side widget, the client has to update the browser. But how does it interact, the server side widget and the client side widget get connected through two main classes, the API resource class and the LCA class. There are different ways of defining the LCA class but here i would just follow the simple approach as explained in the RAP help.

First to create the API resource, we need to create a IResource implementation , In our case, MyWidgetResource as follows,

you can just copy and paste the above code and replace the getLocation method to your .js file. Now the LCA, this can either be written in a pre defined package or can be done using getAdapter method in the widget class. I will follow the pre defined package which com.xyz.project.mywidget.internal.mywidgetkit and create MyWidgetLCA.java

Here, the LCA class is the important class which communicates between the server code and client script. The selection on the client sends an event to the server through the LCA in the readData method. The client code will use org.eclipse.swt.Request.getInstance() to send the request to the server when an image is clicked on the Widget.

Now we got the both the resource and LCA ready. we need to create an resources extension point and add the MyWidgetResource classes.

ok..we have a basic setup ready, what is the Raphael stuff on the Qooxdoo javascript. Raphael is a Javascript based SVG library which helps creating different SVG based graphics. For more details on that visit http://raphaeljs.com/. The demos explain a lot about the library. How do we add an external javascript resource into the myWidget implementation.

1. Create a RaphaelAPIResource similar to the one we created for MyWidget as MyWidgetResource.

Since we are displaying images on the client side , we need the images also as resources sent to the client. we have to create http.registryresources to use aliases for the images. In this case, we are referring to Part_icon_image1.png and Part_icon_image2.png as alias in the javascript.

Thursday, March 5, 2009

Eclipse RCP applications store the prefrences and settings in the workspace. When a RCP application is exported, the workspace is opened within the application folder unless the workspace location is overridden. This will make every user who uses the application to use the same preferences. To enable the preferences and workbench state to be user specific, the default location of the workspace can be configured in the config.ini file as follows.

osgi.instance.area.default=@user.home/eclipseworkspace

Now the preferences and other dialog settings will be written in the user's own workspaces.

To restore the perspctive to the last modified state, eclipse stores the workbench state to a file called workbench.xml. To enable the save and restore layout, the IWorkbenchConfigurer must be set in the ApplicationWorkbenchAdvisor.

Monday, March 2, 2009

When you want to add console message to the eclipse console view, there is no easiest way to do this. The sysout/syserr messages will go on the console where you have the application if you run it with -consoleLog option.

How do we show the messages on the console view eclipse provides. First of all we have to add the console view to the perspective. The console view is part of the org.eclipse.ui.console plugin, so add it to the dependencies if you dont have it already.

Now add the ConsoleView to the perspective in the createInitialLayout method ( the following snippet is written with the RCP Mail example )

Now if you run the application you can see the console view at the bottom of the Messages view of the RCP Mail application. But now there are no open consoles on the console view. Now let us take an example, whenever a Messages view is opened we want to write something to the console.