RCP:打开一个Editor的新窗口的实现代码

IStructuredSelection selection = (IStructuredSelection)event.getSelection(); File file = (File)(selection.getFirstElement()); if (file != null) { IWorkbenchPage page = PlatformUI.getWorkbench(). getActiveWorkbenchWindow().getActivePage(); FileEditorInput input = new FileEditorInput(file); try { showFile = file; page.openEditor(input, MyFileEditor.ID); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } 打开窗口的关键代码为: page.openEditor(input, MyFileEditor.ID); 由此可见打开一个新的Editor需要两个参数,一个是实现了IEditorInput对新建的窗口起描述作用(比如Editor的选项卡窗口的名字,提示语...)的input;另一个是扩展org.eclipse.ui.editors的editor的id,为了使用方便,这个id一般保存在了实现类(本例中MyFileEditor由org.eclipse.ui.editors扩展而来的)的ID成员里. 备忘:运行时出现的一个错误:FileEditorInput input = new FileEditorInput(file);这一句需要特别注意,因为实现IEditorInput接口时不允许传回的参数为空,故在创建input时要先确认参数不为空.否则运行时会抛出错误. 分享到:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值