定製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);
}