当前位置: > 网站建设 > JSP教程 >

【Eclipse插件开发】基于WTP开发自定义的JSP编辑器(九)

时间:2012-03-18 | 栏目:JSP教程 | 点击:

定制StructuredTextEditor源码即时校验

上一节我们定制了WTP StructuredTextEditor的自动提示功能特征,本节将定制另外一个功能特征即 时源码校验。所谓源码即时校验,就是在用户编辑过程中(并未保存),针对用户编辑的内容改变做即时 校验,并给用户即时反馈相关的错误或者其他类型的提示信息。在本节中,我们将以标签的即时校验为例 ,演示如何定制WTP StructuredTextEditor的源码即时校验。

在定制之前,我们先来看一下WTP StructuredTextEditor已有的源码即时校验功能:

我们看到,我们删除</jsp:text>的瞬间,WTP StructuredTextEditor的即时校验就给出了错误 提示。其实我们在很多其他的编辑器,例如java源码编辑器等,都可以看到类似的即时校验功能。

【JFace Text Framework中相关内容】

说白了,我们的源码编辑对应的控件就是ISourceViewer, 那么这个校验也理所当然应该是ISourceViewer所提供的一个服务。JFace Text Framework中确实针对源 码即时校验提供了相应的机制,我们看一下相应的接口和运行原理。

【相关接口】

1、IReconciler (org.eclipse.jface.text.reconciler.IReconciler),调解者,当文档发生变化时,根据分区类型( 如果这个概念忘记了,翻一下前面的文章)提供相应的调解策略(直接说成是验证策略吧^_^)。 public interface IReconciler {
/**
* Installs the reconciler on the given text viewer. After this method has been
* finished, the reconciler is operational, i.e., it works without requesting
* further client actions until <code>uninstall</code> is called.
*
* @param textViewer the viewer on which the reconciler is installed
*/
void install(ITextViewer textViewer);
/**
* Removes the reconciler from the text viewer it has
* previously been installed on.
*/
void uninstall();
/**
* Returns the reconciling strategy registered with the reconciler
* for the specified content type.
*
* @param contentType the content type for which to determine the reconciling strategy
* @return the reconciling strategy registered for the given content type, or
* <code>null</code> if there is no such strategy
*/
IReconcilingStrategy getReconcilingStrategy(String contentType);
}

您可能感兴趣的文章:

相关文章