Java 如何正确创建向导页面(Eclipse平台)
在创建页面后的库代码中,发生控件属性的断言检查:Java 如何正确创建向导页面(Eclipse平台),java,eclipse,eclipse-plugin,eclipse-rcp,Java,Eclipse,Eclipse Plugin,Eclipse Rcp,在创建页面后的库代码中,发生控件属性的断言检查: public void createPageControls(Composite pageContainer) { // the default behavior is to create all the pages controls for (int i = 0; i < pages.size(); i++) { IWizardPage page = (IWizardPage) pa
public void createPageControls(Composite pageContainer) {
// the default behavior is to create all the pages controls
for (int i = 0; i < pages.size(); i++) {
IWizardPage page = (IWizardPage) pages.get(i);
page.createControl(pageContainer);
// page is responsible for ensuring the created control is
// accessable
// via getControl.
Assert.isNotNull(page.getControl());
}
}
这种决定的缺点是什么?在
WizardPage.createControl
中,您必须创建某种类型的控件
——通常是一个组合
,并且您必须调用WizardPage.setControl(Control)
来告诉WizardPage
哪一个是顶级控件。所以通常是这样的:
@Override
public void createControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NULL);
...
setControl(composite);
}
如果你尝试一下会发生什么?
@Override
public void createControl(final Composite parent)
{
final Composite composite = new Composite(parent, SWT.NULL);
...
setControl(composite);
}