Search in sources :

Example 51 with IRecordInternal

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

the class SessionClient method getDataProviderValue.

public synchronized Object getDataProviderValue(String contextName, String dataProviderID) {
    if (dataProviderID == null)
        return null;
    IServiceProvider prev = testThreadLocals();
    try {
        Object value = null;
        if (ScopesUtils.isVariableScope(dataProviderID)) {
            value = getScriptEngine().getSolutionScope().getScopesScope().get(null, dataProviderID);
        } else {
            Pair<IRecordInternal, FormScope> p = getContext(contextName);
            if (p != null) {
                FormScope fs = p.getRight();
                IRecordInternal record = p.getLeft();
                if (// how can fs be null.
                fs != null && fs.has(dataProviderID, fs)) {
                    value = fs.get(dataProviderID);
                } else if (record != null) {
                    value = record.getValue(dataProviderID);
                }
                // $NON-NLS-1$
                if (value == Scriptable.NOT_FOUND)
                    value = "";
            }
        }
        return value;
    } finally {
        unsetThreadLocals(prev);
    }
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FormScope(com.servoy.j2db.scripting.FormScope)

Example 52 with IRecordInternal

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

the class SessionClient method setDataProviderValues.

public synchronized int setDataProviderValues(String contextName, HttpServletRequest request_data) {
    int retval = 0;
    if (request_data.getCharacterEncoding() == null) {
        try {
            request_data.setCharacterEncoding(wicket_app.getRequestCycleSettings().getResponseRequestEncoding());
        } catch (UnsupportedEncodingException e) {
            Debug.log(e);
        }
    }
    IServiceProvider prev = testThreadLocals();
    try {
        Pair<IRecordInternal, FormScope> p = getContext(contextName);
        Enumeration<?> e = request_data.getParameterNames();
        while (e.hasMoreElements()) {
            String param = (String) e.nextElement();
            Object val = request_data.getParameter(param);
            Object oldVal = setDataProviderValue(p, param, val);
            if (!(Utils.equalObjects(oldVal, val)))
                retval++;
        }
        return retval;
    } finally {
        unsetThreadLocals(prev);
    }
}
Also used : IServiceProvider(com.servoy.j2db.IServiceProvider) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FormScope(com.servoy.j2db.scripting.FormScope)

Example 53 with IRecordInternal

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

the class RecordItemModel method setValue.

/**
 * @param obj
 * @param dataProviderID
 * @param prevValue
 */
public void setValue(Component component, String dataProviderID, Object value) {
    Object obj = value;
    String compDpid = getDataProviderID(component);
    boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
    Object prevValue = null;
    if (ownComponentsValue && component instanceof IResolveObject) {
        obj = ((IResolveObject) component).resolveRealValue(obj);
    }
    if (component instanceof IDisplayData) {
        obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
    }
    WebForm webForm = component.findParent(WebForm.class);
    IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
    // use UI converter to convert from UI value to record value
    if (!(record instanceof FindState)) {
        obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
    }
    FormScope fs = webForm.getController().getFormScope();
    try {
        Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
        if (scope.getLeft() != null) {
            if (record == null) {
                webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
            } else {
                // does an additional fire in foundset!
                prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
            }
        } else if (fs.has(dataProviderID, fs)) {
            prevValue = fs.get(dataProviderID);
            fs.put(dataProviderID, obj);
        } else {
            if (record != null && record.startEditing()) {
                try {
                    prevValue = record.getValue(dataProviderID);
                    record.setValue(dataProviderID, obj);
                } catch (IllegalArgumentException e) {
                    Debug.trace(e);
                    ((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                    Object stateValue = record.getValue(dataProviderID);
                    if (!Utils.equalObjects(prevValue, stateValue)) {
                        // reset display to changed value in validator method
                        obj = stateValue;
                    }
                    if (ownComponentsValue) {
                        ((IDisplayData) component).setValueValid(false, prevValue);
                    }
                    return;
                }
                if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
                }
            }
        }
        // then dont call notify
        if (ownComponentsValue) {
            ((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
        }
    } finally {
        // then touch the lastInvalidValue
        if (ownComponentsValue) {
            if (((IDisplayData) component).isValueValid()) {
                lastInvalidValue = NONE;
            } else {
                lastInvalidValue = obj;
            }
        }
    }
    return;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) FormScope(com.servoy.j2db.scripting.FormScope) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 54 with IRecordInternal

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

the class DataproviderTypeSabloValue method detach.

@Override
public void detach() {
    // unregister listeners
    dataAdapterList.removeDataLinkedProperty(this);
    dataAdapterList.removeFindModeAwareProperty(this);
    if (globalRelatedFoundset != null) {
        globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
    }
    globalRelatedFoundset = null;
    globalRelatedFoundsetListener = null;
    if (relatedFoundsets.size() > 0 && relatedRecordModificationListener != null) {
        // just remove it, no need to test this because a remove will be just a NOP when it was not registered anyway.
        relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
    }
    for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
        ((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
    }
    relatedFoundsets = Collections.emptyList();
    if (relatedRecordModificationListener != null) {
        for (IRecordInternal relatedRecord : relatedRecords) {
            relatedRecord.removeModificationListener(relatedRecordModificationListener);
        }
    }
    relatedRecords = Collections.emptyList();
    webObjectContext = null;
    changeMonitor = null;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal)

Example 55 with IRecordInternal

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

the class DataproviderTypeSabloValue method dataProviderOrRecordChanged.

@Override
public void dataProviderOrRecordChanged(final IRecordInternal record, final String dataProvider, final boolean isFormDP, final boolean isGlobalDP, boolean fireChangeEvent) {
    // TODO can type or fieldFormat change, for example in scripting the format is reset (but type shouldn't really change)
    IDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null);
    Collection<PropertyDescription> properties = webObjectContext.getProperties(TypesRegistry.getType(FormatPropertyType.TYPE_NAME));
    FormatTypeSabloValue formatSabloValue = null;
    for (PropertyDescription formatPd : properties) {
        // see whether format if "for" this property (dataprovider)
        Object formatConfig = formatPd.getConfig();
        if (formatConfig instanceof String[] && Arrays.asList((String[]) formatConfig).indexOf(dpPD.getName()) != -1) {
            INGApplication application = servoyDataConverterContext.getApplication();
            formatSabloValue = (FormatTypeSabloValue) webObjectContext.getProperty(formatPd.getName());
            if (formatSabloValue != null) {
                if (formatSabloValue.getFormatDesignValue() != null) {
                    fieldFormat = ComponentFormat.getComponentFormat(formatSabloValue.getFormatDesignValue(), dataProviderID, dpLookup, application);
                }
                break;
            }
        }
    }
    if (fieldFormat != null) {
        typeOfDP = NGUtils.getDataProviderPropertyDescription(fieldFormat.uiType, getDataProviderConfig().hasParseHtml(), fieldFormat.parsedFormat.useLocalDateTime());
        if (record instanceof FindState) {
            ((FindState) record).setFormat(dataProviderID, fieldFormat.parsedFormat);
        }
    } else {
        // see type of dataprovider; this is done only once - first time we get a new record
        typeOfDP = NGUtils.getDataProviderPropertyDescription(dataProviderID, servoyDataConverterContext.getApplication(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null, getDataProviderConfig().hasParseHtml(), formatSabloValue != null ? formatSabloValue.getComponentFormat().parsedFormat.useLocalDateTime() : false);
    }
    if (dpPD.hasTag(TAG_TYPE_NAME)) {
        IPropertyType<?> specType = TypesRegistry.getType((String) dpPD.getTag(TAG_TYPE_NAME));
        if (specType != null && (typeOfDP == null || !specType.getClass().isAssignableFrom(typeOfDP.getClass()))) {
            typeOfDP = new PropertyDescriptionBuilder().withName("Spec type hint").withType(specType).build();
        }
    }
    String dpID = dataProviderID;
    IDataProvider dp = null;
    if (dpLookup != null) {
        try {
            dp = dpLookup.getDataProvider(dataProviderID);
            if (dp != null) {
                dpID = dp.getDataProviderID();
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    if (globalRelationName != null) {
        try {
            IFoundSetInternal newRelatedFoundset = servoyDataConverterContext.getApplication().getFoundSetManager().getGlobalRelatedFoundSet(globalRelationName);
            if (newRelatedFoundset != globalRelatedFoundset) {
                if (globalRelatedFoundsetListener == null) {
                    globalRelatedFoundsetListener = new IFoundSetEventListener() {

                        @Override
                        public void foundSetChanged(FoundSetEvent e) {
                            if (e.getType() == FoundSetEvent.CONTENTS_CHANGED) {
                                dataProviderOrRecordChanged(DataproviderTypeSabloValue.this.dataAdapterList.getRecord(), null, false, false, true);
                            }
                        }
                    };
                } else if (globalRelatedFoundset != null) {
                    globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
                }
                globalRelatedFoundset = newRelatedFoundset;
                globalRelatedFoundset.addFoundSetEventListener(globalRelatedFoundsetListener);
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedFoundsetSelectionListener != null) {
        try {
            ArrayList<IFoundSetInternal> newRelatedFoundsets = getRelatedFoundsets(record, relationName);
            boolean equals = testByReference(newRelatedFoundsets, this.relatedFoundsets);
            if (!equals) {
                IDataProvider column = dp;
                if (column instanceof ColumnWrapper) {
                    column = ((ColumnWrapper) column).getColumn();
                }
                boolean isAggregate = (column instanceof IColumn) ? ((IColumn) column).isAggregate() : false;
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
                }
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
                }
                relatedFoundsets = newRelatedFoundsets;
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().addListSelectionListener(relatedFoundsetSelectionListener);
                }
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).addAggregateModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedRecordModificationListener != null) {
        try {
            ArrayList<IRecordInternal> newRelatedRecords = getRelatedRecords(record, relationName);
            boolean equals = testByReference(newRelatedRecords, this.relatedRecords);
            if (!equals) {
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.removeModificationListener(relatedRecordModificationListener);
                }
                relatedRecords = newRelatedRecords;
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.addModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    Object v = com.servoy.j2db.dataprocessing.DataAdapterList.getValueObject(record, servoyDataConverterContext.getForm().getFormScope(), dpID);
    if (v == Scriptable.NOT_FOUND)
        v = null;
    if (fieldFormat != null && !findMode) {
        // if it has an UI converter, transform it from the record/scope value into the UI value
        v = ComponentFormat.applyUIConverterToObject(v, dataProviderID, servoyDataConverterContext.getApplication().getFoundSetManager(), fieldFormat);
    }
    v = replaceTagsIfNeeded(v);
    boolean changed = ((v != uiValue) && (v == null || !v.equals(uiValue)));
    uiValue = v;
    if (changed) {
        jsonValue = null;
    }
    if (// if it is a foundset related DAL then always call valuechanged (the value can be of a previous row)
    fireChangeEvent && (changed || dataAdapterList instanceof FoundsetDataAdapterList)) {
        changeMonitor.valueChanged();
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) IDataProvider(com.servoy.j2db.persistence.IDataProvider) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) FindState(com.servoy.j2db.dataprocessing.FindState) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) FoundsetDataAdapterList(com.servoy.j2db.server.ngclient.property.FoundsetDataAdapterList) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) RepositoryException(com.servoy.j2db.persistence.RepositoryException) FoundSetEvent(com.servoy.j2db.dataprocessing.FoundSetEvent) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) PropertyDescription(org.sablo.specification.PropertyDescription) IColumn(com.servoy.j2db.persistence.IColumn) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup) IFoundSetEventListener(com.servoy.j2db.dataprocessing.IFoundSetEventListener)

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