Search in sources :

Example 1 with FoundsetLinkedPropertyType

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

the class TitleStringPropertyType method toSabloComponentDefaultValue.

/*
	 * (non-Javadoc)
	 *
	 * @see com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent#toSabloComponentDefaultValue(org.sablo.
	 * specification.PropertyDescription, com.servoy.j2db.server.ngclient.INGFormElement, com.servoy.j2db.server.ngclient.WebFormComponent,
	 * com.servoy.j2db.server.ngclient.DataAdapterList)
	 */
@Override
public BasicTagStringTypeSabloValue toSabloComponentDefaultValue(PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
    TitleStringConfig titleStringConfig = (TitleStringConfig) pd.getConfig();
    String forDataprovider = titleStringConfig.getForDataprovider();
    if (forDataprovider != null) {
        PropertyDescription forProperty = formElement.getPropertyDescription(forDataprovider);
        if (forProperty != null) {
            IPropertyType<?> type = forProperty.getType();
            if (type instanceof FoundsetLinkedPropertyType) {
                Object config = forProperty.getConfig();
                if (config instanceof FoundsetLinkedConfig && ((FoundsetLinkedConfig) config).getForFoundsetName() != null) {
                    String forFoundset = ((FoundsetLinkedConfig) config).getForFoundsetName();
                    String dataproviderID = (String) formElement.getPropertyValue(forDataprovider);
                    JSONObject foundsetValue = (JSONObject) formElement.getPropertyValue(forFoundset);
                    if (foundsetValue != null) {
                        String foundsetID = foundsetValue.optString(FoundsetPropertyType.FOUNDSET_SELECTOR);
                        INGApplication application = ((WebFormComponent) component.getUnderlyingWebObject()).getDataConverterContext().getApplication();
                        Form form = ((IContextProvider) component.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
                        ITable table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetID, application, form);
                        if (table != null) {
                            Column dataproviderColumn = table.getColumn(dataproviderID);
                            if (dataproviderColumn != null) {
                                return toSabloComponentValue(dataproviderColumn.getTitle(), pd, formElement, component, dataAdapterList);
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) PropertyDescription(org.sablo.specification.PropertyDescription) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) JSONObject(org.json.JSONObject) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) Column(com.servoy.j2db.persistence.Column) JSONObject(org.json.JSONObject) ITable(com.servoy.j2db.persistence.ITable) FoundsetLinkedPropertyType(com.servoy.j2db.server.ngclient.property.FoundsetLinkedPropertyType)

Example 2 with FoundsetLinkedPropertyType

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

the class ValueListPropertyType method getDependenciesToOtherProperties.

protected ValuelistPropertyDependencies getDependenciesToOtherProperties(PropertyDescription pd, IPropertyDescriptionProvider propertyDescriptionProvider) {
    ValueListConfig config = (ValueListConfig) pd.getConfig();
    String dataproviderPropertyName = config.getFor();
    String foundsetPropertyName = null;
    // this is really only used I think when you have a custom valuelist with date values (without separate display values) - to convert the String defined dates in the custom valuelist into actual Date values
    String formatPropertyName = null;
    boolean dataproviderResolveValuelist = false;
    if (dataproviderPropertyName != null) {
        PropertyDescription dpPropertyDef = propertyDescriptionProvider.getPropertyDescription(dataproviderPropertyName);
        Object dpConfig = null;
        if (dpPropertyDef != null) {
            dpConfig = dpPropertyDef.getConfig();
        }
        if (dpPropertyDef != null && (dpPropertyDef.getType() instanceof FoundsetLinkedPropertyType)) {
            foundsetPropertyName = ((FoundsetLinkedConfig) dpPropertyDef.getConfig()).getForFoundsetName();
            dpConfig = ((FoundsetLinkedConfig) dpPropertyDef.getConfig()).getWrappedPropertyDescription().getConfig();
        }
        if (dpConfig instanceof DataproviderConfig && ((DataproviderConfig) dpConfig).shouldResolveValuelist()) {
            dataproviderResolveValuelist = true;
        }
    }
    Collection<PropertyDescription> properties = propertyDescriptionProvider.getProperties(FormatPropertyType.INSTANCE);
    for (PropertyDescription formatPd : properties) {
        // compare whether format and valueList property are for same property (dataprovider) or if format is used for valuelist property itself
        if (formatPd.getConfig() instanceof String[] && ((String[]) formatPd.getConfig()).length > 0) {
            for (String formatForClauseEntry : ((String[]) formatPd.getConfig())) {
                if (dataproviderPropertyName.equals(formatForClauseEntry) || pd.getName().equals(formatForClauseEntry)) {
                    formatPropertyName = formatPd.getName();
                    break;
                }
            }
            // there can/should be only one format property for a specific valuelist; we found it
            if (formatPropertyName != null)
                break;
        }
    }
    return new ValuelistPropertyDependencies(dataproviderPropertyName, foundsetPropertyName, formatPropertyName, dataproviderResolveValuelist);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) JSONObject(org.json.JSONObject) DataproviderConfig(com.servoy.j2db.server.ngclient.property.DataproviderConfig) FoundsetLinkedPropertyType(com.servoy.j2db.server.ngclient.property.FoundsetLinkedPropertyType) ValueListConfig(com.servoy.j2db.server.ngclient.property.ValueListConfig)

Aggregations

FoundsetLinkedConfig (com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig)2 FoundsetLinkedPropertyType (com.servoy.j2db.server.ngclient.property.FoundsetLinkedPropertyType)2 JSONObject (org.json.JSONObject)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 Column (com.servoy.j2db.persistence.Column)1 Form (com.servoy.j2db.persistence.Form)1 ITable (com.servoy.j2db.persistence.ITable)1 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)1 DataproviderConfig (com.servoy.j2db.server.ngclient.property.DataproviderConfig)1 ValueListConfig (com.servoy.j2db.server.ngclient.property.ValueListConfig)1