下面是一些rcp(Rich Client Platform) 程序的说明笔记本,记下来免的以后又忘了.关于如何在Eclipse里面建立rcp程序向导,
这儿是一篇不错的翻译教程.
1. Application 作用和一般java程序里面的主类一样,它是一个rcp程序的入口点.必须实现 IPlatformRunnable 接口.即实现run()方法.
在这而run()方法和main()方法作用一样.
2. rcp程序不必全是UI程序,可以是非图形程序.
3. rcp程序几个类: application <= ApplicationWorkbenchAdvisor <== ApplicationWorkbenchWindowAdvisor == Perspective
==ApplicationActionBarAdvisor == xxxPlugin
4.代码示例如下:
org.eclipsercp.hyperbola/Application
public class Application implements IPlatformRunnable {
public Object run(Object args) throws Exception {
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(
display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
return IPlatformRunnable.EXIT_OK;
} finally {
display.dispose();
}
}
}
* Display 在这个类里面生成,PlatformUI类里面全是static方法,主要是生成Workbench和访问Workbench.
* new ApplicationWorkbenchAdvisor() 这个方法引出下面一个类 ApplicationWorkbenchAdvisor(),
5.
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private static final String PERSPECTIVE_ID = "rcphello.perspective";
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
}
说明: return new ApplicationWorkbenchWindowAdvisor(configurer) 生成ApplicationWorkbenchWindowAdvisor.
* 初始化getInitialWindowPerspectiveId() .
6.
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("Hello RCP");
}
}
说明: 生成 new ApplicationActionBarAdvisor(configurer); 另外preWindowOpen() 里面做了好多设置界面的工作.比如是否显示
工具栏,状态栏...,
7.
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}
protected void makeActions(IWorkbenchWindow window) {
}
protected void fillMenuBar(IMenuManager menuBar) {
}
}
说明:
定义程序里面的动作.加到菜单和工具栏.快捷键...上.