源验证器(org.eclipse.wst.sse.ui.sourcevalidation)与编辑器相关还是仅与内容类型相



目前我有源验证器(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.clipse.ui.genericeditor.genericeditor,eclipse Wild Web Developer使用它来打开所有Web开发文件(打开相同的文件,则源验证器不工作。

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

为了解决这个问题,我使用org.eclipse.core.filebuffers.documentSet扩展点找到了一个解决方案,这个扩展点执行方法IDocumentSetupParticipant.setup(IDocumentdocument(,这个扩展点通过独立于编辑器。org.eclipse.core.filebuffers.dococumentSet在使用任何编辑器打开具有特定内容类型的文件时执行。

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

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

  1. 文档AboutToBeChanged
  2. documentChanged

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

相关内容

最新更新