您的位置:首页 > 移动开发

《Eclipse.Rich.Client.Platform》4章 The Hyperbola Application

2016-06-05 17:40 501 查看
chapter 4 The Hyperbola Application  

本章主要讲解应用eclipse生成 rich client的模板代码

4.1 Hyperbola “Hello,world”

       File> New >Project   Choose Plug-in Project clickNext ,enter project name "org.eclipsercp.hyperbola" ,clickNext

        You will see the page of "New Plug-in Project"  这个页面默认设置其实就可以,有两个注意项

          1.Make sure to uncheck the Generate an activator,a
Java class that controls the plug-in's life cycle
option;这个选项在以后会用到

          2.Select the Yes radio button in the Rich Client Applicationarea 这个选项意思是建立一个富客户端,而不仅仅是个plug-in插件

      Click Next and the wizard moves to the RCP Templates Page  这部分书里让选择 hello RCP 但是在我滴版本里没有,所以我选择 RCP 3.x application(minimal)因为这个选项里面用到滴扩展点与书中相同。org.eclipse.core.runtime.applications和org.eclipse.ui.perspectives

        排在第一位滴是RCP滴第4版,稍后再研究一下???

      Click Next 进入到下一个页面,将第一项 Application window title 改一下,注意Add branding复选框一定要
uncheck.

      click Finish.  进入到 Plug-in Development perspective视图

      到此处代码已经都生成完毕了。所以接下来就是逐项进行一下介绍:

      1.plugin.xml MANIFEST.MF bulid.properties 三个文件公用了一个plug-in editor。这个editor编辑器很厉害,有很多不同选项卡,在一个地方就可以进行很多操作啦!赞

      2.Overview选项卡 Testing区域:Launch an Eclipse Application 运行这个插件工程

                                                                 Launch an Eclipse Application in debug mode 以debug模式运行

      3.Dependencies选项卡 里面介绍了我所开发插件所依赖滴插件 org.eclipse.core.runtime 和org.eclipse.ui

         The Dependencies page also has some useful Dependency Analysis tools to help you navigate the dependencise between plug-ins,find unused dependencies,look for cycles,and other tasks。

        在Dependency Analysis 区域选择Show the plug-in dependency hierarchy 这段读中文没明白,英文内容如下:

        Notice that some of the plug-ins under the Runtime and UI,for example,org.eclipse.swt.,have little arrow decorations beside them。

        The arrows identify plug-ins are reexported by their parents in the tree ---org.eclipse.ui in the case of the SWT plug-in.

        大致意思就是箭头means它滴父类滴同时引用他子类

    4.Extensions选项卡 介绍了两个扩展点 以及模板代码与扩展点链接滴类

       org.eclipse.hyperbolat.Application links to org.eclipse.core.runtime.applications  

       org.eclipsercp.hyperbola.Perspective links to org.eclipse.ui.perspectives 

4.2 Tour the code 浏览代码

      4.2.1 Application

         org.eclipse.equinox.app.IApplication;

          public class Application implements IApplication{

              必须继承类IApplication并实现里面滴start和stop方法。书中说是run()方法,也许变化了。

             int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());

           }

      4.2.2 WorkbenchAdvisor

           ApplicationWorkbenchAdvisor 类在4.2.1中被实例化 然后传到了PlatformUI.createAndRunWorkbench()方法里,此处很重要

         import org.eclipse.ui.application.WorkbenchAdvisor;

         public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor{

                方法createWorkbenchWindowAdvisor

         }

       WorkbenchAdvisor确定两件事情:

       1.The initial perspective to be shown:工作区初始化

        2.the workbenchWindowAdvisor to be used  :使用ApplicationWorkbenchWindowAdvisor

     4.2.3 Perspective 透视图

       import org.eclipse.ui.IPerspectiveFactory;

        public class Perspective implements IPerspectiveFactory{

                  这个类是从org.eclipse.ui.perspectives扩展点扩展出来滴,但是却 实现滴IPerspectiveFactory

        }

      4.2.4 WorkbenchWindowAdvisor 

       import org.eclipse.ui.application.WorkbenchWindowAdvisor;

        public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor{

               preWindowOpen() 方法很重要,窗口滴初始化工作

       }

      4.2.5 ActionBarAdvisor

           import org.eclipse.ui.application.ActionBarAdvisor;

           public class ApplicationActionBarAdvisor extends ActionBarAdvisor{

               这个类滴作用主要是定义窗口动作。

            } 

     4.2.6 summary

       注意这几个类之间滴关系

       扩展点 Application -->start 方法里new ApplicationWorkbenchAdvisor() 

                                         -->createWorkbenchWindowAdvisor()方法里new
ApplicationWorkbenchWindowAdvisor(configurer)

                                        -->createActionBarAdvisor()方法里new
ApplicationActionBarAdvisor
(configurer)

      扩展点 Perspective

4.3 Running and debug

      4.3.1 Debuging

        在plug-in editor里滴Testing 区域 有Launch an Eclipse Application in debug mode 以debug模式运行

        修改代码ApplicationWorkbenchWindowAdvisor类里滴preWindowOpen()方法

         IWorkbenchWindowConfigurer configurer = getWindowConfigurer();

         configurer=null;

        运行报空指针错误NullPointException

        Run-->Add Class Load Breakout 添加异常断点,输入NullPointException
 然后再debug项目,会在空指针代码处停住

     4.3.2 Launch Configurations 启动配置

         Run--> Run Configurations  main选项卡 里面粗略滴介绍了一下相关运行配置,后面章节会详细介绍
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: