1 56 package org.objectstyle.cayenne.swing; 57 58 import javax.swing.AbstractButton ; 59 import javax.swing.JComboBox ; 60 import javax.swing.JTable ; 61 import javax.swing.JTextArea ; 62 import javax.swing.JTextField ; 63 64 69 public class BindingFactory { 70 71 protected boolean usingNullForEmptyStrings; 72 protected boolean checkingForValueChange; 73 74 public BindingFactory() { 75 usingNullForEmptyStrings = true; 77 checkingForValueChange = true; 78 } 79 80 public ObjectBinding bindToTable( 81 JTable table, 82 String listBinding, 83 String [] headers, 84 BindingExpression[] columns, 85 Class [] columnClass, 86 boolean[] editableState) { 87 88 TableBinding binding = new TableBinding( 89 table, 90 listBinding, 91 headers, 92 columns, 93 columnClass, 94 editableState); 95 return prepareBinding(binding); 96 } 97 98 public ObjectBinding bindToProperty( 99 BoundComponent component, 100 String property, 101 String boundProperty) { 102 PropertyBinding binding = new PropertyBinding(component, property, boundProperty); 103 return prepareBinding(binding); 104 } 105 106 110 public ObjectBinding bindToStateChange(AbstractButton button, String property) { 111 ItemEventBinding binding = new ItemEventBinding(button, property); 112 return prepareBinding(binding); 113 } 114 115 119 public ObjectBinding bindToAction(AbstractButton button, String action) { 120 ActionBinding binding = new ActionBinding(button, action); 121 return prepareBinding(binding); 122 } 123 124 public ObjectBinding bindToComboSelection( 125 JComboBox component, 126 String property, 127 String noSelectionValue) { 128 ComboSelectionBinding binding = new ComboSelectionBinding( 129 component, 130 property, 131 noSelectionValue); 132 return prepareBinding(binding); 133 } 134 135 public ObjectBinding bindToTextArea(JTextArea component, String property) { 136 TextBinding binding = new TextBinding(component, property); 137 return prepareBinding(binding); 138 } 139 140 143 public ObjectBinding bindToTextField(JTextField component, String property) { 144 TextBinding binding = new TextBinding(component, property); 145 return prepareBinding(binding); 146 } 147 148 151 protected ObjectBinding prepareBinding(BindingBase binding) { 152 binding.setUsingNullForEmptyStrings(isUsingNullForEmptyStrings()); 153 binding.setCheckingForValueChange(isCheckingForValueChange()); 154 return binding; 155 } 156 157 public boolean isCheckingForValueChange() { 158 return checkingForValueChange; 159 } 160 161 public void setCheckingForValueChange(boolean callingSetForEqual) { 162 this.checkingForValueChange = callingSetForEqual; 163 } 164 165 public boolean isUsingNullForEmptyStrings() { 166 return usingNullForEmptyStrings; 167 } 168 169 public void setUsingNullForEmptyStrings(boolean usingNullForEmptyStrings) { 170 this.usingNullForEmptyStrings = usingNullForEmptyStrings; 171 } 172 } | Popular Tags |