嘟嘟

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  26 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

1、 Application:这个类是程序的入口,虽然没有Main函数,但是这个类实现了IPlatformRunnable接口,当JVM完毕,初始化RCP框架以后会调用这个类的run函数来完成UI设置和开始执行我们指定的程序功能。在绝大多数RCP程序中,这个类不用更改。
public class Application implements IPlatformRunnable {

 /* (non-Javadoc)
  * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
  */
 public Object run(Object args) throws Exception {
  Display display = PlatformUI.createDisplay();
  try {
   //将创建用户界面的工作交给了ApplicationWorkbenchAdvisor类
   int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());   
   if (returnCode == PlatformUI.RETURN_RESTART) {
    return IPlatformRunnable.EXIT_RESTART;
   }
   return IPlatformRunnable.EXIT_OK;
  } finally {
   display.dispose();
  }
 }
}

2、 ApplicationWorkbenchAdvisor:这个类是RCP程序的Workbench,RCP是Eclipse的简化,但是所有的组件都是和Eclipse一样的。一个RCP程序也只能有一个Workbench。
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

 private static final String PERSPECTIVE_ID = "RCPDemo.perspective";

    /**
     * 把创建窗口的工作交给了ApplicationWorkbenchWindowAdvisor类
     */
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        return new ApplicationWorkbenchWindowAdvisor(configurer);
    }

    /**
     * 指定默认的透视图
     */
 public String getInitialWindowPerspectiveId() {
  return PERSPECTIVE_ID;
 }
}

3、 ApplicationWorkbenchWindowAdvisor:这个类是RCP的WorkbenchWindow,隶属于当前的Workbench。可以有多个WorkbenchWindow。这个类的功能很强大,我们可以重载它的preWindowCreatepostWindowCreatepreWindowOpenpostWindowOpen等方法,以便修改我们窗口的外观。
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }

    /**
     * 把创建菜单和工具栏的任务交给了ApplicationActionBarAdvisor类
     */
    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }
   
    public void preWindowOpen() {
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
        configurer.setInitialSize(new Point(500, 600));
        configurer.setShowCoolBar(true);
        configurer.setShowStatusLine(false);
        configurer.setTitle("Hello RCP");
    }
}


4、 ApplicationActionBarAdvisor这个类是用来配置程序的菜单栏和工具栏的。
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
    private Action1 action1;
    private Action2 action2;

 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
     super(configurer);
 }

 //初始化所有actions
 protected void makeActions(IWorkbenchWindow window) {
     action1 = new Action1(window);
     action2 = new Action2(window);
 }

 //设置菜单栏
 protected void fillMenuBar(IMenuManager menuBar) {
     //MenuManager实例相当于一个下拉菜单, 参数是text(菜单名)和id(唯一就可以了)
     MenuManager newMenu1 = new MenuManager("menu1", "rcpdemo.menu1");
     //加入菜单项action1
     newMenu1.add(action1);
     //加入一个分隔线
     Separator separator = new Separator();
     newMenu1.add(separator);
     //加入菜单项action2
     newMenu1.add(action2);
  
     //加入第2个下拉菜单,有下拉子菜单
     MenuManager newMenu2 = new MenuManager("menu2", "rcpdemo.menu2");
     //加入菜单项action1
     newMenu2.add(action1);
     //子菜单
     MenuManager newMenu3 = new MenuManager("menu3", "rcpdemo.menu3");
     //加入菜单项action1
     newMenu3.add(action2);
     //子菜单
     newMenu2.add(newMenu3);
  
     //把下拉菜单加到菜单bar中
     menuBar.add(newMenu1);
     menuBar.add(newMenu2);
  
  /**
   * note
   *  一个MenuManager实例就是如果已经被加到menuBar下,同时加到newMenu1下,是显示不出来的
   *  newMenu2.add(newMenu1);
   *  menuBar.add(newMenu1);
   */
 }

 //设置工具栏
 protected void fillCoolBar(ICoolBarManager coolBar) {
     //toolbar1 (group1)
     IToolBarManager toolbar1 = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
     //加入工具项action1
     toolbar1.add(action1);
     //加入一个分隔线
     Separator separator = new Separator();
     toolbar1.add(separator);
     //加入工具项action2
     toolbar1.add(action2);
  
     //toolbar2 (group2)
     IToolBarManager toolbar2 = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
     //加入工具项action1
     toolbar2.add(action1);
  
     //加入到bar中
     coolBar.add(new ToolBarContributionItem(toolbar1, "toolbar1"));
     coolBar.add(new ToolBarContributionItem(toolbar2, "toolbar2"));
 }
}

5、 DemoPlugin:这个类代表了我们的插件,因为RCP程序也是一个插件,Eclipse中所有的插件都必须继承AbstractUIPlugin。这个类为我们提供了很多和插件相关的信息,比如插件的资源,配置等等。
6、 Perspective:是我们新建的RCP的默认透视图。可以在这个类中指定View和Editor的排布。
7、 plugin.xml:这个文件是我们插件的配置文件,包括我们的插件用了哪些其他的插件,具体是怎么配置这些插件的等等。
8、 build.properties:这个文件是用来配置我们插件的编译信息的,用来指定如何编译我们的插件。
9、 MANIFEST.MF:这个文件用来指定我们插件的元数据,比如插件的版本信息。一般来说,这个文件不用手动的去更改。

posted on 2007-06-13 15:44 fyp1210 阅读(912) 评论(0)  编辑  收藏 所属分类: RCP&SWT&JFACE

只有注册用户登录后才能发表评论。


网站导航: