【问题标题】:Is it possible to load an external file/class in a programmatic into the eclipse editor that is located outside the work space?是否可以将程序中的外部文件/类加载到位于工作空间之外的 Eclipse 编辑器中?
【发布时间】:2020-03-31 13:03:06
【问题描述】:

我正在尝试将一个外部类加载到不在本地工作空间内的 Eclipse 编辑器中。 我应该澄清一下,我正在尝试在我正在创建的 Eclipse 插件中执行此操作。

这需要如何为我工作:

  1. 我在创建的视图上有一个双击事件。

  2. 在双击时,我从 SQL 中获取了一个返回绝对路径的数据库字段。 (例如C:\objects\sourceCode\class.java

  3. 从数据库接收到绝对路径后,我需要在 Eclipse 编辑器实例中打开文件。

注意:我确实尝试读取我尝试打开的类的所有行,并在 Eclipse 工作区目录中创建一个临时文件并打开它。但是,我似乎无法让这个工作。


因此我的问题是:

有谁知道这是否可能?如果是的话,你能否给我指出一篇关于做类似事情的文章,或者提供一个可以帮助我努力的例子的位置?

【问题讨论】:

    标签: java eclipse plugins


    【解决方案1】:

    首先请注意,并非所有 Eclipse 编辑器都支持外部文件(例如类文件编辑器)。

    如果编辑器确实支持外部文件,则通过支持 IURIEditorInput 作为编辑器输入来实现。

    FileStoreEditorInputIURIEditorInput的标准实现,这样使用:

    File file = .... the file to open
    
    IFileStore fileStore = EFS.getStore(file.getURI());
    
    IEditorInput editorInput = new FileStoreEditorInput(fileStore);
    
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    
    page.openEditor(editorInput, "id of editor to open");
    

    作为编辑器输入和page.openEditor 的替代方法,您可以使用IDE.openInternalEditorOnFileStore 方法来尝试计算要打开的编辑器的ID:

    IDE.openInternalEditorOnFileStore(page, fileStore);
    

    IDEorg.eclipse.ui.ide 插件中是org.eclipse.ui.ide.IDEEFSorg.eclipse.core.filesystem 插件中是org.eclipse.core.filesystem.EFS

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 2012-03-18
      • 2012-11-08
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      相关资源
      最近更新 更多