String attr = (String) SIMPLE_CASES[i][0];
int size = ((Integer) SIMPLE_CASES[i][1]).intValue();
ModelModifier modifier = new ComponentAttributeModifier(attr);
TextEditor editor = new TextEditor();
editor.setSize(size);
FieldInfo fieldInfo = new FieldInfo(attr, attr, modifier, editor);
context.addFieldInfo(fieldInfo);
}
// ---------------------------------
// A couple more complicated ones...
// ---------------------------------
{
// ----------------
// Sum greater than
// ----------------
String id = OrderSource.SUM_GREATER_THAN_ATTR;
ModelModifier modifier = new DefaultModelModifier() {
public Object getModelValue(Object model) throws Exception {
return ((OrderSource) model).getSumGreaterThan();
}
public void setModelValue(Object model, Object value) throws Exception {
((OrderSource) model).setSumGreaterThan((Double) value);
}
};
DoubleFormatter formatter = new DoubleFormatter();
formatter.setAcceptEmptyValues(true);
TextEditor editor = new TextEditor();
editor.setSize(10);
editor.setFormatter(formatter);
FieldInfo fieldInfo = new FieldInfo(id, id, modifier, editor);
context.addFieldInfo(fieldInfo);
}
{
// -------------
// Sum less than
// -------------
String id = OrderSource.SUM_LESS_THAN_ATTR;
ModelModifier modifier = new DefaultModelModifier() {
public Object getModelValue(Object model) throws Exception {
return ((OrderSource) model).getSumLessThan();
}
public void setModelValue(Object model, Object value) throws Exception {
((OrderSource) model).setSumLessThan((Double) value);
}
};
DoubleFormatter formatter = new DoubleFormatter();
formatter.setAcceptEmptyValues(true);
TextEditor editor = new TextEditor();
editor.setSize(10);
editor.setFormatter(formatter);
FieldInfo fieldInfo = new FieldInfo(id, id, modifier, editor);
context.addFieldInfo(fieldInfo);
}
{
// ----------
// Date after
// ----------
String id = "dateAfter";
ModelModifier modifier = new DefaultModelModifier() {
public Object getModelValue(Object model) throws Exception {
Date date = ((OrderSource) model).getDateAfter();
if(date != null)
return OrderSource.dateFormat.format(date);
else
return "";
}
public void setModelValue(Object model, Object value) throws Exception {
String valueStr = (String) value;
Date date = null;
if(valueStr != null && valueStr.length() != 0) {
try {
date = OrderSource.dateFormat.parse(valueStr);
} catch(ParseException pe) { /* Ignore invalid dates */ }
}
((OrderSource) model).setDateAfter(date);
}
};
TextEditor editor = new TextEditor();
editor.setSize(50);
//and finally create the configurationObject
FieldInfo fieldInfo = new FieldInfo(id, id, modifier, editor);
//add the configuration to the context for usage in the http-requests.
context.addFieldInfo(fieldInfo);
}
{
// -----------
// Date before
// -----------
String id = "dateBefore";
ModelModifier modifier = new DefaultModelModifier() {
public Object getModelValue(Object model) throws Exception {
Date date = ((OrderSource) model).getDateBefore();
if(date != null)
return OrderSource.dateFormat.format(date);
else
return "";
}
public void setModelValue(Object model, Object value) throws Exception {
String valueStr = (String) value;
Date date = null;
if(valueStr != null && valueStr.length() != 0) {
try {
date = OrderSource.dateFormat.parse(valueStr);
} catch(ParseException pe) { /* Ignore invalid dates */ }
}
((OrderSource) model).setDateBefore(date);
}
};
TextEditor editor = new TextEditor();
editor.setSize(50);
//and finally create the configurationObject
FieldInfo fieldInfo = new FieldInfo(id, id, modifier, editor);
//add the configuration to the context for usage in the http-requests.
context.addFieldInfo(fieldInfo);
}