打开Eclipse插件编辑器

时间:2012-04-05 08:16:55

标签: java eclipse eclipse-plugin

我有一个扩展TextEditor的类,用于创建编辑器视图。我已经完成了所有必需的条目,例如plugin.xml。现在我在打开编辑器时收到以下错误...

  

org.eclipse.core.runtime.AssertionFailedException:null参数:编辑器输入必须具有非空名称

我使用以下代码打开编辑器。

IWorkbenchPage page =
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(input, xyz.ID);

1 个答案:

答案 0 :(得分:-1)

以下代码是解决问题的正确方法。

if (fileToOpen.exists() && fileToOpen.isFile()) {
    Stirng path = // file path that to be input.;
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    URI fromString = org.eclipse.core.runtime.URIUtil.fromString("file://" + path);
    try {
        IEditorPart openEditor = IDE.openEditor(page, fromString, XYZEditor.ID, true);
        IEditorInput editorInput = openEditor.getEditorInput();
        //editorInput.
    } catch ( PartInitException e ) {
        //Put your exception handler here if you wish to
    }
}
相关问题