Expandable composite
在网页中有个普遍的功能就是让你有能力把一部分网页内容用一个按钮
这个composite接受一些风格参数来控制它的表现行为ExpandableComposite ec = toolkit.createExpandableComposite(form.getBody(), 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); } });
ExpandableComposite有责任处理按钮组件和标题
我们的视图现在看起来象这样:
图11:一个收缩状态的expandable composite例子
当你点击标题的"+"时,composite伸展出并展示客户:
图12:expandable composite呈伸展状态
expandable composite用到了一个内部layout,这个layout
段落(Section)
Eclipse Forms定制的组件中最versatile之一就是Sectio
1.分隔条(Separator)-一个能够在标题下创建的separato
2.描述(Description)-在标题下的可选的描述.
3.标题栏(Title bar)-能在标题下的一个标题栏(注意separator和标题
下面的代码和expandable composite代码例子差不多:
这次我们用了TWISTIE风格,添加了描述并要求有标题栏.这个视图看起来应该象这样:Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR| 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"); 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);
图13:一个有标题栏和描述的可伸展的section