Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
RCP(Rich Client Platform)入门(4)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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




相关文章

相关软件