KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.gumby.view.binding;
2
3 import javax.swing.text.JTextComponent 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 TextBinding 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     JTextComponent JavaDoc comp = (JTextComponent JavaDoc) acquireWidget(owner);
34     if(value != null) {
35       comp.setText(value.toString());
36     }
37   }
38
39   /**
40    * @see org.sapia.gumby.view.Binding#onChanged(org.sapia.gumby.view.View,
41    * java.lang.Object)
42    */

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

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

59   public void updateModel(View owner, Object JavaDoc model) {
60     JXPathContext ctx = JXPathContext.newContext(model);
61     ctx.setLenient(true);
62     JTextComponent JavaDoc comp = (JTextComponent JavaDoc) acquireWidget(owner);
63     _expr.setValue(ctx, comp.getText());
64   }
65
66 }
67
Popular Tags