1 package org.objectstyle.cayenne.swing; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import javax.swing.JTable ; 7 8 13 public class TableBindingBuilder { 14 15 protected BindingBuilder helper; 16 protected List columns; 17 18 public TableBindingBuilder(BindingFactory factory, Object context) { 19 this(new BindingBuilder(factory, context)); 20 } 21 22 public TableBindingBuilder(BindingBuilder helper) { 23 this.helper = helper; 24 } 25 26 29 public ObjectBinding bindToTable(JTable table, String listBinding) { 30 int width = (columns != null) ? columns.size() : 0; 31 32 String [] headers = new String [width]; 33 BindingExpression[] expressions = new BindingExpression[width]; 34 Class [] classes = new Class [width]; 35 boolean[] editableState = new boolean[width]; 36 37 for (int i = 0; i < width; i++) { 38 ColumnDescriptor descriptor = (ColumnDescriptor) columns.get(i); 39 headers[i] = descriptor.header; 40 expressions[i] = descriptor.expression; 41 classes[i] = descriptor.columnClass; 42 editableState[i] = descriptor.editable; 43 } 44 45 ObjectBinding binding = helper.getFactory().bindToTable( 46 table, 47 listBinding, 48 headers, 49 expressions, 50 classes, 51 editableState); 52 return helper.initBinding(binding, helper.getDelegate()); 53 } 54 55 58 public void addColumn( 59 String header, 60 String expression, 61 Class columnClass, 62 boolean editable) { 63 if (columns == null) { 64 columns = new ArrayList (); 65 } 66 67 columns.add(new ColumnDescriptor( 68 header, 69 new BindingExpression(expression), 70 columnClass, 71 editable)); 72 } 73 74 final class ColumnDescriptor { 75 76 String header; 77 BindingExpression expression; 78 boolean editable; 79 Class columnClass; 80 81 ColumnDescriptor(String header, BindingExpression expression, Class columnClass, 82 boolean editable) { 83 this.header = header; 84 this.expression = expression; 85 this.editable = editable; 86 this.columnClass = columnClass; 87 } 88 } 89 } | Popular Tags |