zoukankan      html  css  js  c++  java
  • Eclipse选项卡式的属性视图(The Eclipse Tabbed Properties View)

    Eclipse工作台提供了一个性能视图用于查看(和/或编辑)选定项目的属性。

    在本文中,您将学习怎样使用选项卡式的属性视图创建一个性能增强的用户界面视图。

    1.引言

    Eclipse工作台提供了一个属性视图。即在文章中具体描写叙述你的性能控制。默认的用户界面是属性和值对表,而且值使用一个标准的对话框单元格编辑器。

    工作台使用扩展(extensions)为属性视图定义了一个自己定义的用户界面。利用这个扩展,Properties视图已创建。

    属性视图同意您创建不论什么用户界面的属性。此外,您能够为元素创建用户接口而不用实现IPropertySource。

    其实,属性视图能够被扩展到查看在工作台中被选择的不论什么数据。

    2.实例解析


    依赖 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上创建。

  • 相关阅读:
    移动服务
    CodeForces
    poj1737-----这题有毒
    洛谷P1219 八皇后 (dfs+回溯法)
    codeforces 598D Igor In the Museum(dfs)
    CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)I
    复制构造函数的作用
    codeforces 1102D Balanced Ternary String(贪心+思维)
    学习3DES加密算法笔记
    个人冲刺(六)
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5092490.html
Copyright © 2011-2022 走看看