public boolean verify(JComponent component) {
if (updating) {
return true;
}
FieldDialog parentFieldDialog = ComponentFactory.getParentFieldDialog(component);
if (parentFieldDialog != null)
parentFieldDialog.setDirtyComponent(null);
JComponent c = component;
component = valueHoldingComponent(component);
component.setForeground(Color.BLACK);
c.setForeground(Color.BLACK);
Object newValue = ComponentFactory.getValueFromComponent(component, field);
//System.out.println("new value " + newValue + " " + (newValue != null ?newValue.getClass():""));
// avoid validating unchanged controls
if (newValue == value || (newValue != null && newValue.equals(value))) { //unchanged
if (component instanceof JSpinner || component instanceof ExtDateField) { // if a spinner, check for modified text
String text = ((JTextField)c).getText();
try {
if (!(component instanceof ExtDateField) || text.trim().length() > 0)
newValue = field.getFormat().parseObject(text);
else {
((JTextField)c).setText(""); // put in empty text
newValue = null;
}
} catch (ParseException e1) {
exception = new FieldParseException(field.syntaxErrorForField());
component.setForeground(Color.RED);
c.setForeground(Color.RED);
if (parentFieldDialog != null)
parentFieldDialog.setDirtyComponent(c);
return false;
}
} else {
return true;
}
}
if (newValue != null && value != null && newValue.toString().equals(value.toString()))
return true;
exception = null;
try {
if (field.hasOptions()) {
if (newValue == null)
newValue = Select.EMPTY;
field.setText(objectRef,newValue.toString(),context);
} else {
if (field.isDate()) {
if (newValue != null && newValue instanceof String) {
try {
newValue = EditOption.getInstance().getDateFormat().parseObject((String) newValue);
} catch (ParseException e) {
}
}
if (newValue == null || newValue.toString().trim().equals("")) // empty text on date is a null date
newValue = DateTime.getZeroDate();
}
if (newValue != value){
Object oldValue=field.getValue(objectRef, context);
if (field.isMoney())
field.setText(objectRef,""+newValue,context);
else
field.setValue(objectRef,source,newValue,context);
UndoableEditSupport undoableEditSupport=objectRef.getDataFactory().getUndoController().getEditSupport();
if (undoableEditSupport!=null){
undoableEditSupport.postEdit(new FieldEdit(field,objectRef,value,oldValue,this,context));
}
}
}
} catch (FieldParseException e) {
exception = e;
component.setForeground(Color.RED);
c.setForeground(Color.RED);
if (parentFieldDialog != null)
parentFieldDialog.setDirtyComponent(c);
return false;
}
setValue(newValue); // set to new value for next time
return true;
}