1 package org.sapia.gumby.view.binding; 2 3 import javax.swing.JCheckBox ; 4 5 import org.apache.commons.jxpath.JXPathContext; 6 import org.sapia.gumby.view.View; 7 8 23 public class CheckboxBinding extends AbstractJXPathBinding { 24 25 29 public void onBound(View owner, Object model) { 30 JXPathContext ctx = JXPathContext.newContext(model); 31 ctx.setLenient(true); 32 Object value = _expr.getValue(ctx); 33 JCheckBox comp = (JCheckBox ) acquireWidget(owner); 34 if(value != null) { 35 try { 36 comp.setSelected(((Boolean ) value).booleanValue()); 37 } catch(ClassCastException e) { 38 } 39 } 40 } 41 42 46 public void onChanged(View owner, Object model) { 47 onBound(owner, model); 48 } 49 50 54 public void onUpdated(View owner, Object model) { 55 onBound(owner, model); 56 } 57 58 62 public void updateModel(View owner, Object model) { 63 JXPathContext ctx = JXPathContext.newContext(model); 64 ctx.setLenient(true); 65 JCheckBox comp = (JCheckBox ) acquireWidget(owner); 66 _expr.setValue(ctx, new Boolean (comp.isSelected())); 67 } 68 69 } 70 | Popular Tags |