private static String normalizeString(String string) { if (Bound.Utilities.isNullOrBlank(string)) { return null; } return string; }
public void insertUpdate(DocumentEvent e) { updateModel(); }
public void removeUpdate(DocumentEvent e) { updateModel(); }
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)); }
public void testIsNullOrBlank() { assertTrue(Bound.Utilities.isNullOrBlank(null)); assertTrue(Bound.Utilities.isNullOrBlank("")); assertTrue(Bound.Utilities.isNullOrBlank(" ")); assertFalse(Bound.Utilities.isNullOrBlank("a")); assertFalse(Bound.Utilities.isNullOrBlank(" a b c ")); }
class CommentsView extends BaseView<CommentableModel> { @Bound(to = "comment") private JLabel countLabel = new JLabel(); public CommentsView(CommentableModel model) { super(model); panel.add(countLabel, BorderLayout.EAST); bindings.bind(this); } }
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 class NegativeActionTest extends TestCase { @Action(call = "failure") private final Object object = new Object(); final Bindings bindings = new Bindings(); public void testFailure() { try { bindings.bind(this); fail("should not allow @Action binding to object with no addActionListener"); } catch (Exception e) { e.printStackTrace(); } } }
class BaseView<T extends BaseModel> { protected final T model; protected Bindings bindings = new Bindings(); protected JPanel panel = new JPanel(new BorderLayout()); // "model." is required to prevent subclasses from clobbering @Bound(to = "model.displayText") private final JLabel label = new JLabel(); public BaseView(T model) { this.model = model; panel.add(label, BorderLayout.CENTER); } }
public void removeUpdate(DocumentEvent e) { updateModel(); }
public void insertUpdate(DocumentEvent e) { updateModel(); }
@Bindable private abstract static class Base { @Action(call = "this.refresh") JButton button = new JButton("test"); abstract public void refresh(); }
public class CommentsView2 extends BaseView<CommentableModel> { private final CommentableModel commentableModel; @Bound(to="comment") private JLabel countLabel = new JLabel(); private Bindings bindings = new Bindings(); public CommentsView2(CommentableModel model) { super(model); this.commentableModel = model; panel.add(countLabel, BorderLayout.EAST); bindings.bind(this); } }
public void changedUpdate(DocumentEvent e) { updateModel(); }
public void changedUpdate(DocumentEvent e) { updateModel(); }
public class CantFindGetterSetterTest extends TestCase { final NegativeModel model = new NegativeModel(); @Bound(to = "cantFind") private final JRadioButton button = new JRadioButton("button"); final Bindings bindings = new Bindings(); public void testFailure() { try { bindings.bind(this); fail("should not allow binding if can't find getter or setter"); } catch (Exception e) { System.err.println(e.getMessage()); } } }
public class WrongTypeTest extends TestCase { final NegativeModel model = new NegativeModel(); @Bound(to = "badEnum") private final JRadioButton button = new JRadioButton("button"); final Bindings bindings = new Bindings(); public void testFailure() { try { bindings.bind(this); fail("should not allow binding to wrong type"); } catch (Exception e) { System.err.println(e.getMessage()); } } }
private static class BooleanComponent { final BooleanModel model; @Bound(to = "state") final JCheckBox box = new JCheckBox("State"); final Bindings bindings = new Bindings(); public BooleanComponent(BooleanModel model) { this.model = model; this.bindings.bind(this); } public JComponent getDisplayComponent() { return box; } public void dispose() { bindings.release(model); } }