Search in sources :

Example 1 with FireCollector

use of com.servoy.j2db.dataprocessing.FireCollector in project servoy-client by Servoy.

the class DataAdapterList method setRecord.

public void setRecord(IRecord record, boolean fireChangeEvent) {
    // because all types should just listen to the right stuff.
    if (shouldIgnoreRecordChange(this.record, record))
        return;
    if (settingRecord) {
        if (record != this.record) {
            throw new IllegalStateException("Record " + record + " is being set on DAL when record: " + this.record + " is being processed for form " + getForm());
        }
        return;
    }
    try {
        FireCollector fireCollector = FireCollector.getFireCollector();
        try {
            settingRecord = true;
            formController.getFormUI().setChanging(true);
            if (this.record != null) {
                this.record.removeModificationListener(this);
                this.record.getParentFoundSet().removeAggregateModificationListener(this);
            }
            this.record = (IRecordInternal) record;
            if (this.record != null) {
                pushChangedValues(null, fireChangeEvent);
                this.record.addModificationListener(this);
                this.record.getParentFoundSet().addAggregateModificationListener(this);
            }
            createRelationListeners();
            if (maxRecIndexPropertyValueListener != null)
                maxRecIndexPropertyValueListener.setRecord(this.record);
        } finally {
            formController.getFormUI().setChanging(false);
            settingRecord = false;
            fireCollector.done();
        }
        // we should use the "this.record" because fireCollector.done() could result in a setRecord with a different record.
        if (this.record != null) {
            for (Entry<IWebFormController, String> entry : getVisibleChildFormCopy().entrySet()) {
                String relation = entry.getValue();
                if (relation != null) {
                    IWebFormController form = entry.getKey();
                    form.loadRecords(this.record.getRelatedFoundSet(relation, ((BasicFormController) form).getDefaultSortColumns()));
                }
            }
        }
    } catch (RuntimeException re) {
        throw new RuntimeException("Error setting record " + record + " on form " + getForm() + " on DAL " + this, re);
    }
}
Also used : FireCollector(com.servoy.j2db.dataprocessing.FireCollector) BasicFormController(com.servoy.j2db.BasicFormController)

Example 2 with FireCollector

use of com.servoy.j2db.dataprocessing.FireCollector in project servoy-client by Servoy.

the class ViewportRowDataProvider method writeRowData.

protected void writeRowData(int startIndex, int endIndex, Set<String> columnNames, IFoundSetInternal foundset, JSONWriter w, DataConversion clientConversionInfo, Object sabloValueThatRequestedThisDataToBeWritten) throws JSONException {
    w.array();
    if (foundset != null) {
        int size = foundset.getSize();
        int end = Math.min(size - 1, endIndex);
        if (startIndex <= end) {
            if (end < endIndex) {
                Debug.error("Illegal state: view ports end index " + endIndex + " is bigger then the size " + size, new RuntimeException());
            }
            // as our goal here is to write contents of all these rows to JSON without triggering calculations that end up triggering data-change-related solution handlers that might in
            // turn change data/bounds of data that we are trying to write to JSON, we use fire collector; after we are done writing, any such handlers will be called
            // and if they alter anything in the foundset, the foundset/other listeners will pick that up and generate a new change to be written to JSON...
            FireCollector fireCollector = FireCollector.getFireCollector();
            if (sabloValueThatRequestedThisDataToBeWritten != null) {
                getDataAdapterList().onlyFireListenersForProperty(sabloValueThatRequestedThisDataToBeWritten);
            }
            try {
                for (int i = startIndex; i <= endIndex; i++) {
                    clientConversionInfo.pushNode(String.valueOf(i - startIndex));
                    writeRowData(i, columnNames, foundset, w, clientConversionInfo);
                    clientConversionInfo.popNode();
                }
            } finally {
                if (sabloValueThatRequestedThisDataToBeWritten != null) {
                    getDataAdapterList().resumeNormalListeners();
                }
                fireCollector.done();
            }
        }
    }
    w.endArray();
}
Also used : FireCollector(com.servoy.j2db.dataprocessing.FireCollector)

Aggregations

FireCollector (com.servoy.j2db.dataprocessing.FireCollector)2 BasicFormController (com.servoy.j2db.BasicFormController)1