在插件中访问StatusLine
1. WorkbenchWindow window = PlatfromUI.getWorkbench().getActiveWorkbenchWindow(); IStatusLineManager status = window.getStatusLineManager();
退出RCP程序
1. PlatformUI.getWorkbench().restart();
重启RCP应用
1. PlatformUI.getWorkbench().restart();
在插件资源库中查找Perspective(其它extend point资源的获得类似)
1. IPerspectiveDescriptor ipd = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(FavoritePerspective.ID);
获得当前RCP应用的shell
1. Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
显示帮助信息
1. PlatformUI.getWorkbench().getHelpSystem().displayHelp();
显示内存
1. PlatformUI.getPreferenceStore().setValue( IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, true);
eclipse平台图片资源共享的获取方法
1. PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TASK));
rcp(插件开发) 获取插件版本信息
1. /**
2. * 获取插件版本
3. * @return
4. */
5. public String getVersion(){
6. return ((BundleHost)getBundle()).getVersion().toString();
7. }
在其他view中获取某个view的引用
1. PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("viewId");
如何使用代码重启RCP程序?
1. PlatformUI.getWorkbench().restart();
获得父Shell的几种方法
IViewPart
1. IShellProvider shellProvider = viewOrEditor.getSite();
PlatformUI:
1. Shell parentShell =
2. .getWorkbench().getActiveWorkbenchWindow().getShell();
Display
1. Shell parentShell = Display.getDefault().getActiveShell();
在实现了
IWorkbenchWindowActionDelegate接口的类中:
1. private IWorkbenchWindow window;
2.
3. public void init(IWorkbenchWindow window) {
4. this.window = window;
5. }
6. public void run(IAction action) {
7. = window.getShell();
8. dialog = new MyDialog(parentShell, );
9. etc
10. }
获取程序启动参数
1. String[] args = Platform.getCommandLineArgs();
关闭一个当前的perspective打开一个新的perspective
1. IWorkbench w=PlatformUI.getWorkbench();
2.
3. .IWorkbenchAction closePerspectiveAction
4. = ActionFactory.CLOSE_PERSPECTIVE.create(w.getActiveWorkbenchWindow());
5. .run();
6.
7. try ...{
8. .getWorkbench().showPerspective("com.ibm.demo.saic.ui.views.NextPerspective",
9. .getActiveWorkbenchWindow());
10. } catch (WorkbenchException e) ...{
11. .printStackTrace();
12. }
定制Console View的ToolBar:
去掉RCP Console View 中的Open Console和Select Console按钮。
1. WorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getPages()[0];
2. = page.findView(IConsoleConstants.ID_CONSOLE_VIEW);
3. = viewpart.getViewSite().getActionBars();
4. = actionBar.getToolBarManager();
5. [] items = toolbarMgr.getItems();
6. for (IContributionItem item : items) {
7. if (item instanceof ActionContributionItem) {
8. action = ((ActionContributionItem) item).getAction();
9. String text = action.getText();
10. if (text.equals("Open Console") || text.equals("Select Console")) {
11. .remove(item);
12. }
13. }
14. }
15. .updateActionBars();
如果不需要toobar中的任何东西,可以直接
1. toolbarMgr.removeAll();
可以看到现在的rcp上有很多menubar,这些是我们所不需要的,可以通过在代码中添加下列代码来简化menubar
1. IWorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0]
2. .getPages()[0];
3. = page.findView(IConsoleConstants.ID_CONSOLE_VIEW);
4. // IActionBars actionBar = viewpart.getViewSite().getActionBars();
5. = viewpart.getViewSite().getActionBars()
6. .getToolBarManager();
7. // IToolBarManager toolbarMgr = actionBar.getToolBarManager();
8. [] items = toolbarMgr.getItems();
9. for (IContributionItem item : items) {
10. if (item instanceof ActionContributionItem) {
11. action = ((ActionContributionItem) item).getAction();
12. String text = action.getText();
13. if (text.equals("Open Console")
14. || text.equals("Select Console")) {
15. .remove(item);
16. }
17. }
18. }
19. .getViewSite().getActionBars().updateActionBars();
http://blog.chinaunix.net/uid/200142/cid-16521-list-1.html