1 package jimm.datavision.field; 2 import jimm.datavision.*; 3 import jimm.datavision.gui.FieldWidget; 4 import jimm.datavision.gui.FormulaWidget; 5 import jimm.datavision.gui.SectionWidget; 6 import java.util.Collection ; 7 import java.util.Observer ; 8 import java.util.Observable ; 9 10 17 public class FormulaField extends Field implements Observer { 18 19 protected Formula formula; 20 21 31 public FormulaField(Long id, Report report, Section section, Object value, 32 boolean visible) 33 { 34 super(id, report, section, value, visible); 35 formula = report.findFormula(value); 36 formula.addObserver(this); 37 } 38 39 protected void finalize() throws Throwable { 40 formula.deleteObserver(this); 41 super.finalize(); 42 } 43 44 public void update(Observable o, Object arg) { 45 setChanged(); 46 notifyObservers(arg); 47 } 48 49 public FieldWidget makeWidget(SectionWidget sw) { 50 return new FormulaWidget(sw, this); 51 } 52 53 56 public String dragString() { 57 return typeString() + ":" + formula.getId(); 58 } 59 60 65 public Formula getFormula() { return formula; } 66 67 72 public void setFormula(Formula newFormula) { 73 if (formula != newFormula) { 74 formula.deleteObserver(this); 75 formula = newFormula; 76 formula.addObserver(this); 77 setChanged(); 78 notifyObservers(); 79 } 80 } 81 82 public String typeString() { return "formula"; } 83 84 public String designLabel() { return formula.designLabel(); } 85 86 public String formulaString() { return formula.formulaString(); } 87 88 public boolean refersTo(Field f) { 89 return formula.refersTo(f); 90 } 91 92 public boolean refersTo(Formula f) { 93 return f == formula || formula.refersTo(f); 94 } 95 96 public boolean refersTo(UserColumn uc) { 97 return formula.refersTo(uc); 98 } 99 100 public boolean refersTo(Parameter p) { 101 return formula.refersTo(p); 102 } 103 104 111 public boolean canBeAggregated() { 112 return section != null && section.isDetail(); 114 } 115 116 122 public Object getValue() { return formula.eval(this); } 123 124 132 public Collection columnsUsed() { 133 return formula.columnsUsed(); 134 } 135 136 145 public Collection userColumnsUsed() { 146 return formula.userColumnsUsed(); 147 } 148 149 } 150 | Popular Tags |