Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

This proposal is deffered and not under active development or consideration
The reason for deferral is that the JSR-295 API is too unstable. Since this posting it has gone under a major re-design. It will not be revisited any earlier than the posting of the first proposed final draft for that reason.

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
    @BoundProperty String synopsis
    @BoundProperty String type
}

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

bugTable = theSwingBuilder.bugTable
summaryLabel = theSwingBuilder.summaryLabel
idTF = theSwingBuilder.idTF
descriptionTF = theSwingBuilder.descriptionTF
typeTF = theSwingBuilder.typeTF
prioritySlider = theSwingBuilder.prioritySlider

// the actual bindings
bindings = new BeansBindingBuilder()
context = bindings.context() {
  binding(source: bugs, target: bugTable, property:'elements') {
    binding(value:'${ID}') {
      tableColumn(0)
    }
    binding(value:'${priority}') {
      tableColumn(1)
    }
    binding(value:'${synopsis}') {
      tableColumn(2)
    }
  }
  binding(
    source:bugTable,
    value:'${bb:listSize(selectedElements)} of ${bb:listSize(elements)} are selected',
    target:summaryLabel,
    property:'text')
  binding(source:bugTable, value:'${selectedElements.ID}', target:idTF, property:'text') {
    textChangeStrategy(CHANGE_ON_TYPE)
    concatenatingCondensor(['"', '"', ','])
  }
  binding(source:bugTable, value:'${selectedElements.synopsis}', target:descriptionTF, property:'text') {
    textChangeStrategy(CHANGE_ON_TYPE)
    concatenatingCondensor(['"', '"', ','])
  }
  binding(source:bugTable, value:'${selectedElements.type}', target:typeTF, property:'text') {
    textChangeStrategy(CHANGE_ON_TYPE)
    concatenatingCondensor(['"', '"', ','])
  }
  binding(source:bugTable, value:'${selectedElements.priority}', target:prioritySlider, property:'value')
}

context.bind()



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
context = 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.

tableBinding.addBinding(
    "${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);

textFieldBinding.setListCondenser(ListCondenser.concatenatingCondenser(
    "\"",   // The string placed before each element
    "\"",   // The string paced after each element
    ", ")); // The string that separates each element.

context.addBinding(
  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

context.bind();