Eclipse:从插件中以编程方式选择XSD中的文本

Eclipse:从插件中以编程方式选择XSD中的文本,eclipse,xsd,eclipse-plugin,Eclipse,Xsd,Eclipse Plugin,我目前正在编写一个Eclipse插件。在其中,我希望以编程方式打开一个编辑器并选择文本的一部分。打开的文件不必导入工作区(这就是为什么我在下面的代码中使用IFileStore) 我使用的代码与此类似: IFileStore fileStore = EFS.getLocalFileSystem().getStore(localPath); IEditorPart part = IDE.openEditorOnFileStore(page, fileStore); final int posStar

我目前正在编写一个Eclipse插件。在其中,我希望以编程方式打开一个编辑器并选择文本的一部分。打开的文件不必导入工作区(这就是为什么我在下面的代码中使用IFileStore)

我使用的代码与此类似:

IFileStore fileStore = EFS.getLocalFileSystem().getStore(localPath);
IEditorPart part = IDE.openEditorOnFileStore(page, fileStore);
final int posStart = ...;
final int posEnd = ...;
part.getEditorSite().getSelectionProvider().setSelection(
                    new TextSelection(posStart, posEnd - posStart));
对于Java文件,它可以正常工作,但对于XMLSchema(XSD),则不行。编辑器将打开,但未选择任何文本

通过调试,我可以看出该部分的类型是org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor,选择管理器是org.eclipse.wst.xsd.ui.internal.adt.editor.CommonSelectionManager

我的目标是月食火星和霓虹灯,它似乎不适用于两者


我能做些什么使它工作?或者至少找到一些进一步的信息?

在查看了WTP代码之后,目前似乎不支持这一点。但我通过显式检查编辑器是否为多部分编辑器找到了一个解决方法:

private static void setSelection(IEditorPart part, TextSelection textSelection) {
    if (part instanceof MultiPageEditorPart) {
        final MultiPageEditorPart multiPage = (MultiPageEditorPart) part;
        for (final IEditorPart subPart : multiPage.findEditors(multiPage.getEditorInput())) {
            setSelection(subPart, textSelection);
        }
    } else {
        part.getEditorSite().getSelectionProvider().setSelection(textSelection);
    }
}

我不确定是将选择发送到所有子部分还是只发送到一个特定部分更好,但到目前为止,将其发送到所有部分似乎都有效。

您必须阅读编辑器的源代码才能了解它支持什么。感谢您的回复。你知道我在哪里可以找到这些类的源存储库吗?我找到了一个带有源JAR的下载,但没有找到git repo。从我到目前为止看到的情况来看,它似乎目前不受支持,但我想进一步研究一下。我认为这是EclipseWTP(Web工具项目)的一部分。将列出的git位置