KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > view > binding > CheckboxBinding


1 package org.sapia.gumby.view.binding;
2
3 import javax.swing.JCheckBox JavaDoc;
4
5 import org.apache.commons.jxpath.JXPathContext;
6 import org.sapia.gumby.view.View;
7
8 /**
9  * @author Yanick Duchesne
10  *
11  * <dl>
12  * <dt><b>Copyright: </b>
13  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
14  * Source Software </a>. All Rights Reserved.</dd>
15  * </dt>
16  * <dt><b>License: </b>
17  * <dd>Read the license.txt file of the jar or visit the <a
18  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
19  * OSS web site</dd>
20  * </dt>
21  * </dl>
22  */

23 public class CheckboxBinding extends AbstractJXPathBinding {
24
25   /**
26    * @see org.sapia.gumby.view.Binding#onBound(org.sapia.gumby.view.View,
27    * java.lang.Object)
28    */

29   public void onBound(View owner, Object JavaDoc model) {
30     JXPathContext ctx = JXPathContext.newContext(model);
31     ctx.setLenient(true);
32     Object JavaDoc value = _expr.getValue(ctx);
33     JCheckBox JavaDoc comp = (JCheckBox JavaDoc) acquireWidget(owner);
34     if(value != null) {
35       try {
36         comp.setSelected(((Boolean JavaDoc) value).booleanValue());
37       } catch(ClassCastException JavaDoc e) {
38       }
39     }
40   }
41
42   /**
43    * @see org.sapia.gumby.view.Binding#onChanged(org.sapia.gumby.view.View,
44    * java.lang.Object)
45    */

46   public void onChanged(View owner, Object JavaDoc model) {
47     onBound(owner, model);
48   }
49
50   /**
51    * @see org.sapia.gumby.view.Binding#onUpdated(org.sapia.gumby.view.View,
52    * java.lang.Object)
53    */

54   public void onUpdated(View owner, Object JavaDoc model) {
55     onBound(owner, model);
56   }
57
58   /**
59    * @see org.sapia.gumby.view.Binding#updateModel(org.sapia.gumby.view.View,
60    * java.lang.Object)
61    */

62   public void updateModel(View owner, Object JavaDoc model) {
63     JXPathContext ctx = JXPathContext.newContext(model);
64     ctx.setLenient(true);
65     JCheckBox JavaDoc comp = (JCheckBox JavaDoc) acquireWidget(owner);
66     _expr.setValue(ctx, new Boolean JavaDoc(comp.isSelected()));
67   }
68
69 }
70
Popular Tags