RCP(Rich Client Platform)入门(4)

4定义WorkbenchAdvisor类 和Application

1)创建WorkbenchAdvisor

l         构建 RCP 应用程序的核心任务之一就是创建一个实现抽象类 org.eclipse.ui.application.WorkbenchAdvisor 的类

l         WorkbenchAdvisor 类负责配置,在执行 RCP 应用程序时显示的工作台

package com.xqtu.google;
    
    
 
    
    
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
    
    
import org.eclipse.ui.application.WorkbenchAdvisor;
    
    
import org.eclipse.swt.graphics.Point;
    
    
 
    
    
public class GoogleWorkbenchAdvisor extends WorkbenchAdvisor {
    
    
 
    
    
    public String getInitialWindowPerspectiveId() {
    
    
 
    
    
        return "com.xqtu.google.GooglePerspective";
    
    
    }
    
    
 
    
    
    public void preWindowOpen(IWorkbenchWindowConfigurer configurer) {
    
    
 
    
    
        super.preWindowOpen(configurer);
    
    
        configurer.setTitle("Google");
    
    
        configurer.setInitialSize(new Point(300, 300));
    
    
        configurer.setShowMenuBar(false);
    
    
        configurer.setShowStatusLine(false);
    
    
        configurer.setShowCoolBar(false);
    
    
    }
    
    
}
    
    

l         getInitialWindowPerspectiveId()方法中,向新的工作台窗口返回初始透视图的标识符

l         增加preWindowOpen()方法,设置工作台的窗口标题和尺寸

2)创建Application

l         在执行应用程序之前,需要创建一个 Application 类,这与 Java 类中的main方法类似, 是RCP应用程序的入口点

l         该类需要实现org.eclipse.core.runtime.IPlatformRunnable接口

package com.xqtu.google;
    
    
 
    
    
import org.eclipse.core.runtime.IPlatformRunnable;
    
    
import org.eclipse.swt.widgets.Display;
    
    
import org.eclipse.ui.PlatformUI;
    
    
import org.eclipse.ui.application.WorkbenchAdvisor;
    
    
 
    
    
public class GoogleApplication implements IPlatformRunnable {
    
    
 
    
    
    public Object run(Object args) throws Exception {
    
    
 
    
    
        WorkbenchAdvisor workbenchAdvisor = new GoogleWorkbenchAdvisor();
    
    
        Display display = PlatformUI.createDisplay();
    
    
        int returnCode = PlatformUI.createAndRunWorkbench(display,
    
    
                      workbenchAdvisor);
    
    
        if (returnCode == PlatformUI.RETURN_RESTART) {
    
    
                return IPlatformRunnable.EXIT_RESTART;
    
    
        } else {
    
    
                return IPlatformRunnable.EXIT_OK;
    
    
        }
    
    
    }
    
    
 
    
    
}
    
    

l         其中的run()方法对大多数RCP 应用程序而言,不需要定制,重新使用就可

l         如前面所示,需要在plugin.xmlorg.eclipse.core.runtime.applications 扩展点指定运行的Application

   <extension
    
    
         id="GoogleApplication"
    
    
         point="org.eclipse.core.runtime.applications">
    
    
      <application>
    
    
         <run class="com.xqtu.google.GoogleApplication"/>
    
    
      </application>
    
    
   </extension>
    
    

3)运行应用程序

l         Run > Run...

l         Configurations列表中选择Run-time Workbench,并点击 New 按钮

l         Name域中键入Google

l         Arguments页中,Run an application下拉框中选择Google.GoogleApplication

l         点击Plug-ins页,选择Choose plug-ins and fragments to launch from the list

l         点击Deselect All按钮

l         选中Workspace Plug-ins选项包含Google项的选择

l         点击Add Required Plug-ins按钮,自动包含执行应用程序必需的插件

l         点击Apply按钮

l         点击Run按钮来执行该应用程序

l         如果正确进行了所有配置的话,应该显示一个标题为“Google”的窗口,这是一个普通工作台框架

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值