KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > dataset > DataValue


1 /*
2  * $Id: DataValue.java,v 1.1 2005/02/23 17:51:29 rbair Exp $
3  *
4  * Copyright 2005 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.dataset;
9
10 import java.beans.PropertyChangeListener JavaDoc;
11 import java.beans.PropertyChangeSupport JavaDoc;
12 import org.jdesktop.dataset.NameGenerator;
13
14 /**
15  * TODO implement a PropertyChangeListener on the synthetic "value" field.
16  * When some value that the DataValue expression depends on changes, it
17  * becomes necessary to recompute the "value", and then notify that the
18  * "value" has changed.
19  *
20  * @author rbair
21  */

22 public class DataValue {
23     //protected for testing
24
protected static final String JavaDoc DEFAULT_NAME_PREFIX = "DataValue";
25     private static final NameGenerator NAMEGEN = new NameGenerator(DEFAULT_NAME_PREFIX);
26
27     //used for communicating changes to this JavaBean, especially necessary for
28
//IDE tools, but also handy for any other component listening to this data value
29
private PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
30
31     private DataSet dataSet;
32     private String JavaDoc name;
33     
34     private String JavaDoc expression;
35     
36     /** Creates a new instance of DataValue */
37     public DataValue(DataSet ds) {
38         assert ds != null;
39         this.dataSet = ds;
40         name = NAMEGEN.generateName(this);
41     }
42     
43     /**
44      * @param name
45      */

46     public void setName(String JavaDoc name) {
47         if (this.name != name) {
48             assert DataSetUtils.isValidName(name);
49             String JavaDoc oldName = this.name;
50             this.name = name;
51             pcs.firePropertyChange("name", oldName, name);
52         }
53     }
54
55     public String JavaDoc getName() {
56         return name;
57     }
58
59     public DataSet getDataSet() {
60         return dataSet;
61     }
62     
63     public String JavaDoc getExpression() {
64         return expression;
65     }
66     
67     public void setExpression(String JavaDoc expression) {
68         this.expression = expression;
69     }
70     
71     public Object JavaDoc getValue() {
72         if (expression != null) {
73             //TODO Hook functor stuff in here for expressions
74
return null;
75         } else {
76             return null;
77         }
78     }
79
80     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
81         pcs.addPropertyChangeListener(listener);
82     }
83     
84     public void addPropertyChangeListener(String JavaDoc property, PropertyChangeListener JavaDoc listener) {
85         pcs.addPropertyChangeListener(property, listener);
86     }
87     
88     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
89         pcs.removePropertyChangeListener(listener);
90     }
91     
92     public void removePropertyChangeListener(String JavaDoc propertyName, PropertyChangeListener JavaDoc listener) {
93         pcs.removePropertyChangeListener(propertyName, listener);
94     }
95 }
Popular Tags