Search in sources :

Example 1 with IContextProvider

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

the class MediaPropertyType method wrap.

@Override
public MediaWrapper wrap(Object value, MediaWrapper previousValue, PropertyDescription propertyDescription, IWrappingContext dataConverterContext) {
    if (previousValue != null && Utils.equalObjects(value, previousValue.mediaUrl)) {
        return previousValue;
    }
    IServoyDataConverterContext servoyDataConverterContext = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext();
    FlattenedSolution flattenedSolution = servoyDataConverterContext.getSolution();
    INGApplication application = servoyDataConverterContext.getApplication();
    String url = getMediaUrl(value, flattenedSolution, application);
    if (url != null)
        return new MediaWrapper(value, url);
    if (value != null && !Utils.equalObjects(value, Integer.valueOf(0)))
        Debug.log("cannot convert media " + value + " using converter context " + servoyDataConverterContext);
    return null;
}
Also used : MediaWrapper(com.servoy.j2db.server.ngclient.property.types.MediaPropertyType.MediaWrapper) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IServoyDataConverterContext(com.servoy.j2db.server.ngclient.IServoyDataConverterContext)

Example 2 with IContextProvider

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

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

the class TagStringPropertyType method toSabloComponentValue.

@Override
public BasicTagStringTypeSabloValue toSabloComponentValue(Object rhinoValue, BasicTagStringTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext componentOrService) {
    if (rhinoValue != null && !RhinoConversion.isUndefinedOrNotFound(rhinoValue)) {
        // this code can interpret the new value as a static one or a a tag-aware one depending on the property's config: USE_PARSED_VALUE_IN_RHINO_CONFIG_OPT
        String newDesignValue = rhinoValue instanceof String ? (String) rhinoValue : rhinoValue.toString();
        DataAdapterList dal = previousComponentValue != null ? previousComponentValue.getDataAdapterList() : null;
        if (dal == null && componentOrService != null && componentOrService.getUnderlyingWebObject() instanceof WebFormComponent) {
            dal = (DataAdapterList) ((WebFormComponent) componentOrService.getUnderlyingWebObject()).getDataAdapterList();
        }
        return createNewTagStringTypeSabloValue(newDesignValue, dal, !((TagStringConfig) pd.getConfig()).useParsedValueInRhino(), true, pd, componentOrService.getUnderlyingWebObject() instanceof WebFormComponent ? ((WebFormComponent) componentOrService.getUnderlyingWebObject()) : null, ((IContextProvider) componentOrService.getUnderlyingWebObject()).getDataConverterContext().getApplication(), false);
    }
    return null;
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList)

Example 4 with IContextProvider

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

the class FormPropertyType method toRhinoValue.

@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext webObjectContext, Scriptable startScriptable) {
    if (webComponentValue instanceof Form) {
        return ((Form) webComponentValue).getName();
    } else {
        if (webComponentValue != null && webObjectContext != null && webObjectContext.getUnderlyingWebObject() instanceof IContextProvider) {
            // form is stored as uuid on disk
            FlattenedSolution solution = ((IContextProvider) webObjectContext.getUnderlyingWebObject()).getDataConverterContext().getSolution();
            Form form = solution.getForm(webComponentValue.toString());
            if (form == null) {
                form = (Form) solution.searchPersist(webComponentValue.toString());
            }
            if (form != null) {
                return form.getName();
            }
        }
    }
    return webComponentValue;
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 5 with IContextProvider

use of com.servoy.j2db.server.ngclient.IContextProvider 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)

Aggregations

IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)10 Form (com.servoy.j2db.persistence.Form)5 FlattenedSolution (com.servoy.j2db.FlattenedSolution)4 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)4 JSONObject (org.json.JSONObject)4 ITable (com.servoy.j2db.persistence.ITable)3 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)3 FoundsetTypeSabloValue (com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 ComponentFormat (com.servoy.j2db.component.ComponentFormat)2 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)2 FoundsetLinkedConfig (com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig)2 BaseWebObject (org.sablo.BaseWebObject)2 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)1 FormController (com.servoy.j2db.FormController)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1 Column (com.servoy.j2db.persistence.Column)1