Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Based off of an example in Scott Violet's last blog at sun, a BindingBuilder in practice would look something like this:

Code Block
// code from elsewhere...
public class Bug {
    @BoundProperty String ID
    @BoundProperty int priority
  @BoundPriority  @BoundProperty String synopsus
    @BoundProperty String type

List<Bug> bugs = [...] // assuming generics make it into 1.1

bugsTablebugTable = theSwingBuilder.bugsTable
summaryLabel = theSwingBuilder.summaryLabel
idTF = theSwingBuilder.idTF
summaryLabeldescriptionTF = theSwingBuilder.summaryLabeldescriptionTF
typeTF = theSwingBuilder.typeTF
prioritySlider = theSwingBuilder.prioritySlider

// the actual bindings
BindingBuilder bindings = new BindingBuilderBeansBindingBuilder()
context = bindings.context() {
  binding(source: bugs, target: bugsTablebugTable, property:'elements') {
      bindbinding(value:'${ID}') {
      bindbinding(value:'${priority}') {
      bindbinding(value:'${synopsis}') {
    value:'${bb:listSize(selectedElements)} of ${bb:listSize(elements)} are selected',
  binding(source:bugTable, value:'${selectedElements.ID}', target:idTF, property:'text') {
    concatenatingCondensor(['"', '"', ','])
  binding(source:bugTable, value:'${selectedElements.synopsis}', target:descriptionTF, property:'text')  source:bugTable,
    concatenatingCondensor(['"', '"', ','])
  binding(source:bugTable, value:'${bb:listSize(selectedElements)} of ${bb:listSize(elements)} are selected'
    property:'textselectedElements.type}', target:typeTF, property:'text') {
    concatenatingCondensor(['"', '"', ','])
  binding(source:bugTable, value:'${selectedElements.priority}', target:prioritySlider, property:'value')


Once I get a better feel for the existing code I can mock up what all the possible children would be.

 Here's what the java snippets from the post are

Code Block
 contextcontext = new BindingContext();

List<Bug> bugs = ...;
Binding tableBinding = context.addBinding(
    bugs,      // Source for the binding, the List of bugs in this case.
    null,      // Expression, relative to the source, used in obtaining the property.
               // For this example it's null, meaning use bugs as is.
    bugTable,  // Target of the binding, a JTable in this case.
    "elements"); // The property of the target to bind to.

    "${ID}",    // Expression evaluated relative to each Bug.
                // In this case, it's treated as bug.getID().
    null,       // Target value (I'm not going to get into this parameter now)
    TableColumnParameter, 0); // Specifies the binding applies to the first column

tableBinding.addBinding("${priority}", null, TableColumnParameter, 1);
tableBinding.addBinding("${synopsis}", null, TableColumnParameter, 2);

Binding textFieldBinding = context.addBinding(
    bugTable,                 // Source of the binding, the JTable in this case.
    "${selectedElements.ID}", // Expression relative to the source. Evaluates to the
                              // the id property of each of the selected elements
    idTF,                     // Target of the binding, a JTextField here.
    "text",                   // The target property to bind to.
    // The next line specifies the 'text' property should change as you type.
    // The default is to change the property on enter/focus leaving.
    TextChangeStrategyParameter, TextChangeStrategy.CHANGE_ON_TYPE);

    "\"",   // The string placed before each element
    "\"",   // The string paced after each element
    ", ")); // The string that separates each element.

  bugTable,  // The source of the binding, the table in this case.
  // The expression evaluated relative to the source. Notice this makes use
  // of the function "listSize", that returns an size of the list supplied to it.
  "${bb:listSize(selectedElements)} of ${bb:listSize(elements)} are selected",
  summaryLabel, // The target of the binding, a JLabel here.
  "text");      // The target property to bind to