Getting Started with Spring RCP
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" />
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:
<ref bean="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" />
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:
<ref bean="aboutCommand" />
- Run the application and now the "Help Contents" item is enabled. When you click the item, the JavaHelp from the sample appears.