Search in sources :

Example 1 with IRecordInternal

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

the class RecordPropertyType method fromJSON.

@Override
public IRecordInternal fromJSON(Object newJSONValue, IRecordInternal previousSabloValue, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
    IRecordInternal record = null;
    if (newJSONValue instanceof JSONObject) {
        JSONObject jsonRecord = (JSONObject) newJSONValue;
        BaseWebObject webObject = dataConverterContext.getWebObject();
        if (webObject != null && jsonRecord.has(FoundsetTypeSabloValue.ROW_ID_COL_KEY)) {
            String rowIDValue = jsonRecord.optString(FoundsetTypeSabloValue.ROW_ID_COL_KEY);
            Pair<String, Integer> splitHashAndIndex = FoundsetTypeSabloValue.splitPKHashAndIndex(rowIDValue);
            if (jsonRecord.has(FoundsetTypeSabloValue.FOUNDSET_ID)) {
                int foundsetID = Utils.getAsInteger(jsonRecord.get(FoundsetTypeSabloValue.FOUNDSET_ID));
                if (foundsetID >= 0 && webObject instanceof IContextProvider) {
                    IFoundSetInternal foundset = ((IContextProvider) webObject).getDataConverterContext().getApplication().getFoundSetManager().findFoundset(foundsetID);
                    if (foundset != null) {
                        int recordIndex = foundset.getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
                        if (recordIndex != -1) {
                            return foundset.getRecord(recordIndex);
                        }
                    }
                }
            }
            Collection<PropertyDescription> properties = webObject.getSpecification().getProperties(FoundsetPropertyType.INSTANCE);
            for (PropertyDescription foundsetPd : properties) {
                FoundsetTypeSabloValue fsSablo = (FoundsetTypeSabloValue) webObject.getProperty(foundsetPd.getName());
                int recordIndex = fsSablo.getFoundset().getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
                if (recordIndex != -1) {
                    record = fsSablo.getFoundset().getRecord(recordIndex);
                    break;
                }
            }
        }
        if (// $NON-NLS-1$
        record == null && jsonRecord.has("recordhash")) {
            // $NON-NLS-1$
            record = getReference(jsonRecord.optString("recordhash"));
        }
    }
    return record;
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) JSONObject(org.json.JSONObject) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) BaseWebObject(org.sablo.BaseWebObject)

Example 2 with IRecordInternal

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

the class ViewportRowDataProvider method writeRowData.

protected void writeRowData(int foundsetIndex, Set<String> columnNames, IFoundSetInternal foundset, JSONWriter w, DataConversion clientConversionInfo) throws JSONException {
    // write viewport row contents
    IRecordInternal record = foundset.getRecord(foundsetIndex);
    populateRowData(record, columnNames, w, clientConversionInfo, shouldGenerateRowIds() ? record.getPKHashKey() + "_" + foundsetIndex : null);
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal)

Example 3 with IRecordInternal

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

the class DataproviderTypeSabloValue method getRelatedRecords.

private ArrayList<IRecordInternal> getRelatedRecords(IRecordInternal record, String relName) {
    // similar code as the loop below is also in class DisplaysAdapter - just in case future fixes need to apply to both places
    ArrayList<IRecordInternal> returnRelatedRecords = new ArrayList<IRecordInternal>();
    if (record != null) {
        // get the new records were are depending on
        IRecordInternal currRecord = record;
        // $NON-NLS-1$
        String[] parts = relName.split("\\.");
        for (int i = 0; currRecord != null && i < parts.length; i++) {
            Object v = currRecord.getValue(parts[i]);
            if (v instanceof ISwingFoundSet) {
                currRecord = ((ISwingFoundSet) v).getRecord(((ISwingFoundSet) v).getSelectedIndex());
                if (currRecord == null)
                    currRecord = ((ISwingFoundSet) v).getPrototypeState();
                returnRelatedRecords.add(currRecord);
            } else {
                currRecord = null;
            }
        }
    }
    return returnRelatedRecords;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ArrayList(java.util.ArrayList) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 4 with IRecordInternal

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

the class FormController method refreshAllPartRenderers.

@Override
protected void refreshAllPartRenderers(IRecordInternal[] records) {
    if (!isFormVisible || application.isShutDown())
        return;
    // don't do anything yet when there are records but the selection is invalid
    if (formModel.getSize() > 0 && (formModel.getSelectedIndex() < 0 || formModel.getSelectedIndex() >= formModel.getSize()))
        return;
    // let the ui know that it will be touched, so that locks can be taken if needed.
    getFormUI().touch();
    boolean executeOnRecordSelect = false;
    IRecordInternal[] state = records;
    if (state == null) {
        if (formModel != null) {
            state = new IRecordInternal[] { formModel.getPrototypeState() };
        } else {
            state = new IRecordInternal[] { new PrototypeState(null) };
        }
    }
    if (dataRenderers[FORM_EDITOR] != null && !(records == null && formModel != null && formModel.getRawSize() > 0) && isStateChanged(state)) {
        lastState = state;
        executeOnRecordSelect = true;
    }
    for (int i = FORM_RENDERER + 1; i < dataRenderers.length; i++) {
        IDataRenderer dataRenderer = dataRenderers[i];
        if (dataRenderer != null) {
            for (IRecordInternal r : state) dataRenderer.refreshRecord(r);
        }
    }
    if (executeOnRecordSelect) {
        // do this at the end because dataRenderer.refreshRecord(state) will update selection
        // for related tabs - and we should execute js code after they have been updated
        executeOnRecordSelect();
    }
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 5 with IRecordInternal

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

the class BasicFormController method setModel.

protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
    if (newModel == formModel || adjustingModel) {
        // same or adjusting do nothing
        return true;
    }
    ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
    if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
        throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
        newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
        form.getTableName() }));
    }
    try {
        IView view = getViewComponent();
        if (view != null && view.isEditing()) {
            // TODO if save fails don't set the newModel??
            int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
            if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
                return false;
            }
        }
        adjustingModel = true;
        if (formModel != null) {
            try {
                ((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
                ((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
                ((ISwingFoundSet) formModel).removeTableModelListener(this);
                // to make sure all data is gc'ed
                if (formModel instanceof FoundSet)
                    ((FoundSet) formModel).flushAllCachedItems();
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
        setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
        if (formScope != null) {
            // $NON-NLS-1$
            formScope.putWithoutFireChange("foundset", formModel);
            if (formScope.getPrototype() == null) {
                formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
            }
        }
        if (isFormVisible) {
            ((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
            ((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
            ((ISwingFoundSet) formModel).addTableModelListener(this);
            if (// it may not yet exist
            view != null) {
                view.setModel(formModel);
            }
            // this was former a call to aggregateChange, but now does now unwanted parent traverse...
            int[] idx = null;
            if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
                int selIdx = formModel.getSelectedIndex();
                if (selIdx != -1)
                    idx = new int[] { selIdx };
            } else {
                idx = formModel.getSelectedIndexes();
            }
            if (idx == null || idx.length == 0) {
                refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
            } else {
                IRecordInternal[] row = new IRecordInternal[idx.length];
                for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
                refreshAllPartRenderers(row);
            }
        }
    } finally {
        adjustingModel = false;
    }
    return true;
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ViewFoundSet(com.servoy.j2db.dataprocessing.ViewFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SelectedRecordScope(com.servoy.j2db.scripting.SelectedRecordScope) ITable(com.servoy.j2db.persistence.ITable) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject)

Aggregations

IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)63 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)26 Point (java.awt.Point)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 FormController (com.servoy.j2db.FormController)9 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)7 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)7 RepositoryException (com.servoy.j2db.persistence.RepositoryException)7 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 ServoyException (com.servoy.j2db.util.ServoyException)7 JSONObject (org.json.JSONObject)7 IComponent (com.servoy.j2db.ui.IComponent)6 ArrayList (java.util.ArrayList)6 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)5 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 JComponent (javax.swing.JComponent)5 Component (org.apache.wicket.Component)5 ApplicationException (com.servoy.j2db.ApplicationException)4