public BindableModel apply(Field from) { return getFieldObject(from, BindableModel.class); } };
public BindableModel getBindableModel(String key) { Field field = bindableModels.get(key); if (field == null) { return null; } return getFieldObject(field, BindableModel.class); }
private Map<String, ObjectFieldMethod> indexBindableProperties(Function<PropertyDescriptor, Method> methodFn) throws IntrospectionException { final Map<ObjectFieldMethod, String> getterOfms = Maps.newHashMap(); for (Field field : Sets.newHashSet(bindableModels.values())) { BeanInfo beanInfo = Introspector.getBeanInfo(field.getType()); PropertyDescriptor[] props = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor descriptor : props) { Method method = methodFn.apply(descriptor); if (method == null) { continue; } BindableModel model = getFieldObject(field, BindableModel.class); getterOfms.put(new ObjectFieldMethod(model, field, method), descriptor.getName()); } } return dotIndex(getterOfms.keySet(), ObjectFieldMethod.TO_FIELD_NAME, Functions.forMap(getterOfms)); }
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()); } }
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 { 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); }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { Mutator mutator = Mutator.create(context, bound.to()); AbstractButton abstractButton = context.getFieldObject(field, AbstractButton.class); return ImmutableList.of(bindAbstractButton(mutator, abstractButton)); }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { String target = bound.to(); Mutator mutator = Mutator.create(context, target); JSlider slider = context.getFieldObject(field, JSlider.class); return ImmutableList.of(bindJSlider(mutator, slider)); }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { JList list = context.getFieldObject(field, JList.class); Mutator mutator = Mutator.create(context, bound.to()); return ImmutableList.of(bindJList(bound, mutator, list)); }
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()); }
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { JLabel label = context.getFieldObject(field, JLabel.class); Mutator mutator = Mutator.create(context, bound.to()); return ImmutableList.of(bindJLabel(mutator, label)); }
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()); }
Object actionObject = context.getFieldObject(field, Object.class); final ObjectFieldMethod ofm = context.getBindableMethod(call); if (ofm == null) {
/** * 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(); JComboBox combo = context.getFieldObject(field, JComboBox.class); Mutator mutator = Mutator.create(context, target); final String nullValue = (String)Utilities.getNullValue(context, bound.nullValue()); return ImmutableList.of(bindJComboBox(bound, mutator, combo, nullValue)); }
throw new BindingException("no setEnabled call on EnabledIf field: " + field); final Object setEnabledObject = context.getFieldObject(field, Object.class); final ObjectFieldMethod getter = context.findGetter(to); if (getter == null) {
public Collection<Binding> wire(Bound bound, BindingContext context, Field field) throws IllegalAccessException, IntrospectionException { String target = bound.to(); Mutator mutator = Mutator.create(context, target); JToggleButton toggle = context.getFieldObject(field, JToggleButton.class); Class<?>[] paramTypes = mutator.getSetter().getMethod().getParameterTypes(); if (paramTypes.length == 1 && paramTypes[0].isEnum()) { Class<?> enumType = paramTypes[0]; String value = bound.value(); return ImmutableList.of(bindJToggleButtonToEnum(value, enumType, mutator, toggle)); } else if (paramTypes.length == 1 && paramTypes[0] == boolean.class) { String value = bound.value(); if (Strings.isNullOrEmpty(value)) { return ImmutableList.of(AbstractButtonWiringHarness.bindAbstractButton(mutator, toggle)); } else { return ImmutableList.of(bindJToggleButtonToBoolean(bound.value(), mutator, toggle)); } } else { throw new BindingException("can only bind JToggleButtons to enums or booleans"); //$NON-NLS-1$ } }
throw new BindingException("no setVisible call on VisibleIf field: " + field); final Object setVisibleObject = context.getFieldObject(field, Object.class); final ObjectFieldMethod getter = context.findGetter(to); if (getter == null) {
public Collection<Binding> wire(BindingContext context) { List<Field> loggedModels = context.getAnnotatedFields(LoggedModel.class); List<Binding> bindings = Lists.newArrayList(); for (Field field : loggedModels) { final LoggedModel annotation = field.getAnnotation(LoggedModel.class); final String loggerParam = annotation.logger(); final String fieldName = field.getName(); if (BindableModel.class.isAssignableFrom(field.getType())) { BindableModel model = context.getFieldObject(field, BindableModel.class); Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { for (T t : changed){ Logger logger = LoggerFactory.getLogger(loggerParam); if (logger.isInfoEnabled()) { logger.info(t.toString() + ": " + fieldName); } } } }; model.bind(binding); bindings.add(binding); } else { throw new BindingException("Can only log a BindableModel."); } } return bindings; } }