【Eclipse外掛程式開發】基於WTP開發自訂的JSP編輯器(八)

來源:互聯網
上載者:User

定製StructuredTextEditor自動提示

前面介紹的內容集中在兩點:StructuredTextEditor架構和WTP資料模型,在本節中就可以定製一個我 們最常用的WTP StructuredTextEditor的功能,那就是自動提示。

【WTP StructuredTextEditor提示功能實現分析】

有關Eclipse文字編輯器架構、JFace Text Framework和WTP StructuredTextEditor的簡要知識,參見:

【Eclipse外掛程式開發】基於WTP開發自訂 的JSP編輯器(二):基於WTP StructuredTextEditor建立自己的JSPEditor

【SourceViewer提示策略 配置】

在章節二中,我們說過如果要對一個ISourceViewer進行自動提示策略的定製,在 ISourceViewer對應的SourceViewerConfiguration中配置就可以了。對於WTP JSP StructuredTextEditor 而言,這裡的ISourceViewer就是StructuredTextViewer,這裡的SourceViewerConfiguration就是 StructuredTextViewerConfigurationJSP。那我們來看一下WTP StructuredTextViewerConfigurationJSP 中對自動提示策略的配置:

(以下代碼摘取子StructuredTextViewerConfigurationJSP類中):

protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
IContentAssistProcessor[] processors = null;
//其他代碼省略......
else if ((partitionType == IXMLPartitions.XML_DEFAULT) || (partitionType == IHTMLPartitions.HTML_DEFAULT) || (partitionType == IHTMLPartitions.HTML_COMMENT) || (partitionType == IJSPPartitions.JSP_DEFAULT) || (partitionType == IJSPPartitions.JSP_DIRECTIVE) || (partitionType == IJSPPartitions.JSP_CONTENT_DELIMITER) || (partitionType == IJSPPartitions.JSP_CONTENT_JAVASCRIPT) || (partitionType == IJSPPartitions.JSP_COMMENT)) {
// jsp
processors = new IContentAssistProcessor[]{new JSPContentAssistProcessor()};
}
else if ((partitionType == IXMLPartitions.XML_CDATA) || (partitionType == IJSPPartitions.JSP_CONTENT_JAVA)) {
// jsp java
processors = new IContentAssistProcessor[]{new JSPJavaContentAssistProcessor()};
}
//其他代碼省略......
return processors;
}

以上代碼,我們可以看的出來,IContentAssistProcessor是和具體分區類型(partition type)相關 聯的。想搞懂這個問題,就需要看一下這個具體分區類型(partition type)是怎麼計算出來的。

PS:分區類型是JFace Text Framework中的概念,相關的知識大家有興趣可以進一步去瞭解一下JFace Text Framework。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.