Spring Rich Client - Part 1

Today I will start a series about the great Swing framework called Spring Rich Client (SRC). The 1.0.0 version was released in March 2008 and it is not inactive as I thought before.

You can get more information about SRC from:

Why I listed the forum as the first point? Because for a beginner like me it was the best source of information (after the samples).

So, let us set up a hello world example.

  • Download the Spring Rich Client 1.0.0 from here (19 MB, Apache License 2.0).
  • Download my Hello World skeleton (a NetBeans 6.1 project, 60 KB) or use the spring-richclient-archetype from the download bundle of SRC, where you have to install maven before you can compile and run it.

If you use my Hello World skeleton you should open it in NetBeans, right click on the project node and resolve reference problems. Then go to the place where you have unzipped the SRC and add the first jar file. The other jar files should be added automagically for you.

The project with dependencies would be about 2.7 MB, it is not a small overhead, but okay, I think. As an example for the reader one can compare it to the minimal size of the NetBeans or Eclipse RCP.

Now it is time to start the project with F6 or Run->’Run Main Project’. You should see the frog-splashscreen and the final view:

Now let me explain several things that one could customize in SRC. Please see the Resources section for the result of customization.

As the first point I wanted to know how easy it is to introduce docking capabilities (vl docking). It was really easy!

  • add spring-richclient-docking.jar and vldocking.jar
  • and change 2 things in the richclient-application-context.xml file:
  • change class of initialView to org.springframework.richclient.application.docking.vldocking.VLDockingViewDescriptor
  • add a applicationPageFactory to the richclient-application-context.xml

Then you can add a new window to see the results of dragging:

  • Create the class View2
  • add the following to the richclient-application-context.xml:

    <bean id=”view2″
    class=”org.springframework.richclient.application.docking.vldocking.VLDockingViewDescriptor”>
    <property name=”viewClass” value=”de.peterk.springr.View2″ />
    <property name=”autoHideEnabled” value=”true” />
    <property name=”closeEnabled” value=”true”/>
    </bean> 
    


    and you are done! Just start the application go to Windows->Show View->View2

Now, how easy is it to use your own layout? Configuring the look and feel:

  • Remove the lookAndFeelConfigurer and add instead:

    <bean id=”lookAndFeelConfigurer” class=”de.peterk.springr.ui.KunststoffConfigurer”></bean> 
    
  • remove looks.jar: 350 kb
  • add kunststoff: 17 kb
  • add the KunststoffConfigurer class to the source package

Okay, then changing the splash screen is trivial: just overwrite the splash-screen.png or change the path in the richclient-startup-context.xml file.

Now we should adjust the size of the view, this can be done with 2 lines in the method SimpleLifecycleAdvisor.onPreWindowOpen:

Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
configurer.setInitialSize(new Dimension(rect.width, rect.height));

And to translate the messages simply copy all property files to e.g. file_de.properties and translate them! In our case it means “cp message.properties message_de.properties”. If you want to add a translateable tool tip of the initalView-label just use:

  • lblMessage.setToolTipText(getMessage(”initialView.toolTip”));
  • in InitialView.createControl and add the property initialView.toolTip to the property file.

To set a keyboard shortcuts e.g. to leave the application. You need to add one line to the message.properties file

  • exitCommand.label=Exit@ctrl Q

Another interesting action (in SRC they will be called commands) could be restart. So how can we add the action into the menu? You have to add

  • restartCommand.label=Restart@ctrl R
  • in the message.properties file and use
  • Application.instance().start(); Application.instance().getActiveWindow().close();
  • within your RestartCommand class. Then add
  • <bean class=”de.peterk.springr.RestartCommand” />
  • into the commands-context.xml (e.g. after <value>propertiesCommand</value> in fileMenu)

The final result is:

Resources

Here you can download the extended “hello more” sample (a NetBeans 6.1 project about 90 KB, without dep). The full project was 2.9 MB.

Conclusion

One can say that Spring Rich Client is a powerful jar collection :-). But I would say SRC is a great way for your next swing application!

It is very intuitive to use: the whole sample (including to write this blog) took me only about 6 hours. I think you could be really productive with it! In the case I published the documents with mistakes: please leave your comment here!

From http://karussell.wordpress.com/

0
Average: 3.5 (2 votes)

One spare time killer for me is my timetabling open source project TimeFinder. I work for Pannous GmbH where we create Software with Java, Ruby and C#. Peter is a DZone MVB and is not an employee of DZone and has posted 18 posts at DZone. You can read more from them at their website.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

bguerout replied on Fri, 2008/06/20 - 10:12am

Happy to see that SRC is not dead (I used it in 2005), but i'm not sure this project is healthy (releases separated by two years ...).

Peter Karich replied on Fri, 2008/06/20 - 12:34pm in response to: bguerout

[quote]but i'm not sure this project is healthy (releases separated by two years ...).[/quote]

Yes, thats true. But the forum is quite busy and the people there (I guess user and developer) are very helpful.

And I think that SpringRCP has more 'traffic' than e.g. a similar project called 'appframework'.

doclolieven replied on Fri, 2008/06/20 - 3:43pm

Spring Rich Client will be transformed into Spring Desktop, as you can read from the website. Our goal is to merge all existing code, fix the current bugs while not being bound to the current codebase.

The Spring Desktop will, hopefully, also be larger and be more out-of-the-box usable (with a lot of usable components) than the current RCP project.

Normally in about 3 weeks there will be a maintenance release of RCP. Yeah, it's true that the project was stagnant, but was more an issue of manpower than quality of the code.

I urge everyone to take a look, we need fresh opinions to make sure Desktop becomes what people want and need. Mark my words, you'll be hearing a lot of us :).

Moch Nasrullah R replied on Sun, 2008/06/22 - 6:12pm

Is it okay to put XML configuration in client machine?

Jeroen Wenting replied on Tue, 2008/06/24 - 12:38am in response to: zrvl

why shouldn't it be? Would be best packed in a jar to deter at least casual changes by users unaware of the consequences though.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.