---
title: "spring-richclient开发swing应用程序 4"
author: "lujar"
date: "2005-09-03T18:50:00Z"
tags: []
slug: "spring-richclient-swing-4"
draft: false
lastmod: "2005-09-03T18:50:00Z"
id: 253918
url: "https://lujar.iteye.com/blog/253918"
---

spring-rcp里面简单到极点（相对）的就算是菜单和导航条的配置了，当然这里面吸收了eclipse,netbean等思想。做成这样的形式以后也许可以向vb的菜单编辑器一样图形化创建菜单栏吧。

所有菜单栏和工具栏的配置都在commands-context.xml这个文件里面

1

 &lt;bean id="windowCommandManager"  
  class="org.springframework.richclient.application.support.ApplicationWindowCommandManager"&gt;  
  &lt;property name="sharedCommandIds"&gt;  
   &lt;list&gt;  
    &lt;value&gt;saveAsCommand&lt;/value&gt;  
    &lt;value&gt;propertiesCommand&lt;/value&gt;  
    &lt;value&gt;renameCommand&lt;/value&gt;                 
    &lt;value&gt;undoCommand&lt;/value&gt;  
    &lt;value&gt;redoCommand&lt;/value&gt;  
    &lt;value&gt;cutCommand&lt;/value&gt;  
    &lt;value&gt;copyCommand&lt;/value&gt;  
    &lt;value&gt;pasteCommand&lt;/value&gt;  
    &lt;value&gt;selectAllCommand&lt;/value&gt;  
    &lt;value&gt;deleteCommand&lt;/value&gt;  
   &lt;/list&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;

统一定义所有的command，便于事件的分布传递

2

 &lt;bean id="menuBar"  
  class="org.springframework.richclient.command.CommandGroupFactoryBean"&gt;  
  &lt;property name="members"&gt;  
   &lt;list&gt;  
    &lt;ref bean="fileMenu"/&gt;  
    &lt;ref bean="editMenu"/&gt;  
    &lt;ref bean="windowMenu"/&gt;  
    &lt;ref bean="helpMenu"/&gt;  
   &lt;/list&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;

定义菜单，菜单分四个组，也就是我们一般菜单里面的 文件，编辑 窗口 帮助

3 以其中的一个文件为例

 &lt;bean id="fileMenu"  //文件菜单  
  class="org.springframework.richclient.command.CommandGroupFactoryBean"&gt;  
  &lt;property name="members"&gt;  
   &lt;list&gt;  
    &lt;ref bean="newMenu"/&gt; //新建按钮  
    &lt;value&gt;separator&lt;/value&gt;//分割条  
    &lt;ref bean="loginCommand"/&gt;//登陆  
    &lt;ref bean="logoutCommand"/&gt;//登出  
    &lt;value&gt;separator&lt;/value&gt;//分隔条  
    &lt;value&gt;saveAsCommand&lt;/value&gt;//另存为  
    &lt;value&gt;separator&lt;/value&gt;//分隔条  
    &lt;value&gt;propertiesCommand&lt;/value&gt;//属性  
    &lt;value&gt;separator&lt;/value&gt;//分隔条  
    &lt;bean class="org.springframework.richclient.command.support.ExitCommand"/&gt;//退出  
   &lt;/list&gt;  
  &lt;/property&gt;

 &lt;bean id="newMenu" 上面的新建菜单还有一个子菜单里面是新建主人  
  class="org.springframework.richclient.command.CommandGroupFactoryBean"&gt;  
  &lt;property name="members"&gt;  
   &lt;list&gt;  
    &lt;ref bean="newOwnerCommand"/&gt;  
   &lt;/list&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
 &lt;/bean&gt;

//这里是新建主人具体的命令，作用是调用新建主人向导框

 &lt;bean id="newOwnerCommand"  
  class="org.springframework.richclient.command.TargetableActionCommand"&gt;  
  &lt;property name="commandExecutor"&gt;  
   &lt;ref bean="newOwnerWizard"/&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;

按照这个思路，其他的菜单都是一样的道理

 &lt;bean id="helpContentsCommand"  
  class="org.springframework.richclient.command.support.HelpContentsCommand"/&gt;  
    
 &lt;bean id="aboutCommand"  
  class="org.springframework.richclient.command.support.AboutCommand"&gt;  
  &lt;property name="aboutTextPath"&gt;  
   &lt;value&gt;org/springframework/richclient/samples/petclinic/about.txt&lt;/value&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;

 &lt;bean id="preferenceCommand" class="org.springframework.richclient.preference.PreferenceCommand"&gt;  
  &lt;property name="preferenceManager"&gt;  
   &lt;ref bean="preferenceManager"/&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
    
 &lt;bean id="loginCommand"  
  class="org.springframework.richclient.security.LoginCommand"&gt;  
  &lt;property name="authenticationManager"&gt;  
   &lt;ref bean="authenticationManager"/&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
   
 &lt;bean id="logoutCommand"  
  class="org.springframework.richclient.security.LogoutCommand"/&gt;