Search in sources :

Example 11 with IServoyAwareBean

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);
}
Also used : ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean)

Aggregations

IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)11 IComponent (com.servoy.j2db.ui.IComponent)5 Point (java.awt.Point)5 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)4 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 IScriptable (com.servoy.j2db.scripting.IScriptable)3 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)3 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)2 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)2 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)2 FormScope (com.servoy.j2db.scripting.FormScope)2