从文件系统以编程方式打开Eclipse Custom Editor文件

时间:2013-03-28 11:58:17

标签: java eclipse eclipse-plugin eclipse-rcp

我正在使用自定义文本编辑器开发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();
    }

由于

1 个答案:

答案 0 :(得分:3)

尝试使用IDE.openEditor(...)

这个Eclipse wiki有关于此的更多信息:

http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F

相关问题