KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > SuppressionProc


1 package jimm.datavision;
2 import jimm.datavision.field.Field;
3 import jimm.util.XMLWriter;
4
5 /**
6  * A suppression proc is an object used to decide if data should be
7  * displayed or not. It returns <code>true</code> if the data should
8  * be displayed or <code>false</code> if the data should be supressed
9  * (should not be displayed).
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  */

13 public class SuppressionProc implements Writeable {
14
15 protected Formula formula;
16 protected Report report;
17 protected boolean hiding;
18
19 public SuppressionProc(Report report) {
20     this.report = report;
21     hiding = false;
22 }
23
24 public boolean isHidden() { return hiding; }
25 public void setHidden(boolean val) { hiding = val; }
26
27 /**
28  * Returns formula used when not hiding.
29  *
30  * @return formula used when not hiding
31  */

32 public Formula getFormula() {
33     if (formula == null) {
34     formula = new Formula(null, report, "");
35     report = null; // Don't need it anymore
36
}
37     return formula;
38 }
39
40 public boolean refersTo(Field f) {
41     return formula != null && formula.refersTo(f);
42 }
43
44 public boolean refersTo(Formula f) {
45     return formula != null && (f == formula || formula.refersTo(f));
46 }
47
48 public boolean refersTo(UserColumn uc) {
49     return formula != null && formula.refersTo(uc);
50 }
51
52 public boolean refersTo(Parameter p) {
53     return formula != null && formula.refersTo(p);
54 }
55
56
57 /**
58  * Returns <code>true</code> if the data should be suppressed (not displayed).
59  * Returns <code>false</code> if the data should not be supressed (it should
60  * be displayed).
61  *
62  * @return <code>true</code> if the data should be suppressed (not displayed)
63  */

64 public boolean suppress() {
65     if (hiding)
66     return true;
67     if (formula == null)
68     return false;
69
70     String JavaDoc expr = formula.getExpression();
71     if (expr == null || expr.length() == 0)
72     return false;
73
74     Object JavaDoc obj = formula.eval();
75     if (obj == null) // Bogus BSF code format (bad column)
76
return false;
77     return ((Boolean JavaDoc)obj).booleanValue();
78 }
79
80 /**
81  * Writes this suppression proc as an XML tag.
82  *
83  * @param out a writer that knows how to write XML
84  */

85 public void writeXML(XMLWriter out) {
86     String JavaDoc expression = null;
87     boolean hasFormula = formula != null
88     && (expression = formula.getExpression()) != null
89     && expression.length() > 0;
90
91     if (!hiding && !hasFormula)
92     return;
93
94     out.startElement("suppression-proc");
95     if (hiding)
96     out.attr("hide", true);
97
98     if (hasFormula)
99     formula.writeXML(out);
100
101     out.endElement();
102 }
103
104 }
105
Popular Tags