super(FormModelHelper.createFormModel(new Selection()));
}
protected JComponent createFormControl() {
SwingBindingFactory bf = new SwingBindingFactory(getFormModel());
TableFormBuilder formBuilder = new TableFormBuilder(bf);
formBuilder.row();
Map<String, Object> countryContext = new HashMap<String, Object>();
countryContext.put(ListSelectionDialogBinder.SELECTABLE_ITEMS_HOLDER_KEY, new ValueHolder(countries));
countryContext.put(ListSelectionDialogBinder.LABEL_PROVIDER_KEY, new LabelProvider() {
public String getLabel(Object item) {
Country country = (Country) item;
return country == null ? "" : country.getName();
}
});
countryContext.put(ListSelectionDialogBinder.FILTERED_KEY, Boolean.TRUE);
countryContext.put(ListSelectionDialogBinder.FILTER_PROPERTIES_KEY, new String[] { "name" });
// this works ... but unfortunately ListSelectionDialogBinder has no public constructor
// ListSelectionDialogBinder binder = new ListSelectionDialogBinder();
// Binding binding = binder.bind(getFormModel(), "country", countryContext);
// formBuilder.add(binding, "colSpan=2");
// this works if the binderSelectionStrategy is configured in richclient-application-context.xml
formBuilder.add(bf.createBinding("country", countryContext), "colSpan=2");
formBuilder.row();
this.addFormValueChangeListener("country", new ChangeCountryListener());
refreshableTownValueHolder = new RefreshableValueHolder(new Closure() {
public Object call(Object object) {
Country country = (Country) getValue("country");
List<Town> towns = getTowns(country);
if (towns == null) {
towns = Collections.EMPTY_LIST;
}
return towns;
}
}, true, false);
refreshableTownValueHolder.setValue(Collections.EMPTY_LIST);
formBuilder
.add(bf.createBoundComboBox("town", refreshableTownValueHolder, "name"), "colSpan=2 align=left");
formBuilder.row();
return formBuilder.getForm();
}