public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { JTextComponent textComponent = context.getFieldObject(field, JTextComponent.class); Mutator mutator = Mutator.create(context, bound.to()); Binding binding = bindJTextComponent(mutator, textComponent); if (binding == null) { return ImmutableList.of(); } return ImmutableList.of(binding); }
/** * Creates a new Mutator bound to the passed {@link BindingContext}. * * @param context the context for this {@link Mutator} * @param target the model and field to bind this {@link Mutator} to. * @return the {@link Mutator} * @throws IntrospectionException */ public static Mutator create(BindingContext context, String target) throws IntrospectionException { final ObjectFieldMethod getter = context.findGetter(target); final ObjectFieldMethod setter = context.findSetter(target); if (getter == null && setter == null) { throw new IllegalArgumentException("could not find either getter/setter for " + target); } BindableModel model = null; BindableModel getterModel = null; BindableModel setterModel = null; if (getter != null) { getterModel = context.getFieldObject(getter.getField(), BindableModel.class); model = getterModel; } if (setter != null) { setterModel = context.getFieldObject(setter.getField(), BindableModel.class); model = setterModel; } if (getterModel != null && setterModel != null && getterModel != setterModel) { throw new IllegalStateException("setter and getter must be on same BindableModel."); } return new Mutator(getter, setter, model); }