Search in sources :

Example 1 with TargetDataLinks

use of com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks in project servoy-client by Servoy.

the class ValueListTypeSabloValue method initializeIfPossibleAndNeeded.

private void initializeIfPossibleAndNeeded() {
    // some dependent property has changed
    // get the new values
    String newDataproviderID = null;
    String newFormatString = null;
    FoundsetTypeSabloValue newFoundsetPropertySabloValue = null;
    ITable newFoundsetPropertyTable = null;
    if (propertyDependencies.foundsetPropertyName != null) {
        newFoundsetPropertySabloValue = (FoundsetTypeSabloValue) webObjectContext.getProperty(propertyDependencies.foundsetPropertyName);
        if (newFoundsetPropertySabloValue != null) {
            // this won't add it twice if it's already added (see javadoc of this call)
            newFoundsetPropertySabloValue.addStateChangeListener(this);
            if (newFoundsetPropertySabloValue.getFoundset() != null) {
                newFoundsetPropertyTable = newFoundsetPropertySabloValue.getFoundset().getTable();
            } else {
                newFoundsetPropertyTable = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(newFoundsetPropertySabloValue.getFoundsetSelector(), dataAdapterListToUse.getApplication(), ((IContextProvider) webObjectContext.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
            }
        }
    }
    if (propertyDependencies.formatPropertyName != null) {
        FormatTypeSabloValue formatSabloValue = ((FormatTypeSabloValue) webObjectContext.getProperty(propertyDependencies.formatPropertyName));
        ComponentFormat componentFormat = (formatSabloValue != null ? formatSabloValue.getComponentFormat() : null);
        newFormatString = ((componentFormat != null && componentFormat.parsedFormat != null) ? componentFormat.parsedFormat.getFormatString() : null);
        // this won't add it twice if it's already added (see javadoc of this call)
        if (formatSabloValue != null)
            formatSabloValue.addStateChangeListener(this);
    }
    if (propertyDependencies.dataproviderPropertyName != null) {
        Object dataproviderValue = webObjectContext.getProperty(propertyDependencies.dataproviderPropertyName);
        if (// if it's foundset linked; otherwise this will be false
        dataproviderValue instanceof IHasUnderlyingState) {
            // this won't add it twice if it's already added (see javadoc of this call)
            ((IHasUnderlyingState) dataproviderValue).addStateChangeListener(this);
        }
        // this will only return non-null if dataproviderValue != null && it is initialized (so foundset is already operational)
        newDataproviderID = DataAdapterList.getDataProviderID(dataproviderValue);
    }
    // see if anything we are interested in changed, of if it's not yet initialized (a detach + attach could happen where everything is still equal, but the detach did clear the vl/format and set initialized to false; for example a table column remove and then add back)
    if (!Utils.stringSafeEquals(newDataproviderID, dataproviderID) || !Utils.stringSafeEquals(newFormatString, formatParsedString) || newFoundsetPropertySabloValue != foundsetPropertySabloValue || !Utils.safeEquals(foundsetPropertyTable, newFoundsetPropertyTable) || !initialized) {
        // so something did change
        dataproviderID = newDataproviderID;
        foundsetPropertySabloValue = newFoundsetPropertySabloValue;
        foundsetPropertyTable = newFoundsetPropertyTable;
        formatParsedString = newFormatString;
        if ((!waitForDataproviderIfNull || dataproviderID != null) && (!waitForFormatIfNull || newFormatString != null) && (propertyDependencies.foundsetPropertyName == null || (newFoundsetPropertySabloValue != null && newFoundsetPropertyTable != null))) {
            // see if all we need is here
            // we don't have a "waitForFoundsetIfNull" because if we really have a foundset-linked-dataprovider, then that one is not initialized until the foundset != null anyway; so we won't get to this place becauuse the dataprovider property would not be ready
            // in case we previously already had an operational valuelist, clear it up as we have new dependency values
            clearUpRuntimeValuelistAndFormat();
            // initialize now
            initializeValuelistAndFormat();
            if (valueList != null) {
                valueList.addListDataListener(this);
                // register data link and find mode listeners as needed
                TargetDataLinks dataLinks = getDataLinks();
                dataAdapterListToUse.addDataLinkedProperty(this, dataLinks);
                // reset the initial wait for flags as we have the initial value; any other change in dependent properties has to be treated right away without additional waiting (even if they change to null)
                waitForDataproviderIfNull = false;
                waitForFormatIfNull = false;
                initialized = true;
            } else {
                Debug.error("Cannot instantiate valuelist (does it exist in the solution?) '" + valuelistIdentifier + "' for property " + vlPD + " of " + webObjectContext, new RuntimeException());
                clearUpRuntimeValuelistAndFormat();
            }
            changeMonitor.markFullyChanged(true);
        } else if (initialized) {
            // so we don't have yet all we need
            // make sure value is cleared/uninitialized (just in case something became unavailable that was available before)
            clearUpRuntimeValuelistAndFormat();
            changeMonitor.markFullyChanged(true);
        }
    }
}
Also used : FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) ITable(com.servoy.j2db.persistence.ITable) JSONObject(org.json.JSONObject) TargetDataLinks(com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks) ComponentFormat(com.servoy.j2db.component.ComponentFormat) IHasUnderlyingState(com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)

Example 2 with TargetDataLinks

use of com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks in project servoy-client by Servoy.

the class FoundsetTypeSabloValue method attachToBaseObject.

@Override
public void attachToBaseObject(IChangeListener changeNotifier, IWebObjectContext webObjectCntxt) {
    this.webObjectContext = webObjectCntxt;
    dataAdapterList = null;
    changeMonitor.setChangeNotifier(changeNotifier);
    // get the foundset identifier, then the foundset itself
    // foundset: {
    // foundsetSelector: 'string',
    // dataProviders: 'dataprovider[]'
    // }
    updateFoundset((IRecordInternal) null);
    if (designJSONValue != null) {
        JSONObject designValue = (JSONObject) designJSONValue;
        JSONObject dataProvidersJSON = designValue.optJSONObject(FoundsetPropertyType.DATAPROVIDERS_KEY_FOR_DESIGN);
        if (dataProvidersJSON != null) {
            changeMonitor.dataProvidersChanged();
        }
    }
    // register parent record changed listener
    if (parentDAL != null) {
        TargetDataLinks dataLinks = TargetDataLinks.LINKED_TO_ALL;
        if (foundsetSelector != null && !FORM_FOUNDSET_SELECTOR.equals(foundsetSelector) && !DataSourceUtils.isDatasourceUri(foundsetSelector)) {
            // it is a relation then, not a datasource (separate or named foundset)
            int lastIndex = foundsetSelector.lastIndexOf('.');
            if (lastIndex > 0) {
                // if this is a nested relation the parent dal needs to know this. so it can monitor the parent relations.
                Relation[] relations = getApplication().getFlattenedSolution().getRelationSequence(foundsetSelector.substring(0, lastIndex));
                if (relations != null && relations.length > 0) {
                    dataLinks = new TargetDataLinks(null, true, relations);
                }
            }
        }
        parentDAL.addDataLinkedProperty(this, dataLinks);
    }
    // we now have a webObjectContext so getDataAdapterList() might return non-null now; in some cases this is all other properties need, they don't need the foundset itself
    fireUnderlyingStateChangedListeners();
}
Also used : Relation(com.servoy.j2db.persistence.Relation) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) TargetDataLinks(com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks)

Example 3 with TargetDataLinks

use of com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks in project servoy-client by Servoy.

the class ComponentPropertyType method findRecordAwareRootProperties.

protected RecordBasedProperties findRecordAwareRootProperties(FormElement formElement, FlattenedSolution flattenedSolution) {
    RecordBasedProperties m = new RecordBasedProperties();
    // tagstrings, valuelists, tab seq, ... must be implemented separately and provided as a
    // viewport containing these values as part of 'components' property
    Set<Entry<String, PropertyDescription>> propertyDescriptors = formElement.getWebComponentSpec().getProperties().entrySet();
    for (Entry<String, PropertyDescription> propertyDescriptorEntry : propertyDescriptors) {
        PropertyDescription pd = propertyDescriptorEntry.getValue();
        IPropertyType<?> type = pd.getType();
        if (type instanceof IDataLinkedType) {
            // as these are root-level component properties, their TargetDataLinks will always be cached (only array element values are not cached)
            TargetDataLinks dataLinks = ((IDataLinkedType) type).getDataLinks(formElement.getPropertyValue(pd.getName()), propertyDescriptorEntry.getValue(), flattenedSolution, formElement);
            if (dataLinks != TargetDataLinks.NOT_LINKED_TO_DATA && dataLinks.recordLinked) {
                m.addRecordBasedProperty(propertyDescriptorEntry.getKey(), dataLinks.dataProviderIDs, null);
            }
        }
    }
    return m;
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) Entry(java.util.Map.Entry) IDataLinkedType(com.servoy.j2db.server.ngclient.property.types.IDataLinkedType) TargetDataLinks(com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks)

Aggregations

TargetDataLinks (com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks)3 JSONObject (org.json.JSONObject)2 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 ITable (com.servoy.j2db.persistence.ITable)1 Relation (com.servoy.j2db.persistence.Relation)1 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 FoundsetTypeSabloValue (com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue)1 IHasUnderlyingState (com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)1 IDataLinkedType (com.servoy.j2db.server.ngclient.property.types.IDataLinkedType)1 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1 Entry (java.util.Map.Entry)1 PropertyDescription (org.sablo.specification.PropertyDescription)1