KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.field;
2 import jimm.datavision.Report;
3 import jimm.datavision.Section;
4 import jimm.datavision.Subreport;
5
6 /**
7  * A subreport field represents an entire report within a field. The value
8  * of a subreport field holds a report object.
9  *
10  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
11  */

12 public class SubreportField extends Field {
13
14 protected Subreport subreport;
15
16 /**
17  * Constructs a text field with the specified id in the specified report
18  * section whose text value is <i>value</i>.
19  *
20  * @param id the new field's id
21  * @param report the report containing this element
22  * @param section the report section in which the field resides
23  * @param value the id of a subreport
24  * @param visible show/hide flag
25  */

26 public SubreportField(Long JavaDoc id, Report report, Section section, Object JavaDoc value,
27               boolean visible)
28 {
29     super(id, report, section, value, visible);
30     subreport = report.findSubreport(value);
31 }
32
33 public Subreport getSubreport() { return subreport; }
34
35 /**
36  * This override adds or removes the subreport from its parent report. When
37  * <var>s</var> is <code>null</code>, the subreport is removed from the
38  * report. Doing this prevents the subreport from being output as part of
39  * the report when this field has been removed from the report.
40  *
41  * @param s the new section; may be <code>null</code>
42  */

43 public void setSection(Section s) {
44     if (s == null)
45     report.removeSubreport(subreport);
46     else {
47     // The first time we are added to the report, the subreport has
48
// already been added to the report. Avoid adding it again.
49
if (report.findSubreport(subreport.getId()) == null)
50         report.addSubreport(subreport);
51     }
52     super.setSection(s);
53 }
54
55 /**
56  * Returns a string containing a line of text for each row returned by
57  * the subreport query.
58  *
59  * @return a string with newlines separating each row of data
60  */

61 public Object JavaDoc getValue() {
62     return subreport.getValue();
63 }
64
65 public String JavaDoc dragString() {
66     return typeString() + ":" + getId();
67 }
68
69 public String JavaDoc typeString() { return "subreport"; }
70
71 public String JavaDoc formulaString() { return "{|subreport " + getId() + "}"; }
72
73 }
74
Popular Tags