Eclipse编辑器插件:“ERROR”打开文件外面的项目 [英] Eclipse editor plugin: "ERROR" when opening file outside project

查看:203
本文介绍了Eclipse编辑器插件:“ERROR”打开文件外面的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Eclipse的编辑器插件。它在eclipse项目中的文件工作正常,但是当通过文件 - >打开文件菜单(与Java文件进行文件工作)打开外部文件时,我将看到一个不显示水平蓝线的页面,字错误。 eclipse的错误日志为空,而.metadata目录中的日志文件也为空。



可能会导致什么?当我没有错误信息告诉我在哪里看时,如何诊断错误?似乎没有办法从eclipse获取更详细的记录。



编辑:



我发现问题的根源是接近jamesh提到的,但不是ClassCastException - 对于文本根本就没有 IDocument 实例查看器显示,因为 StorageDocumentProvider.createDocument()返回null。原因是它只知道如何为 org.eclipse.ui.IStorageEditorInput 的实例创建文档,但在这种情况下,它会获得一个 org.eclipse.ui.ide.FileStoreEditorInput ,它不实现该接口,而是实现 org.eclipse.ui.IURIEditorInput / p>

解决方案

我有同样的问题,终于找到解决方案为我工作。
您必须提供2个不同的文档提供程序 - 首先为工作台中的文件扩展 FileDocumentProvider ,然后再将 TextFileDocumentProvider 扩展为工作区外的其他资源。然后,您在编辑器 doSetInput 方法中注册正确的提供者,如下所示:

  private IDocumentProvider createDocumentProvider(IEditorInput input){
if(input instanceof IFileEditorInput){
return new XMLTextDocumentProvider();
} else if(input instanceof IStorageEditorInput){
return new XMLFileDocumentProvider();
} else {
return new XMLTextDocumentProvider();
}
}

@Override
protected final void doSetInput(IEditorInput input)throws CoreException {
setDocumentProvider(createDocumentProvider(input));
super.doSetInput(input);
}

然后在您的新文档提供程序(扩展TextFileDocumentProvider)中插入somethnig,如下所示: / p>

  protected FileInfo createFileInfo(Object element)throws CoreException {
FileInfo info = super.createFileInfo(element);
if(info == null){
info = createEmptyFileInfo();
}
IDocument document = info.fTextFileBuffer.getDocument();
if(document!= null){

/ *在这里注册您的分区器和其他东西
与您的fisrt文档提供程序相同* /
}
返回信息;
}

这适用于我:)最后我必须提到,不是很聪明,我从项目Amateras(Opensource HTML编辑器插件为eclipse)复制了这个解决方案。


I'm developing an editor plugin for eclipse. It works fine on files within eclipse projects, but when an external file is opened via the "File -> Open File" menu (which works file with, e.g. Java files), I get a page displaying nothing but a horizontal blue line and the word "ERROR". The Error Log of eclipse is empty, as is the log file in the .metadata directory.

What could cause this? How can I diagnose the error when I have no error message that tells me where to look? There doesn't seem to be a way to get more detailed logging from eclipse.

Edit:

I've found that the source of the problem is close to what jamesh mentioned, but not a ClassCastException - there simply is no IDocument instance for the text viewer to display because StorageDocumentProvider.createDocument() returns null. The reason for this is that it only knows how to create documents for instances of org.eclipse.ui.IStorageEditorInput, but in this case it gets an instance of org.eclipse.ui.ide.FileStoreEditorInput, which does not implement that interface, but instead implements org.eclipse.ui.IURIEditorInput

解决方案

I had the same probleam and finally found solution working for me. You have to provide 2 different document providers - first extending FileDocumentProvider for files inside your workbench, and second extending TextFileDocumentProvider for other resources outside your workspace. Then you register the right provider acording to the input in your editors doSetInput method like this:

private IDocumentProvider createDocumentProvider(IEditorInput input) {
    if(input instanceof IFileEditorInput){
        return new XMLTextDocumentProvider();
    } else if(input instanceof IStorageEditorInput){
        return new XMLFileDocumentProvider();
    } else {
        return new XMLTextDocumentProvider();
    }
}

@Override
protected final void doSetInput(IEditorInput input) throws CoreException {
    setDocumentProvider(createDocumentProvider(input));
    super.doSetInput(input);
}

then in your new document provider (extending TextFileDocumentProvider) insert somethnig like this:

protected FileInfo createFileInfo(Object element) throws CoreException {
        FileInfo info = super.createFileInfo(element);
        if(info==null){
            info = createEmptyFileInfo();
        }
        IDocument document = info.fTextFileBuffer.getDocument();
        if (document != null) {

            /* register your partitioner and other things here 
                       same way as in your fisrt document provider */
        }
        return info;
    }

This works for me :) Finally I have to mention, that I'm not so clever and that I copied this solution from project Amateras (Opensource HTML editor plugin for eclipse)

这篇关于Eclipse编辑器插件:“ERROR”打开文件外面的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆