Search in sources :

Example 1 with IHasUnderlyingState

use of com.servoy.j2db.server.ngclient.property.IHasUnderlyingState in project servoy-client by Servoy.

the class FormatTypeSabloValue method detach.

public void detach() {
    if (propertyDependencies.dataproviderPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.dataproviderPropertyName, this);
        Object dataproviderValue = webObjectContext.getProperty(propertyDependencies.dataproviderPropertyName);
        if (dataproviderValue instanceof IHasUnderlyingState)
            ((IHasUnderlyingState) dataproviderValue).removeStateChangeListener(this);
    }
    if (propertyDependencies.valueListPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.valueListPropertyName, this);
        if (valuelistContentChangeListener != null) {
            IHasUnderlyingState valuelistSabloValue = (IHasUnderlyingState) webObjectContext.getProperty(propertyDependencies.valueListPropertyName);
            if (valuelistSabloValue != null) {
                valuelistSabloValue.removeStateChangeListener(valuelistContentChangeListener);
            }
        }
    }
    if (propertyDependencies.foundsetPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.foundsetPropertyName, this);
    }
    this.changeMonitor = null;
    webObjectContext = null;
    initialized = false;
}
Also used : IHasUnderlyingState(com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)

Example 2 with IHasUnderlyingState

use of com.servoy.j2db.server.ngclient.property.IHasUnderlyingState 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 3 with IHasUnderlyingState

use of com.servoy.j2db.server.ngclient.property.IHasUnderlyingState in project servoy-client by Servoy.

the class ValueListTypeSabloValue method detach.

@Override
public void detach() {
    clearUpRuntimeValuelistAndFormat();
    customValueListDataSet = null;
    if (propertyDependencies.dataproviderPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.dataproviderPropertyName, this);
        Object dataproviderValue = webObjectContext.getProperty(propertyDependencies.dataproviderPropertyName);
        if (dataproviderValue instanceof IHasUnderlyingState)
            ((IHasUnderlyingState) dataproviderValue).removeStateChangeListener(this);
    }
    if (propertyDependencies.foundsetPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.foundsetPropertyName, this);
        Object foundsetValue = webObjectContext.getProperty(propertyDependencies.foundsetPropertyName);
        if (foundsetValue instanceof IHasUnderlyingState)
            ((IHasUnderlyingState) foundsetPropertySabloValue).removeStateChangeListener(this);
    }
    if (propertyDependencies.formatPropertyName != null) {
        webObjectContext.removePropertyChangeListener(propertyDependencies.formatPropertyName, this);
        Object formatPropertyValue = webObjectContext.getProperty(propertyDependencies.formatPropertyName);
        if (formatPropertyValue instanceof IHasUnderlyingState)
            ((IHasUnderlyingState) formatPropertyValue).removeStateChangeListener(this);
    }
    changeMonitor.setChangeNotifier(null);
    webObjectContext = null;
}
Also used : JSONObject(org.json.JSONObject) IHasUnderlyingState(com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)

Example 4 with IHasUnderlyingState

use of com.servoy.j2db.server.ngclient.property.IHasUnderlyingState in project servoy-client by Servoy.

the class FormatTypeSabloValue method initializeIfPossibleAndNeeded.

private void initializeIfPossibleAndNeeded() {
    // some dependent property has changed
    // get the new values
    String newDataproviderID = null;
    Object newValuelistID = null;
    String newFoundsetID = null;
    if (propertyDependencies.valueListPropertyName != null) {
        // valuelistSabloValue can be a ValuelistTypeSabloValue or FoundsetLinkedTypeSabloValue
        Object valuelistSabloValue = webObjectContext.getProperty(propertyDependencies.valueListPropertyName);
        if (valuelistSabloValue != null) {
            if (valuelistContentChangeListener == null) {
                valuelistContentChangeListener = new IChangeListener() {

                    @Override
                    public void valueChanged() {
                        if (!isValuelistFormatSet) {
                            componentFormat = null;
                            initializeIfPossibleAndNeeded();
                        }
                    }
                };
            }
            ((IHasUnderlyingState) valuelistSabloValue).addStateChangeListener(valuelistContentChangeListener);
            ValueListTypeSabloValue vlV = ((ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(valuelistSabloValue));
            if (vlV != null)
                newValuelistID = vlV.getValuelistIdentifier();
        }
    }
    if (propertyDependencies.dataproviderPropertyName != null) {
        Object dataproviderValue = webObjectContext.getProperty(propertyDependencies.dataproviderPropertyName);
        if (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);
    }
    if (propertyDependencies.foundsetPropertyName != null) {
        FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectContext.getProperty(propertyDependencies.foundsetPropertyName);
        if (runtimeValOfFoundset != null) {
            newFoundsetID = runtimeValOfFoundset.getFoundsetSelector();
            if (newFoundsetID == null && runtimeValOfFoundset.getFoundset() != null) {
                // set from Rhino (then foundsetSelector/ID is null); take the datasource from the foundset itself; datasources are valid "foundsetIDs/foundsetSelectors"
                newFoundsetID = runtimeValOfFoundset.getFoundset().getDataSource();
            }
        }
    }
    // it even if dataProvider or valueList are null (maybe they are really not set or not present)
    if (!Utils.stringSafeEquals(newDataproviderID, dataproviderID) || !Utils.safeEquals(valuelistID, newValuelistID) || !Utils.stringSafeEquals(newFoundsetID, foundsetID) || componentFormat == null) {
        // so something did change or we should do first initialization
        dataproviderID = newDataproviderID;
        valuelistID = newValuelistID;
        foundsetID = newFoundsetID;
        componentFormat = getSabloValue(formatDesignValue, dataproviderID, valuelistID, foundsetID, webObjectContext);
        if (changeMonitor != null)
            changeMonitor.valueChanged();
    }
    // then on attach we just need to mark it as 'initialized' again
    if (componentFormat != null)
        initialized = true;
}
Also used : IChangeListener(org.sablo.IChangeListener) FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) IHasUnderlyingState(com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)

Aggregations

IHasUnderlyingState (com.servoy.j2db.server.ngclient.property.IHasUnderlyingState)4 FoundsetTypeSabloValue (com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue)2 JSONObject (org.json.JSONObject)2 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 ITable (com.servoy.j2db.persistence.ITable)1 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 TargetDataLinks (com.servoy.j2db.server.ngclient.property.types.IDataLinkedType.TargetDataLinks)1 IChangeListener (org.sablo.IChangeListener)1