Eclipse Tabbed Properties View

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

依赖 org.eclipse.ui.views.properties.tabbed 插件

需要实现三个扩展点:

org.eclipse.ui.views.properties.tabbed.PropertyContributor
Tabbed View 由一个 PropertyContributor 构成,其中包含多个 PropertyTab。
<extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
<propertyContributor contributorId="mview.views.SampleView">
<propertyCategory category="sample"/>
</propertyContributor>
</extension>
org.eclipse.ui.views.properties.tabbed.PropertyTabs
每个 PropertyTab 由多个 PropertySection 构成。
<extension point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs contributorId="mview.views.SampleView">
<propertyTab
category="sample"
id="mview.ButtonTab"
label="Button"/>
<propertyTab
afterTab="mview.ButtonTab"
category="sample"
id="mview.AdvancedTab"
label="Advanced"/>
</propertyTabs>
</extension>
org.eclipse.ui.views.properties.tabbed.PropertySections
每个 PropertySection 实现为一个或一组 widget,对应着一个 property。
<extension point="org.eclipse.ui.views.properties.tabbed.propertySections">
<propertySections contributorId="mview.views.SampleView">
<propertySection
class="mview.views.LabelSection"
id="mview.LabelSection"
tab="mview.ButtonTab">
<input type="mview.views.ButtonElement"/>
</propertySection>
<propertySection
afterSection="mview.LabelSection"
class="mview.views.SizeSection"
id="mview.SizeSection"
tab="mview.ButtonTab">
<input type="mview.views.ButtonElement"/>
</propertySection>
<propertySection
afterSection="mview.SizeSection"
class="mview.views.FontSection"
id="mview.FontSection"
tab="mview.ButtonTab">
<input type="mview.views.ButtonElement"/>
</propertySection>
<propertySection
class="org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection"
id="mview.AdvancedSection"
tab="mview.AdvancedTab">
<input type="mview.views.ButtonElement"/>
</propertySection>
</propertySections>
</extension>
Tabbed Property是eclipse3.2中新加入一个view,可以使属性编辑器的功能近乎无限的扩大。这里说明一些Tabbed Property的使
        用方法。Tabbed Property中分成三个部分,Contributer,Tabs,Sections,一个Contributor包含若干个Tabs,一个Tabs又
        可以包含若干个sections。下面我们来分别进行描述。
      1。Contributor 这需要扩展org.eclipse.ui.views.properties.tabbed.PropertyContributor扩展点,定义时,最重
       要的是定义contributId,这个id必须是全局唯一的,这样在加载属性页时,才能找到这个我们定义的属性页,一般地,我们
       都将对应于这个属性页的workbenchpart的id作为本contributor的id,这样我们在代码中可以不硬编码本id字符串,而使
       用getSite().getId()就可以得到这个id了(当然,这样定义id不是必须的)。一个property view可以被多个
       workbench part共享,但 一个workbench part只能有一个property view,这个workbench part需要实现
       ITabbedPropertySheetPageContributor 接口,这个接口只有一个方法,要求返回本part对应的tabbed property 
       Contributor id,一般只要return getSite().getId();
   contributor有如下几个attribute:
    1)typeMapper,这个类需要实现org.eclipse.ui.views.properties.tabbed.ITypeMapper,主要是实现类型的映射,
      因为我们选择的元素并不一定是实现IPropertySource的元素(即能够给property view提供内容的元素),比如在GEF中,
      我们选择的finger实际上是选择了对应的EditPart,而实际上实现了IPropertySource一般的是model部分的元素,
      所以这时候我们要将Editpart映射到对应的model元素。
  
  2)labelProvider,需要一个实现org.eclipse.jface.viewers.ILabelProvider的类,主要是在各个tabs的最上面显示
       文字和图片。
    3)propertyCategory,用于聚合多个tabs,注意至少要定义一个category,来聚合tabs,否则,可能会显示property失败。
    2。Tabs,这个需要扩展org.eclipse.ui.views.properties.tabbed.propertyTabs扩展点,其中contributorId就是
      与之相关联的Contributor的id,然后我们可以定义多个tab,这些tab的属性如下:
    1)label,用于显示在property view的tab bar上的字
    2)category,填入的就是在Contributor扩展点中定义的那些category,用于聚合tabs
    3)id,本tab的唯一标识
    4)afterTab,用于tab之间的排序,如果这是第一个tab,则没有afterTab,afterTab指的是在本tab之前的那个tab,并且
      afterTab描述的是在同一个category中的tabs,不同category之间的顺序是按照在contributor中定义category的顺序
      来定义的。
    5)indented,如果为ture,则各个tabs是有缩进的
    6)image,本tab的图片

    3。section ,需要扩展 org.eclipse.ui.views.properties.tabbed.PropertySections扩展点,它的
      contributionId就是本section所在的Contribution的id,针对每个tab,我们可以定义多个section,每个section的
      attribut描述如下:
    1)id,本secation的唯一标识
    2)tab,本section所属tab的标识
    3)class,实现了org.eclipse.ui.views.properties.tabbed.AbstractPropertySection抽象类的类,用于描述这个
       section的控件和布局。
    4)aftersection和上面的aftertab差不多,描述的是同一个tab中的section的顺序,注意afterserction描述的是本
       section之前的section的id
    5)filter:一个实现org.eclipse.jface.viewers.IFilter接口的过滤器,对选中元素进行过滤。
    6)enableFor:一个用于只是选择数目的值,必须要符合这个舒服才能使能这个section。如果不符合,则这个section就被过
       滤了,如果省略本值,则section的使能器就不会工作了。这是一个自然数,比如,当enableFor=1时,仅仅只有一个元素
       被选择的时候,本section才会被使能。

some notes:
    上面说过实现ITabbedPropertySheetPageContributor接口的workbench part除了要实现getContributeId方法外,
     还需要重载getAdapter方法,因为eclipse的默认加载的property veiw时原来的那个view,为了使tabbed property 
     view能够加载,我们就需要重载getAdapter方法,返回一个TabbedPropertySheetPage对象。

    在实现section class的时候需要注意,createcontrol时首先应该先创建一个composite,一般是 Composite composite
      = getWidgetFactory().createFlatFormComposite(parent); 然后各个控件在这个composite上创建。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值