KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > field > UserColumnField


1 package jimm.datavision.field;
2 import jimm.datavision.*;
3 import jimm.datavision.gui.FieldWidget;
4 import jimm.datavision.gui.UserColumnWidget;
5 import jimm.datavision.gui.SectionWidget;
6 import java.util.Collection JavaDoc;
7 import java.util.Observer JavaDoc;
8 import java.util.Observable JavaDoc;
9
10 /**
11  * A user column field represents a user column, which in turn holds some SQL
12  * that is put in the SELECT clause of a query. The value of a user column
13  * field holds a {@link UserColumn} object. (In the XML, the user column
14  * field's value is the id of the user column.)
15  *
16  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
17  */

18 public class UserColumnField extends Field implements Observer JavaDoc {
19
20 protected UserColumn usercol;
21
22 /**
23  * Constructs a user column field with the specified id in the specified report
24  * section whose {@link UserColumn}'s id is <var>value</var>.
25  *
26  * @param id the new field's id
27  * @param report the report containing this element
28  * @param section the report section in which the field resides
29  * @param value the id of a user column
30  * @param visible show/hide flag
31  */

32 public UserColumnField(Long JavaDoc id, Report report, Section section, Object JavaDoc value,
33             boolean visible)
34 {
35     super(id, report, section, value, visible);
36     usercol = report.findUserColumn(value);
37     usercol.addObserver(this);
38 }
39
40 protected void finalize() throws Throwable JavaDoc {
41     usercol.deleteObserver(this);
42     super.finalize();
43 }
44
45 public void update(Observable JavaDoc o, Object JavaDoc arg) {
46     setChanged();
47     notifyObservers(arg);
48 }
49
50 public FieldWidget makeWidget(SectionWidget sw) {
51     return new UserColumnWidget(sw, this);
52 }
53
54 /**
55  * Not really used; we drag user columns, not user column fields.
56  */

57 public String JavaDoc dragString() {
58     return typeString() + ":" + usercol.getId();
59 }
60
61 /**
62  * Returns the user column.
63  *
64  * @return the user column
65  */

66 public UserColumn getUserColumn() { return usercol; }
67
68 /**
69  * Sets the user column.
70  *
71  * @param newUsercol the new user column
72  */

73 public void setUserColumn(UserColumn newUsercol) {
74     if (usercol != newUsercol) {
75     usercol.deleteObserver(this);
76     usercol = newUsercol;
77     usercol.addObserver(this);
78     setChanged();
79     notifyObservers();
80     }
81 }
82
83 public String JavaDoc typeString() { return "usercol"; }
84
85 public String JavaDoc designLabel() { return usercol.designLabel(); }
86
87 public String JavaDoc formulaString() { return usercol.formulaString(); }
88
89 public boolean refersTo(Field f) {
90     return usercol.refersTo(f);
91 }
92
93 public boolean refersTo(Parameter p) {
94     return usercol.refersTo(p);
95 }
96
97 /**
98  * This override returns <code>true</code> if this user column is in a
99  * detail section. We don't really know that this user column returns
100  * a number, so we'll err on the side of allowing aggregation.
101  *
102  * @return <code>true</code> if this field can be aggregated
103  */

104 public boolean canBeAggregated() {
105     // Section can be null during dragging.
106
return section != null && section.isDetail();
107 }
108
109 /**
110  * Returns the value of this field. For user column fields, this is the
111  * value generated by evaluating the {@link UserColumn}.
112  *
113  * @return the result of evaluating the usercol
114  */

115 public Object JavaDoc getValue() { return getReport().columnValue(usercol); }
116
117 /**
118  * Returns a collection of the columns used in the user column. This is used
119  * by the report's query when it is figuring out what columns and tables
120  * are used by the report. Calls {@link UserColumn#columnsUsed}.
121  *
122  * @see jimm.datavision.source.Query#findSelectablesUsed
123  */

124 public Collection JavaDoc columnsUsed() {
125     return usercol.columnsUsed();
126 }
127
128 }
129
Popular Tags