【Eclipse插件开发】基于WTP开发自定义的JSP编辑器(四)2011-10-12 blogjava zhuxingStrucutured Document分析视图在上一篇中,我们详细阐述了WTP中最重要的数据模型之一IStructuredDocument(我们就称之为WTP Document吧,和另外一个核心数据模型WTP Model----IStructuredModel对应),本节中我们将自己开发 一个工具来分析IStrucutredDocument。PS:千万别着急,后面的文章会对WTP StructuredTextEditor进行功能特征定制的,在真正定制之前 一定要搞清楚WTP Document(IStructuredDocument)和WTP Model(IStructuredModel),连核心数据 模型都不熟悉,后面谈何定制^_^【WTP提供的Properteis视图扩展】说明:Properteis视图是Eclipse固有的,允许用户通过相应的类型扩展机制来定制Properties视图 中的内容,涉及到的主要知识点包括:1、Eclipse的Adapter机制(IAdaptable、IAdapterFactory、AdapterManager),关于Eclipse中的 类型适配扩展机制,博客中的另外一篇文章做了分析:【Eclipse插件开发】Eclipse中类型扩展机制分析2、Properties视图相关的几个重要接口:org.eclipse.ui.views.properties.IPropertySource.classorg.eclipse.ui.views.properties.PropertySheetPage...3、WTP就是借助于Eclipse类型扩展机制,实现了对应的功能。我们看一下在WTP的 StructuredTextEditor中的getAdapter方法中提供了扩展服务(IWorkbenchPart本身就是声明为 IAdaptable):
1 /*
2 * (non-Javadoc)
3 *
4 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
5 */
6 public Object getAdapter(Class required) {
7 //
8 else if (IPropertySheetPage.class.equals(required) && isEditable()) {
9 if (fPropertySheetPage == null || fPropertySheetPage.getControl() == null || fPropertySheetPage.getControl().isDisposed()) {
10 PropertySheetConfiguration cfg = createPropertySheetConfiguration();
11 if (cfg != null) {
12 ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage();
13 propertySheetPage.setConfiguration(cfg);
14 fPropertySheetPage = propertySheetPage;
15 }
16 }
17 result = fPropertySheetPage;
18 }
19 //.
20 }
ConfigurablePropertySheetPage^_^ (org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage)。WTP的properties视图的主要功能就是,根据用户在编辑器中光标的位置,在Properties视图中展示 对应的标签内容,并支持用户编辑,例如:

当前编辑器中,用户光标位于jsp:directive.page标签内,属性视图就列举了对应的标签内容,允许 用户编辑。