Chinaunix首页 | 论坛 | 博客
  • 博客访问: 906471
  • 博文数量: 380
  • 博客积分: 3495
  • 博客等级: 中校
  • 技术积分: 3996
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-02 09:35
文章分类

全部博文(380)

文章存档

2015年(2)

2014年(5)

2013年(9)

2012年(9)

2011年(67)

2010年(103)

2009年(182)

2008年(3)

我的朋友

分类: Java

2011-09-03 07:36:39

from:
http://czetsuya-tech.blogspot.com/2009/12/execute-eclipse-rcp-command-and-open.html

Execute an eclipse-rcp command and open an eclipse-rcp view in code
Objective:
1.) To execute an eclipse rcp command in code
2.) To open an eclipse rcp view in command

Most of the time you will just use the extension tab in the plugin.xml but for those who chose to implement in code here's how they're done:

Solution:
1.) By consulting the eclipse-rcp documentation, this is how I done it:
//execute command IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IViewPart view = window.getActivePage().findView("your.view.class.id");
 IHandlerService service = (IHandlerService) view.getSite().getService(IHandlerService.class);
 service.executeCommand("your.application.command.id", null);
Please take note of the findView and executeCommand parameters, which are IDs.

2.) Opening an eclipse-rcp view in code:
//open view IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
//any view in your application
window.getActivePage().showView(you.view.class.id);
 } catch (PartInitException e1) {
// TODO Auto-generated catch block
 e1.printStackTrace();
}
阅读(672) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~