嘟嘟

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            26 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

          1、 Application:這個類是程序的入口,雖然沒有Main函數(shù),但是這個類實現(xiàn)了IPlatformRunnable接口,當(dāng)JVM完畢,初始化RCP框架以后會調(diào)用這個類的run函數(shù)來完成UI設(shè)置和開始執(zhí)行我們指定的程序功能。在絕大多數(shù)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 {
             //將創(chuàng)建用戶界面的工作交給了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";

              /**
               * 把創(chuàng)建窗口的工作交給了ApplicationWorkbenchWindowAdvisor類
               */
              public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
                  return new ApplicationWorkbenchWindowAdvisor(configurer);
              }

              /**
               * 指定默認的透視圖
               */
           public String getInitialWindowPerspectiveId() {
            return PERSPECTIVE_ID;
           }
          }

          3、 ApplicationWorkbenchWindowAdvisor:這個類是RCP的WorkbenchWindow,隸屬于當(dāng)前的Workbench??梢杂卸鄠€WorkbenchWindow。這個類的功能很強大,我們可以重載它的preWindowCreate、postWindowCreate、preWindowOpen、postWindowOpen等方法,以便修改我們窗口的外觀。
          public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

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

              /**
               * 把創(chuàng)建菜單和工具欄的任務(wù)交給了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);
           }

           //設(shè)置菜單欄
           protected void fillMenuBar(IMenuManager menuBar) {
               //MenuManager實例相當(dāng)于一個下拉菜單, 參數(shù)是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實例就是如果已經(jīng)被加到menuBar下,同時加到newMenu1下,是顯示不出來的
             *  newMenu2.add(newMenu1);
             *  menuBar.add(newMenu1);
             */
           }

           //設(shè)置工具欄
           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。這個類為我們提供了很多和插件相關(guān)的信息,比如插件的資源,配置等等。
          6、 Perspective:是我們新建的RCP的默認透視圖??梢栽谶@個類中指定View和Editor的排布。
          7、 plugin.xml:這個文件是我們插件的配置文件,包括我們的插件用了哪些其他的插件,具體是怎么配置這些插件的等等。
          8、 build.properties:這個文件是用來配置我們插件的編譯信息的,用來指定如何編譯我們的插件。
          9、 MANIFEST.MF:這個文件用來指定我們插件的元數(shù)據(jù),比如插件的版本信息。一般來說,這個文件不用手動的去更改。

          posted on 2007-06-13 15:44 fyp1210 閱讀(937) 評論(0)  編輯  收藏 所屬分類: RCP&SWT&JFACE
          主站蜘蛛池模板: 宁乡县| 和林格尔县| 大洼县| 宜兰县| 宽城| 吉木乃县| 阜阳市| 博客| 金乡县| 沙河市| 宝应县| 中山市| 马龙县| 沧州市| 郑州市| 大丰市| 安义县| 根河市| 辽宁省| 黑山县| 普洱| 三台县| 阜南县| 恭城| 昌乐县| 呼和浩特市| 金塔县| 常熟市| 白朗县| 新民市| 腾冲县| 双城市| 怀宁县| 万山特区| 苏尼特右旗| 峨眉山市| 碌曲县| 博湖县| 体育| 绥阳县| 垫江县|