如果你有一个Eclipse插件/编辑器或类似这样的尝试:
//get the workspace
IWorkspace workspace= ResourcesPlugin.getWorkspace();
//create the path to the file
IPath location= new Path(yourURL.getPath());
//try to get the IFile (returns null if it could not be found in the workspace)
IFile file= workspace.getRoot().getFileForLocation(location);
if (file == null) {
//not found in the workspace, get the IFileStore (external files)
IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
return fileStore;
} else {
// file found, return it
return file;
}
有益的可能是也:
url = FileLocator.toFileURL(yourURL);
和/或
URL resolvedUrl = FileLocator.resolve(url);
此之后,你可以为您的编辑器创建输入(我认为您想在那里使用它)?
Object file = myGetFile();
IEditorInput input;
if (file instanceof IFile) {
input = new FileEditorInput((IFile)file);
else {
if (file instanceof IFileStore) {
input = new FileStoreEditorInput((IFileStore)file);
} else {
throw new MyException("file is null, not found");
}
}
我希望这会帮助你。
Greetz, Adreamus
嗨,谢谢你的回答。更加详细:我编写的工具的用户可以在编辑器中打开特殊文件。这些文件可以位于工作区,也可以通过以IDE(新功能)开始的捆绑包提供。但是旧的实现需要在编辑器中显示一个IFile。我不知道如何在编辑器中打开由已启动的软件包提供的文件。对我来说最糟糕的情况是重写编辑器期望不是IFile,而是其他东西(比如新模型等)。但我希望我不需要重写这么多;) – mosk 2012-02-09 20:18:51
感谢您的详细信息。编辑器可能假定一个“IFileEditorInput”作为它的输入对象......这是不好的做法,但我想这对你没有多大帮助。你可以试着看看它是否会接受一个'IStorageEditorInput',这对于非文件输入来说更容易实现。 – 2012-02-09 20:31:57
就是这样,你把我带到了正确的道路上。编辑器实际上假设我能够自己实现的IEditorInput。现在它工作正常。谢谢! – mosk 2012-02-10 16:53:57