RCP(Rich Client Platform)入门(4)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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.xml的org.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”的窗口,这是一个普通工作台框架

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航