}
为了简化 Sample 理解复杂度,doAddPages 方法中只加入首页(SampleProjectFirstPage),而忽略 了其他页面。在构造函数中,使用 SetWindowTitle 方法设置 Wizard 标题。getDefalutProvider 中注 册 SampleProjectCreationDataModelProvider 用来执行控制操作。
清单 3. Wizard Page
protected void createPresetPanel(Composite top)
{
final Group group = new Group(top, SWT.NONE);
group.setText("Sample Main Class");
group.setLayoutData(gdhfill());
group.setLayout(new GridLayout(2, false));
Label lp = new Label(group, SWT.NULL);
lp.setText("Package");
Text tp = new Text(group, SWT.BORDER);
tp.setLayoutData(gdhfill());
Label lc = new Label(group, SWT.NULL);
lc.setText("Name");
Text tc = new Text(group, SWT.BORDER);
tc.setLayoutData(gdhfill());
synchHelper.synchText(tp,
SampleProjectCreationDataModelProvider.PACKAGE, null);
synchHelper.synchText(tc,
SampleProjectCreationDataModelProvider.MAIN_CLASS_NAME, null);
}
Eclipse插件开发-如何扩展 WTP Wizard(9)
时间:2011-10-22 IBM 黄彦军 王浩
Sample Wizard 的首页隐蔽了 Dynamic Web Project Wizard 首页中 Dynamic WEB Module Version 与 Configuration Group。因此 Sample Page 通过继承 WEB Project Page,并重写相关 createPresetPanel,createPrimaryFacetComposite 方法来达到目的。
这里通过 synchHelper 方法的 synchText 方法实现 Text 空间与 provider 想关联的 Model 同步, 当 Text 值发生改变时,helper 通过自身 Listener 机制通知 Model 来同步 UI 数据。相应地, synchHelper 还提供了与 Label、Combo\ Tree ,CheckBox 等 Widget 同步方法。
清单 4. Provider
public class SampleProjectCreationDataModelProvider extends
WebFacetProjectCreationDataModelProvider
{
public static final String PACKAGE = "MAIN_CLASS_PACKAGE";
public static final String MAIN_CLASS_NAME = "MAIN_CLASS_NAME";
public static final String DEFAULT_PACKAGE = "com.sample.app";
public static final String DEFAULT_MAIN_CLASS_NAME = "NewsListSample";
public Object getDefaultProperty(String propertyName) {
if (PACKAGE.equals(propertyName))
return DEFAULT_PACKAGE;
if (MAIN_CLASS_NAME.equals(propertyName))
return DEFAULT_MAIN_CLASS_NAME;
return super.getDefaultProperty(propertyName);
}
public Set getPropertyNames() {
Set propertyNames = super.getPropertyNames();
propertyNames.add(PACKAGE);
propertyNames.add(MAIN_CLASS_NAME);
return propertyNames;
}
public IStatus validate(String propertyName) {
//do validate
return super.validate(propertyName);
}
public IDataModelOperation getDefaultOperation() {
return new SampleCreationOperation(getDataModel());
}
}
如前图所示,Page 中新增了两个字段 Main Class Package 和 Main Class Name,所以 Provider 继 承 WebFacetProjectCreationDataModelProvider 之后重写 getPropertyNames 方法,加入上述字段。为 了方便用户 |