Java 从文件系统以编程方式打开Eclipse自定义编辑器文件

Java 从文件系统以编程方式打开Eclipse自定义编辑器文件,java,eclipse,eclipse-plugin,eclipse-rcp,Java,Eclipse,Eclipse Plugin,Eclipse Rcp,我正在用我的自定义文本编辑器开发一个Eclipse插件 我需要在这个自定义编辑器中以编程方式打开文件。 当我使用Eclipse的DefaultTextEditor打开它时,文件会打开文件,我可以编辑文本,等等 但是,当我尝试使用编辑器打开文件时,编辑器显示为空白,不可编辑。这是我正在使用的源代码 File file = new File(filename); IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStor

我正在用我的自定义文本编辑器开发一个Eclipse插件

我需要在这个自定义编辑器中以编程方式打开文件。 当我使用Eclipse的DefaultTextEditor打开它时,文件会打开文件,我可以编辑文本,等等

但是,当我尝试使用编辑器打开文件时,编辑器显示为空白,不可编辑。这是我正在使用的源代码

    File file = new File(filename);
    IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(file.toURI());
    FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();

    try {
          // this works fine    
          page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEditor");         

          // this is where the issue is
          page.openEditor(editorInput, "MyEditor.editor");          

    } catch (PartInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

谢谢

尝试使用
IDE.openEditor(…)

此Eclipse wiki提供了有关以下内容的更多信息:


您确定您的编辑器可以处理此输入类型吗?试着在编辑器的
init
方法中设置一个断点或记录一些东西,看看它是否到达这里。