KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.field;
2 import jimm.datavision.Report;
3 import jimm.datavision.Section;
4 import jimm.datavision.source.Column;
5 import jimm.util.I18N;
6
7 /**
8  * A column field represents a data source column. The value of a column field
9  * holds the {@link Column} object.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  */

13 public class ColumnField extends Field {
14
15 protected Column column;
16
17 /**
18  * Constructs a column field with the specified id in the specified report
19  * section whose database {@link Column}'s id is <var>value</var>.
20  *
21  * @param id the new field's id
22  * @param report the report containing this element
23  * @param section the report section in which the field resides
24  * @param value the string id of a database column
25  * @param visible show/hide flag
26  */

27 public ColumnField(Long JavaDoc id, Report report, Section section, Object JavaDoc value,
28            boolean visible)
29 {
30     super(id, report, section, value, visible);
31     column = report.findColumn((String JavaDoc)value);
32     if (column == null) {
33     String JavaDoc errorMsg = I18N.get("UnknownColumn.the_column")
34         + ' ' + (String JavaDoc)value + ' '
35         + I18N.get("UnknownColumn.column_unknown");
36     throw new IllegalArgumentException JavaDoc(errorMsg);
37     }
38 }
39
40 public String JavaDoc dragString() {
41     return typeString() + ":" + column.getId();
42 }
43
44 /**
45  * Returns the database column.
46  *
47  * @return the database column
48  */

49 public Column getColumn() { return column; }
50
51 /**
52  * Sets the database column.
53  *
54  * @param newColumn the new database column
55  */

56 public void setColumn(Column newColumn) {
57     if (column != newColumn) {
58     column = newColumn;
59     setChanged();
60     notifyObservers();
61     }
62 }
63
64 public String JavaDoc typeString() { return "column"; }
65
66 public String JavaDoc formulaString() { return "{" + value + "}"; }
67
68 /**
69  * Returns the value of this field. For column fields, this is the current
70  * value of the database column.
71  *
72  * @return the value string
73  */

74 public Object JavaDoc getValue() { return getReport().columnValue(column); }
75
76 /**
77  * This override returns <code>true</code> if this column is in a detail
78  * section and holds a numeric type.
79  *
80  * @return <code>true</code> if this field can be aggregated
81  */

82 public boolean canBeAggregated() {
83     // Section can be null during dragging.
84
return section != null && section.isDetail() && getColumn().isNumeric();
85 }
86
87 }
88
Popular Tags