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