use of com.servoy.j2db.dataui.IServoyAwareBean in project servoy-client by Servoy.
the class DataAdapterList method setRecord.
/**
* Inform all dataAdapters about the new state. <br><br>
*
* Note on param: stopAnyEdit, the Renderer paints state 6 (record 6) after that the editor comes in and edits
* that state 6, then another row must be repainted so State 7 and it calls stop editing on 6, but the editor is
* still editing that state 6
*
* @param state the new state (can be null to delete old state)
*/
public void setRecord(IRecordInternal state, boolean stopAnyEdit) {
if (destroyed) {
Debug.error("calling setRecord on a destroyed DataAdapterList, formcontroller: " + formController + ", currentRecord: " + currentRecord, new RuntimeException());
return;
}
if (undoManager != null)
undoManager.setIgnoreEdits(true);
if (currentRecord != null) {
// NEVER enable this ,values in the state could be changed: if (currentState.equals(state)) return;//same
if (!currentRecord.equals(state)) {
stopUIEditing(false);
}
if (state != currentRecord) {
// unregister
currentRecord.removeModificationListener(this);
}
}
if (state != null && state != currentRecord) {
// register so we are notified about javascript changes on non global vars from here
state.addModificationListener(this);
}
currentRecord = state;
// 1) handle first related data (needed for comboboxes)
for (IDisplayRelatedData drd : relatedDataAdapters) {
if (// && !(state instanceof PrototypeState))
state != null) {
if (// performance enhancement
!(drd instanceof RelatedFieldHolder)) {
drd.setRecord(state, stopAnyEdit);
}
} else {
// clear
drd.setRecord(null, true);
}
}
// check if destroyed.
if (dataAdapters == null)
return;
// 2) handle all fields, make sure all the events are collected and fired later (calculations that are triggering data change events)
FireCollector collector = FireCollector.getFireCollector();
try {
Iterator<IDataAdapter> it = dataAdapters.values().iterator();
while (it.hasNext()) {
IDataAdapter da = it.next();
da.setRecord(state);
}
if (currentRecord != null && servoyAwareBeans.size() > 0) {
ServoyBeanState sbr = new ServoyBeanState(state, getFormScope());
for (IServoyAwareBean da : servoyAwareBeans) {
try {
da.setSelectedRecord(sbr);
} catch (RuntimeException e) {
// never make the app break on faulty beans
Debug.error(e);
}
}
}
} finally {
collector.done();
}
if (undoManager != null)
undoManager.setIgnoreEdits(false);
}
Aggregations