001: package jimm.datavision;
002:
003: import jimm.datavision.field.Field;
004: import jimm.util.XMLWriter;
005:
006: /**
007: * A suppression proc is an object used to decide if data should be
008: * displayed or not. It returns <code>true</code> if the data should
009: * be displayed or <code>false</code> if the data should be supressed
010: * (should not be displayed).
011: *
012: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
013: */
014: public class SuppressionProc implements Writeable {
015:
016: protected Formula formula;
017: protected Report report;
018: protected boolean hiding;
019:
020: public SuppressionProc(Report report) {
021: this .report = report;
022: hiding = false;
023: }
024:
025: public boolean isHidden() {
026: return hiding;
027: }
028:
029: public void setHidden(boolean val) {
030: hiding = val;
031: }
032:
033: /**
034: * Returns formula used when not hiding.
035: *
036: * @return formula used when not hiding
037: */
038: public Formula getFormula() {
039: if (formula == null) {
040: formula = new Formula(null, report, "");
041: report = null; // Don't need it anymore
042: }
043: return formula;
044: }
045:
046: public boolean refersTo(Field f) {
047: return formula != null && formula.refersTo(f);
048: }
049:
050: public boolean refersTo(Formula f) {
051: return formula != null && (f == formula || formula.refersTo(f));
052: }
053:
054: public boolean refersTo(UserColumn uc) {
055: return formula != null && formula.refersTo(uc);
056: }
057:
058: public boolean refersTo(Parameter p) {
059: return formula != null && formula.refersTo(p);
060: }
061:
062: /**
063: * Returns <code>true</code> if the data should be suppressed (not displayed).
064: * Returns <code>false</code> if the data should not be supressed (it should
065: * be displayed).
066: *
067: * @return <code>true</code> if the data should be suppressed (not displayed)
068: */
069: public boolean suppress() {
070: if (hiding)
071: return true;
072: if (formula == null)
073: return false;
074:
075: String expr = formula.getExpression();
076: if (expr == null || expr.length() == 0)
077: return false;
078:
079: Object obj = formula.eval();
080: if (obj == null) // Bogus BSF code format (bad column)
081: return false;
082: return ((Boolean) obj).booleanValue();
083: }
084:
085: /**
086: * Writes this suppression proc as an XML tag.
087: *
088: * @param out a writer that knows how to write XML
089: */
090: public void writeXML(XMLWriter out) {
091: String expression = null;
092: boolean hasFormula = formula != null
093: && (expression = formula.getExpression()) != null
094: && expression.length() > 0;
095:
096: if (!hiding && !hasFormula)
097: return;
098:
099: out.startElement("suppression-proc");
100: if (hiding)
101: out.attr("hide", true);
102:
103: if (hasFormula)
104: formula.writeXML(out);
105:
106: out.endElement();
107: }
108:
109: }
|