4、定義WorkbenchAdvisor類 和Application類
(1)創(chuàng)建WorkbenchAdvisor類
l 構(gòu)建 RCP 應(yīng)用程序的核心任務(wù)之一就是創(chuàng)建一個實現(xiàn)抽象類 org.eclipse.ui.application.WorkbenchAdvisor 的類
l WorkbenchAdvisor 類負(fù)責(zé)配置,在執(zhí)行 RCP 應(yīng)用程序時顯示的工作臺
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()方法中,向新的工作臺窗口返回初始透視圖的標(biāo)識符
l 增加preWindowOpen()方法,設(shè)置工作臺的窗口標(biāo)題和尺寸
(2)創(chuàng)建Application類
l 在執(zhí)行應(yīng)用程序之前,需要創(chuàng)建一個 Application 類,這與 Java 類中的main方法類似, 是RCP應(yīng)用程序的入口點
l 該類需要實現(xiàn)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()方法對大多數(shù)RCP 應(yīng)用程序而言,不需要定制,重新使用就可
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)運行應(yīng)用程序
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按鈕,自動包含執(zhí)行應(yīng)用程序必需的插件
l 點擊Apply按鈕
l 點擊Run按鈕來執(zhí)行該應(yīng)用程序
l 如果正確進行了所有配置的話,應(yīng)該顯示一個標(biāo)題為“Google”的窗口,這是一個普通工作臺框架
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=79401