【问题标题】:Is the source validator (org.eclipse.wst.sse.ui.sourcevalidation) related with the editor or just with the content-type?源验证器 (org.eclipse.wst.sse.ui.sourcevalidation) 是与编辑器相关还是仅与内容类型相关?
【发布时间】:2021-09-05 12:53:54
【问题描述】:

目前我有源验证器(org.eclipse.wst.sse.ui.sourcevalidation)来检查html源:

<extension point="org.eclipse.wst.sse.ui.sourcevalidation">
    <validator
        scope="total"
        class="com.test.HtmlValidator"
        id="com.test.HtmlValidator.total">
        <contentTypeIdentifier
            id="org.eclipse.wst.html.core.htmlsource">
            <partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
            <partitionType id="org.eclipse.wst.html.HTML_DECLARATION"/>
            <partitionType id="org.eclipse.wst.html.HTML_COMMENT"/>
        </contentTypeIdentifier>
    </validator>

源验证器在默认的 html 编辑器 (org.eclipse.wst.html.core.htmlsource.source) 中按预期工作,但如果我使用 Eclipse 通用编辑器 (org.eclipse.ui.genericeditor. GenericEditor,Eclipse Wild Web Developer 用它来打开所有的 Web 开发文件)源代码验证器不起作用。

在我知道源验证器直接与内容类型而不是与编辑器一起工作之前,我的问题是我应该怎么做才能使验证器与两个编辑器一起工作?

【问题讨论】:

  • This tutorial 似乎是说它仅在基于 Eclipse WTP 结构化源代码编辑器的编辑器中可用
  • 我找到了使用 org.eclipse.wst.validation.validatorV2 将验证器添加到 org.eclipse.ui.genericeditor.GenericEditor 的方法,但唯一的问题是验证器V2 只能手动触发, @greg-449 你知道配置validatorV2 来检测sse.ui.sourcevalidation 等文件更改的方法是什么吗?

标签: java eclipse eclipse-rcp


【解决方案1】:

为了解决这个问题,我找到了一个解决方法,使用 org.eclipse.core.filebuffers.documentSetup 扩展点,这个扩展点执行方法 IDocumentSetupParticipant.setup(IDocument document),这个扩展点的好处是它是独立于编辑器。 org.eclipse.core.filebuffers.documentSetup 在使用任何编辑器打开具有特定内容类型的文件时执行。

<extension
       point="org.eclipse.core.filebuffers.documentSetup">
   <participant
      class="setup.HTMLDocumentSetup"
      contentTypeId="org.eclipse.wst.html.core.htmlsource">
    </participant>
 </extension>

在IDocumentSetupParticipant.setup中我们可以注册一个IDocumentListener,这个接口定义了2个方法:

  1. documentAboutToBeChanged
  2. 文档已更改

如果我们使用 documentChanged,每次用户在编辑器中键入内容时,该方法都会执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多