站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题Eclipse Form程序设计指南(3)

Eclipse Form程序设计指南(3)

摘要: Eclipse Form程序设计指南(3)

4、复杂控件

(1) ExpandableComposite

l Web页面中一个通用的主题是具有收缩一部分页面内容的能力

l Eclipse Form也提供了这样一个控件:ExpandableComposite

l 下面的代码片断是使用ExpandableComposite的一个例子:

              ExpandableComposite ec = toolkit.createExpandableComposite(body,
                ExpandableComposite.TREE_NODE
                       | ExpandableComposite.CLIENT_INDENT);
              ec.setText("Expandable Composite title");
              String ctext = "We will now create a somewhat long text so that "
                + "we can use it as content for the expandable composite. "
                + "Expandable composite is used to hide or show the text using the "
                + "toggle control";
              Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);
              ec.setClient(client);
              td = new TableWrapData();
              td.colspan = 2;
              ec.setLayoutData(td);
              ec.addExpansionListener(new ExpansionAdapter() {
                public void expansionStateChanged(ExpansionEvent e) {
                       form.reflow(true);
                }
              });

l 这个控件有很多风格,TREE_NODE使得该控件具有树型节点的展开、收缩功能;而TWISTIE使得控件具有三角箭头风格

l EXPANDED使得初始展开显示

l CLIENT_INDENT使得Client内容缩进对齐

l ExpandableComposite呈现为激活控件和标题,而可以展开、收缩的内容称为Client

l Client必须是可展开的composite(上例是Label控件)

l 最后需要添加Expansion监听器在状态变化时,reflow Form(即根据控件的新的大小重新定位和更新滚动条)

l 下面是上例的运行结果:

2)Section

l Eclipse Form中最常用的定制控件就是Section(在PDE中到处可见)

l Section扩展ExpandableComposite,但具有下面的新特性:

n 在标题下面有一个分隔控件

n 在分隔控件下面可以有一个描述文本

l 下面的代码片断是使用Section的一个例子,代码和ExpandableComposite没有太大差别,这里是用了TWISTIE风格:

              Section section = toolkit.createSection(body, Section.DESCRIPTION
                       | Section.TWISTIE | Section.EXPANDED);
              td = new TableWrapData(TableWrapData.FILL);
              td.colspan = 2;
              section.setLayoutData(td);
              section.addExpansionListener(new ExpansionAdapter() {
                public void expansionStateChanged(ExpansionEvent e) {
                       form.reflow(true);
                }
              });
              section.setText("Section title");
              toolkit.createCompositeSeparator(section);
              section
                       .setDescription("This is the description that goes below the title");
              Composite sectionClient = toolkit.createComposite(section);
              sectionClient.setLayout(new GridLayout());
              button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);
              button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);
              section.setClient(sectionClient);

l 下面是上例的运行结果:



↑返回目录
前一篇: Eclipse快速上手Hibernate--4. 继承映射(1)
后一篇: eclipse plugin