【问题标题】:Eclipse RCP - Path must include project and resource nameEclipse RCP - 路径必须包含项目和资源名称
【发布时间】:2013-12-09 05:58:45
【问题描述】:

我正在使用 Eclipse RCP 并创建编辑器,我需要以下代码:

  new Path("c:/myfile.txt")

我遇到了以下问题:

 Path must include project and resource name

我不知道项目或资源名称是什么(我不关心它们 - 我想打开那个文件)。我很惊讶如此简单的事情(以及许多其他事情)在 Eclipse RCP 中如此复杂。

【问题讨论】:

  • 您如何使用Path?听起来您可能正在使用需要工作区中的资源的 Eclipse API。
  • 我有一个动作,我正在尝试创建编辑器(在 Swing 的几分钟问题中,在 Eclipse RCP 中它似乎非常复杂):PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file. getName());
  • 什么是EclipseUtils
  • 它包含以下静态函数: public static IFileEditorInput getFileEditorInput(IPath path){ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile 文件 = root.getFile(path);如果(文件==空)返回空; IFileEditorInput fileEditorInput = new FileEditorInput(file);返回文件编辑器输入; }

标签: eclipse rcp


【解决方案1】:

代码

IFile file = root.getFile(path);

要求指定的路径在 Eclipse 工作区中,这就是您收到此错误的原因,因为所有工作区文件都在一个项目中。

如果您希望编辑器访问不在工作区中的文件,您将必须使用实现 IURIEditorInput 的编辑器输入 - 可能是 FileStoreEditorInput

IFileStore fileStore = EFS.getStore(file.toURI());
IURIEditorInput input = new FileStoreEditorInput(fileStore);

有些编辑可能不理解这种类型的输入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2017-12-06
    • 1970-01-01
    相关资源
    最近更新 更多