package jimm.datavision.field;
import jimm.datavision.Report;
import jimm.datavision.Section;
import jimm.datavision.Parameter;
import jimm.datavision.gui.FieldWidget;
import jimm.datavision.gui.ParameterWidget;
import jimm.datavision.gui.SectionWidget;
import java.util.Observer;
import java.util.Observable;
/**
* A parameter field represents a parameter. The value of a parameter field
* holds a {@link Parameter} object. In the XML, the parameter field's value
* is the id of the parameter.
*
* @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
*/
public class ParameterField extends Field implements Observer {
protected Parameter parameter;
/**
* Constructs a parameter field with the specified id in the specified report
* section whose {@link Parameter}'s id is <i>value</i>.
*
* @param id the new field's id
* @param report the report containing this element
* @param section the report section in which the field resides
* @param value the id of a parameter
* @param visible show/hide flag
*/
public ParameterField(Long id, Report report, Section section, Object value,
boolean visible)
{
super(id, report, section, value, visible);
parameter = report.findParameter(value);
parameter.addObserver(this);
}
protected void finalize() throws Throwable {
parameter.deleteObserver(this);
super.finalize();
}
public void update(Observable o, Object arg) {
setChanged();
notifyObservers(arg);
}
public FieldWidget makeWidget(SectionWidget sw) {
return new ParameterWidget(sw, this);
}
/**
* Not really used; we drag parameters, not parameter fields.
*/
public String dragString() {
return typeString() + ":" + parameter.getId();
}
/**
* Returns the parameter.
*
* @return the parameter
*/
public Parameter getParameter() { return parameter; }
/**
* Sets the parameter.
*
* @param newParameter the new parameter
*/
public void setParameter(Parameter newParameter) {
if (parameter != newParameter) {
parameter.deleteObserver(this);
parameter = newParameter;
parameter.addObserver(this);
setChanged();
notifyObservers();
}
}
public String typeString() { return "parameter"; }
public String designLabel() { return parameter.designLabel(); }
public String formulaString() { return parameter.formulaString(); }
public boolean refersTo(Parameter p) {
return parameter == p;
}
/**
* This override returns <code>true</code> if this parameter is in a detail
* section and returns a number.
*
* @return <code>true</code> if this field can be aggregated
*/
public boolean canBeAggregated() {
// Section can be null during dragging.
return section != null && section.isDetail()
&& getParameter().getType() == Parameter.TYPE_NUMERIC;
}
/**
* Returns the value of this field. For parameter fields, this is the
* value generated by evaluating the {@link Parameter}.
*
* @return the result of evaluating the parameter
*/
public Object getValue() { return parameter.getValue(); }
}