private static Collection<Binding> wire(BoundExtent bound, BindingContext context, Field field) throws IntrospectionException { String target = bound.to(); final ObjectFieldMethod setter = context.findSetter(target); final ObjectFieldMethod getter = context.findGetter(target); if (setter == null || getter == null) { throw new IllegalArgumentException("could not find setter/getter for @BoundExtent: " + field); } final BindableModel model1 = context.getFieldObject(setter.getField(), BindableModel.class); final BindableModel model2 = context.getFieldObject(getter.getField(), BindableModel.class); assert model1 == model2; if (Component.class.isAssignableFrom(field.getType())) { final JSlider comp = context.getFieldObject(field, JSlider.class); return bindSlider(bound, context, comp, setter, getter, model1); } else { throw new IllegalArgumentException("don't know how to wire up @BoundExtent field: " + field.getName()); } }
private static Collection<Binding> wire(BoundLocation bound, BindingContext context, Field field) throws IntrospectionException { String target = bound.to(); final ObjectFieldMethod setter = context.findSetter(target); final ObjectFieldMethod getter = context.findGetter(target); if (setter == null || getter == null) { throw new IllegalArgumentException("could not finder setter/getter for @BoundLocation: " + field); } final BindableModel model1 = context.getFieldObject(setter.getField(), BindableModel.class); final BindableModel model2 = context.getFieldObject(getter.getField(), BindableModel.class); assert model1 == model2; if (Component.class.isAssignableFrom(field.getType())) { final Component comp = context.getFieldObject(field, Component.class); return bindComponent(bound, context, comp, setter, getter, model1); } else { throw new IllegalArgumentException("don't know how to wire up @BoundLocation field: " + field.getName()); } }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { String target = bound.to(); JProgressBar bar = context.getFieldObject(field, JProgressBar.class); // ObjectFieldMethod setter = context.findSetter(target); ObjectFieldMethod getter = context.findGetter(target); if (getter == null) { throw new IllegalArgumentException("could not find getter/setter for " + target); } BindableModel model = context.getFieldObject(getter.getField(), BindableModel.class); // verify type parameters return bindJProgressBar(model, bar, getter.getMethod()); }
final ObjectFieldMethod getter = context.findGetter(to); if (getter == null) { throw new BindingException("could not find bindable property: " + to);
final ObjectFieldMethod getter = context.findGetter(to); if (getter == null) { throw new BindingException("could not find bindable property: " + to);
/** * 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); }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { String target = bound.to(); JPasswordField pwdField = context.getFieldObject(field, JPasswordField.class); ObjectFieldMethod setter = context.findSetter(target); ObjectFieldMethod getter = context.findGetter(target); if (setter == null || getter == null) { throw new IllegalArgumentException("could not find getter/setter for " + target); } BindableModel model1 = context.getFieldObject(setter.getField(), BindableModel.class); BindableModel model2 = context.getFieldObject(getter.getField(), BindableModel.class); Preconditions.checkArgument(model1 == model2, "setter not bound to same field as getter"); // verify type parameters return bindJPasswordField(model1, pwdField, getter.getMethod(), setter.getMethod()); }
public void testGetterIndex() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { model1.setSimpleString("string1"); model2.setSimpleString("string2"); model.setOtherString("other"); BindingContext context = new BindingContext(this); assertNull(context.findGetter("simpleString")); ObjectFieldMethod ofm = context.findGetter("model1.simpleString"); assertEquals("string1", ofm.getMethod().invoke(ofm.getObject(), (Object[])null)); ofm = context.findGetter("model2.simpleString"); assertEquals("string2", ofm.getMethod().invoke(ofm.getObject(), (Object[])null)); ofm = context.findGetter("otherString"); assertEquals("other", ofm.getMethod().invoke(ofm.getObject(), (Object[])null)); }