use of com.servoy.j2db.util.IDelegate in project servoy-client by Servoy.
the class CellAdapter method getCellEditorValue.
public Object getCellEditorValue() {
// test if currentEditing state isn't deleted already
if (currentEditingState == null || dataProviderID == null || (currentEditingState != null && currentEditingState.getParentFoundSet() == null))
return null;
Object comp = editor;
if ((comp instanceof IDisplay && ((IDisplay) comp).isReadOnly()) || gettingEditorValue) {
return currentEditingState.getValue(getDataProviderID());
}
try {
gettingEditorValue = true;
if (comp instanceof IDelegate<?>) {
comp = ((IDelegate<?>) comp).getDelegate();
}
// HACK:needed for commit value copied from other hack 'processfocus' in DataField
if (comp instanceof DataField && ((DataField) comp).isEditable()) {
DataField edit = (DataField) comp;
boolean needEntireState = edit.needEntireState();
try {
edit.setNeedEntireState(false);
int fb = edit.getFocusLostBehavior();
if (fb == JFormattedTextField.COMMIT || fb == JFormattedTextField.COMMIT_OR_REVERT) {
try {
edit.commitEdit();
// Give it a chance to reformat.
edit.setValueObject(edit.getValue());
} catch (ParseException pe) {
return null;
}
} else if (fb == JFormattedTextField.REVERT) {
edit.setValueObject(edit.getValue());
}
} finally {
edit.setNeedEntireState(needEntireState);
}
}
Object obj = null;
if (editor instanceof IDisplayData) {
IDisplayData displayData = (IDisplayData) editor;
obj = Utils.removeJavascripLinkFromDisplay(displayData, null);
if (!findMode) {
// use UI converter to convert from UI value to record value
obj = ComponentFormat.applyUIConverterFromObject(displayData, obj, dataProviderID, application.getFoundSetManager());
}
// if the editor is not enable or is readonly dont try to set any value.
if (!displayData.isEnabled() || displayData.isReadOnly())
return obj;
// this can happen when toggeling with readonly. case 233226 or 232188
if (!currentEditingState.isEditing() && !currentEditingState.startEditing())
return obj;
try {
if (// $NON-NLS-1$
currentEditingState != null && (obj == null || "".equals(obj)) && currentEditingState.getValue(dataProviderID) == null) {
return null;
}
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
Object oldVal = null;
if (currentEditingState instanceof FindState) {
if (displayData instanceof IScriptableProvider && ((IScriptableProvider) displayData).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat() != null) {
((FindState) currentEditingState).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat().parsedFormat);
}
try {
oldVal = currentEditingState.getValue(dataProviderID);
} catch (IllegalArgumentException iae) {
// $NON-NLS-1$
Debug.error("Error getting the previous value", iae);
oldVal = null;
}
currentEditingState.setValue(dataProviderID, obj);
if (!Utils.equalObjects(oldVal, obj)) {
// call notifyLastNewValue changed so that the onChangeEvent will be fired and called when attached.
displayData.notifyLastNewValueWasChange(oldVal, obj);
obj = dal.getValueObject(currentEditingState, dataProviderID);
}
} else {
if (!displayData.isValueValid() && Utils.equalObjects(lastInvalidValue, obj)) {
// already validated
return obj;
}
try {
adjusting = true;
try {
oldVal = currentEditingState.getValue(dataProviderID);
} catch (IllegalArgumentException iae) {
// $NON-NLS-1$
Debug.error("Error getting the previous value", iae);
}
try {
if (oldVal == Scriptable.NOT_FOUND && dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
oldVal = dal.getFormScope().get(dataProviderID);
dal.getFormScope().put(dataProviderID, obj);
IFoundSetInternal foundset = currentEditingState.getParentFoundSet();
if (foundset instanceof FoundSet)
((FoundSet) foundset).fireFoundSetChanged();
} else
currentEditingState.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
displayData.setValueValid(false, oldVal);
application.handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = null;
try {
stateValue = dal.getValueObject(currentEditingState, dataProviderID);
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
Object displayValue;
if (Utils.equalObjects(oldVal, stateValue)) {
// reset display to typed value
displayValue = obj;
} else {
// reset display to changed value in validator method
displayValue = stateValue;
}
convertAndSetValue(displayData, displayValue);
return displayValue;
}
if (!Utils.equalObjects(oldVal, obj)) {
fireModificationEvent(currentEditingState);
displayData.notifyLastNewValueWasChange(oldVal, obj);
obj = dal.getValueObject(currentEditingState, dataProviderID);
// we also want to reset the value in the current display if changed by script
convertAndSetValue(displayData, obj);
} else if (!displayData.isValueValid()) {
displayData.notifyLastNewValueWasChange(null, obj);
} else {
displayData.setValueValid(true, null);
}
} finally {
adjusting = false;
if (displayData.isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
}
return obj;
} finally {
gettingEditorValue = false;
}
}
Aggregations