RCP:打开一个Editor的新窗口的实现代码
2010-07-18 22:35
288 查看
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时要先确认参数不为空.否则运行时会抛出错误.
分享到:
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时要先确认参数不为空.否则运行时会抛出错误.
分享到:
相关文章推荐
- RCP:打开一个Editor的新窗口的实现代码
- WinForm实现只打开一个窗口的代码
- 如何打开一个新窗口--代码小集合(是转的别人的回复内容)
- Javascript 用本页面文本域中的HTML代码打开一个空白窗口来运行
- C# 在主窗口中打开一个带有计算器功能的子窗口,有三种实现方法
- 【代码】用div+css实现 在新窗口中打开指定的DIV标签下链接
- 在RCP中实现用托拽打开Editor
- Java:在RCP中实现用托拽打开Editor
- 一个实现了ViewPart和EditorPart的简单RCP例子
- 在RCP中实现用托拽打开Editor
- jquery 打开窗口返回值实现代码
- jquery 打开窗口返回值实现代码
- 【原创】在winform程序中实现在IE浏览器中打开一个新的页面,全屏化并屏蔽IE窗口的工具栏和地址栏
- 代码实现给Wordpress站外链接自动nofollow和新窗口打开
- Xcode里通过代码实现一个窗口程序
- 一个vc的watch窗口的实现代码
- JavaScript实现打开窗口最大化代码
- flex中只打开一个窗口(用单例实现)
- Window.open 实现导航与打开窗口,导航到一个特定链接地址,也可以打开一个新的浏览器窗体
- 在cs代码中实现新窗口(_blank)中打开