public Collection<Binding> wire(BindingContext context) { List<Field> boundFields = context.getAnnotatedFields(BoundSelection.class); List<Binding> bindings = Lists.newArrayList(); for (Field field : boundFields) { BoundSelection bound = field.getAnnotation(BoundSelection.class); try { bindings.addAll(wire(bound, context, field)); } catch (Exception e) { throw Throwables.throwUncheckedException(e); } } return bindings; }
private static Collection<Binding> wire(BoundSelection bound, BindingContext context, Field field) throws IntrospectionException { String target = bound.to(); Mutator mutator = Mutator.create(context, target); if (JList.class.isAssignableFrom(field.getType())) { final JList list = context.getFieldObject(field, JList.class); return bindJList(bound, mutator, list); } else if (JComboBox.class.isAssignableFrom(field.getType())) { final JComboBox combo = context.getFieldObject(field, JComboBox.class); final String nullValue = (String)Bound.Utilities.getNullValue(context, bound.nullValue()); return bindJComboBox(bound, mutator, combo, nullValue); } else { throw new IllegalArgumentException("don't know how to wire up @BoundSelection field: " + field.getName()); } }