Getting Started with Spring RCP
Enabling Actions
Let's now look at the menubar. Several menu items are available by default. Where do they come from? Our simple application contains no Java classes that have anything to do with menu items. So, what's going on here?
Menus and toolbars are all declared in the "command-context.xml" file. That file and its contents, in turn, are declared in the "richclient-application-context.xml" file, which is the application context XML file that is loaded at startup.
- Open the "richclient-application-context.xml" file and take note of the declaration of the command-context.xml file, as follows, in line 3:
<bean id="lifecycleAdvisor" class="simple.SimpleLifecycleAdvisor">
<property name="startingPageId" value="CustomerView" />
<property name="windowCommandBarDefinitions" value="ui/commands-context.xml" />
<property name="windowCommandManagerBeanName" value="windowCommandManager" />
<property name="menubarBeanName" value="menuBar" />
<property name="toolbarBeanName" value="toolBar" />
</bean>Note: The menubar and the toolbar are also declared above and are then further spelled out in the "command-context.xml" file.
- Notice the third line above and then open that file, i.e., the commands-context.xml file. Let's start by looking at the Help menu:
So, the "Help Contents" item is disabled, while the "About" item is enabled. Why?
- Look at the "menuBar" bean in commands-context.xml, where you'll find that one of its members is "helpMenu". Hold down the Ctrl key and move your mouse over the "helpMenu" text and you will see a hyperlink:
Click it and you will jump to the "helpMenu" bean, which is defined as follows:
<bean id="helpMenu"
class="org.springframework.richclient.command.CommandGroupFactoryBean">
<property name="members">
<list>
<value>helpContentsCommand</value>
<value>separator</value>
<ref bean="aboutCommand" />
</list>
</property>
</bean>
<bean id="aboutCommand"
class="org.springframework.richclient.command.support.AboutCommand" /> - Now you can see why the "Help Contents" item is disabled, while the "About" item is enabled. In the first case, only a value has been declared, while in the second case there is a reference to a bean, for which a class has been defined that handles the invocation of the menu item. Let's do the same for the "Help Contents" item, starting by creating a new bean for the "Help Contents" item:
<bean id="helpContentsCommand" class="org.springframework.richclient.command.support.HelpContentsCommand">
<property name="helpSetPath" value="help/simple-hs.xml" />
</bean>Note: We refer above to "help/simple-hs.xml". That's the JavaHelp helpset file that is the entrypoint to our helpset. You could create that by hand, as well as all the files that are needed to set up a JavaHelp helpset. Instead of that, save yourself some time and trouble by going back to the New Project wizard (Ctrl-Shift-N) and in the "Samples" category you will find some Spring Rich Client samples. Complete the wizard for one of them and then copy its "help" package into the "Resource Packages" node of your own application. Hurray you now have the start of your own helpset.
- Finally, we need to hook the bean up to our help menu, replacing the value with a reference to the bean, as shown below, in the same way as is done by default for the About item:
<bean id="helpMenu"
class="org.springframework.richclient.command.CommandGroupFactoryBean">
<property name="members">
<list>
<ref bean="helpContentsCommand"/>
<value>separator</value>
<ref bean="aboutCommand" />
</list>
</property>
</bean> - Run the application and now the "Help Contents" item is enabled. When you click the item, the JavaHelp from the sample appears.
| Attachment | Size |
|---|---|
| figure-1.png | 49.01 KB |
| figure-2.png | 37.15 KB |
| figure-3.png | 10.45 KB |
| figure-4.png | 24.74 KB |
| figure-5.png | 49.25 KB |
| figure-6.png | 9.61 KB |
| figure-7.png | 62.91 KB |
| figure-8.png | 22.96 KB |
| figure-9.png | 108.96 KB |
| figure-10.png | 64.77 KB |
| figure-11.png | 121.18 KB |
| figure-12.png | 25.68 KB |
| figure-13.png | 20.96 KB |
| figure-14.png | 105.25 KB |
| figure-15.png | 3.28 KB |
| figure-16.png | 6.23 KB |
| figure-17.png | 94.77 KB |
| figure-18.png | 80.02 KB |
| figure-19.png | 26.8 KB |
| figure-20.png | 24.82 KB |
| figure-21.png | 2.76 KB |
| figure-22.png | 9.17 KB |
| figure-23.png | 98.88 KB |
| figure-24.png | 99.05 KB |
| figure-25.png | 117.51 KB |
| figure-26.png | 99.56 KB |
| figure-27.png | 89.89 KB |
| figure-28.png | 109.22 KB |
| figure-29.png | 211.88 KB |
- Login or register to post comments
- 56871 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Jacek replied on Tue, 2008/07/01 - 6:31am
Don't get me wrong, it's a nice effort...but the amount of XML config required to make the most basic of setup makes my stomach turn. Really, most of this should be one method call to some common ancestor or static class to register and configure your views.
I don't want to even think what sort of havoc you could wreck on your app if you did any major refactoring of your code and your IDE didn't update the Spring XML files correctly.
It seems like the wrong solution for an issue than in 95% of the cases will not change over time any way and hence does probably not need to be soft-coded in XML, down to every last little detail.
But Spring is the hot kid on the block these days, so I guess that's the way everyone is going...I for once would prefer that someone creates something equivalent but lets you configure it with simple annotations like EJB 3.0. Isn't annotation support part of the new Spring release?
Could this example be re-worked to avoid configuring every single detail in XML and using the new Spring annotations instead?
Geertjan Wielenga replied on Tue, 2008/07/01 - 6:46am
Jacek replied on Tue, 2008/07/01 - 6:52am
Yes, but let's face it....since the project lead left to join Adobe, JSR-296 seems to be as dead as the dodo, if I recall correctly.
https://appframework.dev.java.net/servlets/ReadMsg?list=users&msgNo=1567
The last release is from Nov 2007 when Hans was still employed with Sun...doesn't exactly install confidence in the long term viability of this JSR. Say what you want about Spring, but at least it has a large active community.
Geertjan Wielenga replied on Tue, 2008/07/01 - 6:58am
in response to: Jacek
Yes, but let's face it....since the project lead left to join Adobe, JSR-296 seems to be as dead as the dodo, if I recall correctly.
https://appframework.dev.java.net/servlets/ReadMsg?list=users&msgNo=1567
The last release is from Nov 2007 when Hans was still employed with Sun...doesn't exactly install confidence in the long term viability of this JSR. Say what you want about Spring, but at least it has a large active community.
[/quote]
True enough, except that Spring RCP hasn't existed in any real form over the past years. Now it's back but there's no guarantee that it'll go anywhere. (The 1.0.0 release just came out, after two years, and so who knows when the next release will be with us?) I would personally like it to do so (hence this article and hence the tooling I'm providing, should you need evidence), but there's no guarantees (hard to argue with Kirill's comments here). In that sense, depending on Spring RCP is as problematic as depending on JSR-296, but for different reasons. (And that's why I focused only on the technology in this article without being distracted by the politics around it.)
Jacek replied on Tue, 2008/07/01 - 7:03am
in response to: geertjan
doclolieven replied on Tue, 2008/07/01 - 10:15am
in response to: Jacek
Don't get me wrong, it's a nice effort...but the amount of XML config required to make the most basic of setup makes my stomach turn. Really, most of this should be one method call to some common ancestor or static class to register and configure your views.
[/quote]
You're right, but the registration you speak of is just the sort of locator pattern we want to refactor out of the system. I'm looking into the annotation based configuration, which works great as long as you don't do a lot of configuration besides injecting other beans (f.e. using a propertyplaceholder configurer in conjunction with the component scanning provided in Spring 2.5 is proving to be a real PITA).
I don't think the XML configuration is that much of a burden, if you have a good IDE with Spring support I don't think you'll have a lot of issues. I've worked in a company where all products were made with Spring RCP, and I haven't encountered any problems concerning writing all those bean definitions. There could be some improvement, but I'm thinking more in the line of custom namespaces.
Anyway, you're right in many ways. Things should be simplified. But then again, writing all my forms in YAML also seems a real hassle, and I'm sure a refactor will certainly cause all sorts havoc there too... :)
Jacek replied on Tue, 2008/07/01 - 10:23am
in response to: doclolieven
Point taken :-) I guess I just like YAML a lot more than XML (and I think writing the forms in YAML is a lot less hassle than coding them by hand, but hey...I recognize it's an off the beaten path approach).
It just seems that with Spring it's an all or nothing proposition, even the most basic config stuff is externalized. Seems overkill for 90% of apps.
Peter Karich replied on Tue, 2008/07/01 - 4:24pm
Great Geertjan!
Thanks a lot!
Does NetBeans handle the refactoring in XML? If yes, how?
>> Secondly, you can try the Swing Application Framework (JSR-296) if you want annotations rather than XML.
Isn't it possible to configure Spring with Java or a scripting language? In picocontainer this is possible with nanocontainer.
Any hints?
Geertjan Wielenga replied on Tue, 2008/07/01 - 4:29pm
Peter Karich replied on Wed, 2008/07/02 - 2:22am
But wouldn't it be cool to provide those things?
Then NetBeans will be the SpringRC-IDE ;-)
Hint: To create the simple app with your plugin it is required to have the jdk1.6 as default (javax.swing.GroupLayout)
Rohan Ranade replied on Thu, 2008/07/03 - 7:29am
weggyboy replied on Fri, 2008/09/19 - 4:15am
Hello!
Excuse me, if this is the wrong place for such questions.
I was interested in using a view to display the changes made in another view, both dockable.
How would you do that, when the both views are not known and they are created by the VLDockingApplicationPageFactory?
I though I could implement the Observer Pattern, but since the views are created by the factory I can´t get any Observable object registered in the Observer View.
Any Ideas?
Thanks!
Peter Karich replied on Fri, 2008/09/19 - 11:21am
in response to: weggyboy
Why not adding a listener to the model instead to the view?
Maybe more details are necessary to help you.
weggyboy replied on Sat, 2008/09/20 - 3:03am
in response to: peathal
Thanks for your answer Peter!
What I´ve done is exactly that, just I´m having some problems with the GUI actualization, since the form inputs works on a DialogWizard. The Other docked View must first be "resized" before the changes can be shown... Tipical GUI Problem...
Best Regards!
Wagner
prabithchandranr replied on Tue, 2008/10/07 - 8:47am
watcher replied on Thu, 2009/10/01 - 5:30am
venkatambati replied on Tue, 2009/10/27 - 5:29am
surajchhetry replied on Wed, 2009/11/11 - 10:56pm
Hi,
I am working on desktop application on Java we have Eclipse RCP,Netbean RCP,Spring RCP and etc. Currenly iam using Netbean RCP but my application using Spring a lot means IOC,AOP and DAO so is it wise to switch to Spring RCP from Netbean RCP ??