TabbedProperties实现

前文中 http://winseclone.iteye.com/blog/1774307 介绍了使用Properties的方法。但是TableTree 形式的Properties视图,局限性比较大,不能很好的发挥。如下操作在Properties就很难实现:

  • 调整属性, 重要常用的属性放置在前!
  • 在属性上添加其他操作,如在Class对象上通过ctrl+<单击>能跳转到对应的class类,并用编辑器打开。

Tabbed Properties效果

Tabbed Properties与表格式Properties不同,采用的是通过表单形式来编辑属性。如下图所示:

 

图中主要分3部分:

1、最外面层是Contributor,由Label + TabContainer;

2、中间层是TabContainer,可以包括n个Tab,每个Tab则是一个SectionContainer;

3、内层是SectionContainer, 由n个Section组成。

 

每个层可以使用一个扩展点来实现。对应Tabbed提供的3个扩展点:

  • org.eclipse.ui.views.properties.tabbed.propertyContributor
  • org.eclipse.ui.views.properties.tabbed.propertyTabs
  • org.eclipse.ui.views.properties.tabbed.propertySections

 

 这里,我们先按照步骤一步步的实现效果,然后再讲解3个扩展点常用的属性。

实现Tabbed Properties View

· 更新SampleView.java

1、实现ITabbedPropertySheetPageContributor接口

	public String getContributorId() {
		return SampleView.ID;
	}

2 重写SampleView的getAdapter方法。修改默认的IPropertySheetPage.class适配对象

	public Object getAdapter(Class adapter) {
		if (adapter == IPropertySheetPage.class) {
			return new TabbedPropertySheetPage(this);
		}

		return super.getAdapter(adapter);
	}

· 实现ISection,定义控件以及布局

实现自定义的IFilter和Section

StringFilter 

· 扩展点实现

添加tabbed的3个扩展点。

contributorId填写为对应SampleView的Id(即SampleView.ID的值)。具体Contributor,Tab,Section的属性配置按照层次关系填写即可。


 

   <extension
         point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
      <propertyContributor
            contributorId="plugin.properties.views.SampleView"
            labelProvider="org.eclipse.jface.viewers.LabelProvider">
         <propertyCategory
               category="Sample"></propertyCategory>
         <propertyCategory
               category="AdvancedCategory"></propertyCategory>
      </propertyContributor>
   </extension>
   <extension
         point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
      <propertyTabs
            contributorId="plugin.properties.views.SampleView">
         <propertyTab
               category="AdvancedCategory"
               id="plugin.properties.advancedTab"
               label="Advanced">
         </propertyTab>
         <propertyTab
               category="Sample"
               id="plugin.properties.sampleTab"
               label="Sample">
         </propertyTab>
      </propertyTabs>
   </extension>
   <extension
         point="org.eclipse.ui.views.properties.tabbed.propertySections">
      <propertySections
            contributorId="plugin.properties.views.SampleView">
         <propertySection
               class="org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection"
               id="plugin.properties.advanceSection"
               tab="plugin.properties.advancedTab">
            <input
                  type="plugin.properties.views.StringWrapper">
            </input>
         </propertySection>
         <propertySection
               class="plugin.properties.section.StringTypeSection"
               filter="plugin.properties.section.StringFilter"
               id="plugin.properties.sampleSection"
               tab="plugin.properties.sampleTab">
         </propertySection>
      </propertySections>
   </extension>

 

另外,编写Tabbed Properties页签视图需要懂swt,以及FormLayout布局。

对于一个属性显示一行的TabbedProperties可以通过topcased插件来生成。这个插件还是不错的。但是如果复杂一点的就需要自己定义了。


扩展点含义

下面主要讲一下3个扩展点的常用属性,及其子节点

1、 org.eclipse.ui.views.properties.tabbed.propertyContributor

#propertyContributor节点的属性

  • contributorId Tabbed PropertySheetPage贡献者的ID,即选中元素所在View或Editor的ID。 同时View和Editor也需要实现ITabbedPropertySheetPageContributor 接口,这个接口只有一个方法,要求返回的值即该contributorId。
  • typeMapper - 实现类型的映射。TabbedPropertyRegistryClassSectionFilter.appliesToSelection(ISectionDescriptor, ISelection) 起到mappingFilter的作用。因为我们选择的元素并不一定是实现IPropertySource的元素(即能够给property view提供内容的元素),比如在GEF中,我们选择的finger实际上是选择了对应的EditPart,而实际上实现了IPropertySource一般的是model部分的元素,所以这时候我们要将Editpart映射到对应的model元素[r3]
  • labelProvider - 标题显示提供者Provider(ILabelProvider)
  • actionProvider - 没啥用。TabbedPropertySheetPage.validateRegistry(ISelection)中会调用registry.getActionProvider(),但在中间就返回了。
  • sectionDescriptorProvider - (应该是类似于propertySections扩展点的作用)
  • tabDescriptorProvider - (应该是类似于propertyTabs扩展点的作用)

 

通过Extensions标签页扩展点的“Show extension point description”查看该扩展点的详细描述。

 

    #propertyContributor#propertyCategory属性

用于聚合多个tabs,将会在propertyTab标签中用到;

注意至少要定义一个category,来聚合tabs,否则,可能会显示property失败。

2、org.eclipse.ui.views.properties.tabbed.propertyTabs

#propertyTabs#propertyTab节点的属性

  • label - Tab显示的名称.
  • category - 对应上面的propertyCategory属性的category的值.
  • id - The unique id for the tab,将会用于propertySection标签。

3、org.eclipse.ui.views.properties.tabbed.propertySections

#propertySections#propertySection属性

  • tab - 该section需要放置到Tab,对应propertyTab扩展点的id属性值.
  • id - 表示该section的唯一ID.
  • class - section的实现类,用于描述这个section的控件和布局。
  • filter - 对象过滤,只有通过该filter的对象才会显示该section

如果没有选择fitler,则需要添加input子节点


源码:

s1: 本文实现的例子

https://github.com/winse/hello/tree/8c8ae8a1a83c7cfe27287631e5b575d50f17d75c

s2: topcased相关源码

http://subversion.moskitt.org/gvcase-adaptations/topcased/branches/org.topcased.modeler/src/org/topcased/modeler/editor/properties/filters/DiagramElementFilter.java

 

http://gforge.enseeiht.fr/scm/viewvc.php/plugins/modeler/org.topcased.tabbedproperties/src/org/topcased/tabbedproperties/sections/?diff_format=s&root=topcased-mf

 

http://gforge.enseeiht.fr/scm/viewvc.php/*checkout*/plugins/modeler/org.topcased.modeler/plugin.xml?revision=1.127&root=topcased-mf

 

参考:

r1:最权威的tabbed_properties的使用说明

http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html

r2:一个通用的页签式视图框架(可以了解一下,使用的不是Eclipse提供的扩展点)

http://www.ibm.com/developerworks/cn/opensource/os-cn-eclipse-tabview/index.html

r3:Eclipse Tabbed Properties View

http://hi.baidu.com/uvfluhpkkjfglor/item/5526fd459565ec14886d1071

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值