yep, a ShuttleList setup works similarly. In my builder I have an add shuttle list method:
Code:
public JComponent addShuttleList(String propertyName, ValueModel selectableItemsHolder, String renderedProperty, int column, int row, int widthSpan, int heightSpan) {
Map context = ShuttleListBinder.createBindingContext(getFormModel(), propertyName, selectableItemsHolder, renderedProperty);
Binding binding = getBindingFactory().createBinding(ShuttleList.class, propertyName, context);
ShuttleList shuttleList = (ShuttleList)binding.getControl();
addComponent(shuttleList, column, row, widthSpan, heightSpan);
return shuttleList;
}
and in the createFormControl method you can then simply add a ShuttleList with a RefreshableValueHolder and Closure as before:
Code:
refreshableValueHolder = new RefreshableValueHolder(new Closure() {
@Override
public Object call(Object o) {
if(company != null) {
return companyService.getAvailableFacilities(company.getId());
} else {
return Collections.EMPTY_LIST;
}
}
}, false, false);
ShuttleList shuttleList = (ShuttleList)builder.addShuttleList("facilities", refreshableValueHolder, "name", 1, 3, 5, 1);
This will create a ShuttleList bound to the "facilities" property of your form backing object. The list will render the facility using the "name" property. This time you can see that I have a reference to the refreshableValueHolder, this is important. Elsewhere in my form, I may have (attempting to stick to your example here) a combo box that allows the user to select which company they are assigning facilities to. You would then add a listener to the combo box that forces a refresh on the refreshableValueHolder to get the new list of selectable items, like this:
Code:
combobox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshableValueHolder.refresh();
// anything else you may need to do...
}
});
This is set up like this because unlike the combo box example, where we refreshed the selectable values when the popup menu was about to be shown, the ShuttleList doesn't have a self-contained idea of when the selectable list should be updated. In this case it is more natural for the refresh to be triggered by an external action such as the user selecting a new company or facility, creating a new company to add to the database, etc.