jimm.datavision.field
Class FormulaField

java.lang.Object
  extended by java.util.Observable
      extended by jimm.datavision.Element
          extended by jimm.datavision.field.Field
              extended by jimm.datavision.field.FormulaField
All Implemented Interfaces:
java.lang.Cloneable, java.util.Observer, Draggable, Identity, Writeable

public class FormulaField
extends Field
implements java.util.Observer

A formula field represents a formula calculated on-the-fly. The value of a formula field holds a Formula object. (In the XML, the formula field's value is the id of the formula.)

Author:
Jim Menard, jimm@io.com

Field Summary
protected  Formula formula
           
 
Fields inherited from class jimm.datavision.field.Field
border, bounds, cache, DEFAULT_HEIGHT, DEFAULT_WIDTH, format, id, maxIdSeen, value
 
Fields inherited from class jimm.datavision.Element
report, section, visible
 
Constructor Summary
FormulaField(java.lang.Long id, Report report, Section section, java.lang.Object value, boolean visible)
          Constructs a formula field with the specified id in the specified report section whose Formula's id is value.
 
Method Summary
 boolean canBeAggregated()
          This override returns true if this formula is in a detail section.
 java.util.Collection columnsUsed()
          Returns a collection of the columns used in the formula.
 java.lang.String designLabel()
          Returns a string representing the field in the GUI during report design.
 java.lang.String dragString()
          Not really used; we drag formulas, not formula fields.
protected  void finalize()
           
 java.lang.String formulaString()
          Returns a string representing the field as it appears in a formula.
 Formula getFormula()
          Returns the formula.
 java.lang.Object getValue()
          Returns the value of this field.
 FieldWidget makeWidget(SectionWidget sw)
          Returns a new widget of the appropriate FieldWidget subclass for this field.
 boolean refersTo(Field f)
          Returns true if this field contains a reference to the specified field.
 boolean refersTo(Formula f)
          Returns true if this field contains a reference to the specified formula.
 boolean refersTo(Parameter p)
          Returns true if this field contains a reference to the specified parameter.
 boolean refersTo(UserColumn uc)
          Returns true if this field contains a reference to the specified user column.
 void setFormula(Formula newFormula)
          Sets the formula.
 java.lang.String typeString()
          Returns the string that specifies this field's type in the report XML.
 void update(java.util.Observable o, java.lang.Object arg)
           
 java.util.Collection userColumnsUsed()
          Returns a collection of the user columns used in the formula.
 
Methods inherited from class jimm.datavision.field.Field
clone, create, createFromDragString, getBorder, getBorderOrDefault, getBounds, getFormat, getId, getOutputHeight, setBorder, setBounds, setFormat, setValue, toString, writeFieldGuts, writeXML
 
Methods inherited from class jimm.datavision.Element
getReport, getSection, isVisible, setSection, setVisible
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

formula

protected Formula formula
Constructor Detail

FormulaField

public FormulaField(java.lang.Long id,
                    Report report,
                    Section section,
                    java.lang.Object value,
                    boolean visible)
Constructs a formula field with the specified id in the specified report section whose Formula's id is value.

Parameters:
id - the new field's id
report - the report containing this element
section - the report section in which the field resides
value - the id of a formula
visible - show/hide flag
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class Field
Throws:
java.lang.Throwable

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer
Overrides:
update in class Field

makeWidget

public FieldWidget makeWidget(SectionWidget sw)
Description copied from class: Field
Returns a new widget of the appropriate FieldWidget subclass for this field. Subclasses override this method to return different types of widgets.

Overrides:
makeWidget in class Field
Parameters:
sw - a field widget

dragString

public java.lang.String dragString()
Not really used; we drag formulas, not formula fields.

Specified by:
dragString in interface Draggable
Specified by:
dragString in class Field
Returns:
the string used to identify the field when dragging

getFormula

public Formula getFormula()
Returns the formula.

Returns:
the formula

setFormula

public void setFormula(Formula newFormula)
Sets the formula.

Parameters:
newFormula - the new formula

typeString

public java.lang.String typeString()
Description copied from class: Field
Returns the string that specifies this field's type in the report XML.

Specified by:
typeString in class Field
Returns:
a string representing this field's type; used in XML files

designLabel

public java.lang.String designLabel()
Description copied from class: Field
Returns a string representing the field in the GUI during report design.

Overrides:
designLabel in class Field
Returns:
a string useful for display in the design GUI

formulaString

public java.lang.String formulaString()
Description copied from class: Field
Returns a string representing the field as it appears in a formula.

Specified by:
formulaString in class Field
Returns:
a string useful in a formula

refersTo

public boolean refersTo(Field f)
Description copied from class: Field
Returns true if this field contains a reference to the specified field. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
f - a field
Returns:
true if this field contains a reference to the specified field

refersTo

public boolean refersTo(Formula f)
Description copied from class: Field
Returns true if this field contains a reference to the specified formula. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
f - a formula
Returns:
true if this field contains a reference to the specified field

refersTo

public boolean refersTo(UserColumn uc)
Description copied from class: Field
Returns true if this field contains a reference to the specified user column. Most fields return false; only a AggregateField, UserColumnField, or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
uc - a user column
Returns:
true if this field contains a reference to the specified user column

refersTo

public boolean refersTo(Parameter p)
Description copied from class: Field
Returns true if this field contains a reference to the specified parameter. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
p - a parameter
Returns:
true if this field contains a reference to the specified field

canBeAggregated

public boolean canBeAggregated()
This override returns true if this formula is in a detail section. We don't really know that this formula returns a number, so we'll err on the side of allowing aggregation.

Overrides:
canBeAggregated in class Field
Returns:
true if this field can be aggregated

getValue

public java.lang.Object getValue()
Returns the value of this field. For formula fields, this is the value generated by evaluating the Formula.

Overrides:
getValue in class Field
Returns:
the result of evaluating the formula

columnsUsed

public java.util.Collection columnsUsed()
Returns a collection of the columns used in the formula. This is used by the report's query when it is figuring out what columns and tables are used by the report. Calls Expression.columnsUsed().

Returns:
a possibly empty collection of database columns
See Also:
Query.findSelectablesUsed()

userColumnsUsed

public java.util.Collection userColumnsUsed()
Returns a collection of the user columns used in the formula. This is used by the report's query when it is figuring out what columns, tables, and user columns are used by the report. Calls Expression.userColumnsUsed().

Returns:
a possibly empty collection of user columns
See Also:
Query.findSelectablesUsed()