public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { String text = ""; Object obj = mutator.get(); if (obj != null) { text = obj.toString(); } label.setText(text); } catch (Exception ex) { Wiring.logger.error("exception in JLabel binding", ex); } } };
public static Binding bindJTextComponent(final Mutator mutator, final JTextComponent textField) { if (mutator.getSetter() != null) { textField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { if (mutator.getGetter() != null) { binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { mutator.getModel().bind(binding);
public void itemStateChanged(ItemEvent e) { try { Object current = mutator.get(); Object newValue = combo.getSelectedItem(); if (newValue != null && newValue.equals(nullValue)) { newValue = null; } if (!Objects.equal(current, newValue)) { mutator.set(newValue); } } catch (Exception ex) { logger.error("could not invoke JComboBox binding", ex); } } });
public static Binding bindJLabel(final Mutator mutator, final JLabel label) { Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { String text = ""; Object obj = mutator.get(); if (obj != null) { text = obj.toString(); } label.setText(text); } catch (Exception ex) { Wiring.logger.error("exception in JLabel binding", ex); } } }; mutator.getModel().bind(binding); return binding; } }
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 void actionPerformed(ActionEvent e) { try { mutator.set(enumValue); } catch (Exception ex) { Wiring.logger.error("exception in JToggleButton binding", ex); //$NON-NLS-1$ } } });
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$ } }
/** * 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); }
private Binding bindJList(final Bound bound, final Mutator mutator, final JList list) { final List<Object> ons = BindingContext.getOnObjects(bound.on(), mutator.getModel()); Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { if (!BindingContext.isOn(ons, changed)) { return; } try { updateListModel(list, (List<?>)mutator.get()); } catch (Exception ex) { Wiring.logger.error("exception in JList binding", ex); } } }; mutator.getModel().bind(binding); return binding; }
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 void actionPerformed(ActionEvent e) { try { mutator.set(booleanValue); } catch (Exception ex) { Wiring.logger.error("exception in JRadioButton binding", ex); //$NON-NLS-1$ } } });
public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { String string = (String)mutator.get(); if (string == null) { string = ""; } if (!string.equals(textField.getText())) { textField.setText(string); } } catch (Exception ex) { Wiring.logger.error("exception in JTextField binding", ex); } } };
private Binding bindJComboBox(final Bound bound, final Mutator mutator, final JComboBox combo, final String nullValue) { final List<Object> ons = BindingContext.getOnObjects(bound.on(), mutator.getModel()); Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { if (!BindingContext.isOn(ons, changed)) { return; } try { updateComboModel(combo, (List<?>)mutator.get(), nullValue); } catch (Exception ex) { Wiring.logger.error("exception in JList binding", ex); } } }; mutator.getModel().bind(binding); return 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)); }
private void updateModel() { try { mutator.set(textField.getText()); } catch (Exception ex) { Wiring.logger.error("exception in JTextField binding", ex); } } });
public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { Object current = mutator.get(); if (current == null) { current = nullValue; } if (!Objects.equal(combo.getSelectedItem(), current)) { combo.setSelectedItem(current); } } catch (Exception ex) { logger.error("could not invoke JComboBox binding", ex); } } };
mutator.getModel().bind(binding); return binding;
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 <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { button.setSelected(mutator.get().equals(Boolean.valueOf(booleanValue))); } catch (Exception ex) { Wiring.logger.error("exception in JRadioButton binding", ex); //$NON-NLS-1$ } } };