Eclipse 插件开发-如何扩展 WTP Wizard
2010-04-12 00:00:00 来源:WEB开发网清单 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 方法,加入上述字段。为了方便用户使用 wizard, 重写 Provider 中 getDefaultProperty 方法,为 Package 和 Class Name 提供默认值。Data Model Wizard 作为一套完善的 MVC 框架,实现了 Model 检验功能,当 UI 输入值发生改变时会触发 validate 方法,并将检验结果显示在 Wizard 的 Title 区域。
更多精彩
赞助商链接