Search in sources :

Example 1 with INGApplication

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

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

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

the class ValueListPropertyType method toSabloComponentValue.

@Override
public ValueListTypeSabloValue toSabloComponentValue(Object rhinoValue, ValueListTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext webObjectContext) {
    if (rhinoValue == null || RhinoConversion.isUndefinedOrNotFound(rhinoValue))
        return null;
    if (previousComponentValue == null) {
        return rhinoValue instanceof String ? createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext) : null;
    }
    if (!previousComponentValue.isInitialized()) {
        if (rhinoValue instanceof String) {
            // weird; but we are going to create a new value anyway so it doesn't matter much
            return createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
        } else {
            // we cannot set values from a dataset if the previous value is not ready for it
            Debug.error("Trying to make changes (assignment) to an uninitialized valuelist property (this is not allowed): " + pd + " of " + webObjectContext, new RuntimeException());
            return previousComponentValue;
        }
    }
    ParsedFormat format = null;
    int type = -1;
    IValueList list = previousComponentValue.getValueList();
    if (list.getName().equals(rhinoValue)) {
        // no need to create a new value if we have the same valuelist name
        return previousComponentValue;
    }
    ValueListTypeSabloValue newValue;
    IValueList newVl = null;
    // see if it's a component.setValuelistItems (legacy) equivalent
    if (list != null && list instanceof CustomValueList && (rhinoValue instanceof JSDataSet || rhinoValue instanceof IDataSet)) {
        // here we create a NEW, separate (runtime) custom valuelist instance for this component only (no longer the 'global' custom valuelist with that name that can be affected by application.setValuelistItems(...))
        INGApplication application = previousComponentValue.getDataAdapterList().getApplication();
        ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
        if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
            format = ((CustomValueList) list).getFormat();
            type = ((CustomValueList) list).getValueType();
            newVl = ValueListFactory.fillRealValueList(application, valuelist, IValueListConstants.CUSTOM_VALUES, format, type, rhinoValue);
            if (newVl != null) {
                previousComponentValue.setNewCustomValuelistInstance(newVl, rhinoValue);
                newValue = previousComponentValue;
            } else {
                // should never happen; ValueListFactory.fillRealValueList seems to always return non-null
                Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed for an unknown reason; dataset: " + rhinoValue, new RuntimeException());
                // just keep old value
                newValue = previousComponentValue;
            }
        } else {
            Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning a dataset is ONLY allowed for custom valuelists; dataset: " + rhinoValue, new RuntimeException());
            newValue = previousComponentValue;
        }
    } else if (rhinoValue instanceof String) {
        // the Rhino value is a different valuelist name; create a full new one
        newValue = createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
    } else {
        Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning this value is not supported: " + rhinoValue, new RuntimeException());
        // whatever was set here is not supported; so keep the previous value
        newValue = previousComponentValue;
    }
    return newValue;
}
Also used : ParsedFormat(com.servoy.j2db.util.FormatParser.ParsedFormat) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) ValueList(com.servoy.j2db.persistence.ValueList) JSValueList(com.servoy.j2db.scripting.solutionmodel.JSValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 4 with INGApplication

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

the class ValueListTypeSabloValue method initializeValuelistAndFormat.

private void initializeValuelistAndFormat() {
    INGApplication application = dataAdapterListToUse.getApplication();
    ValueList valuelistPersist = getValuelistPersist(valuelistIdentifier, application);
    format = getComponentFormat(vlPD, dataAdapterListToUse, getConfig(), dataproviderID, webObjectContext);
    if (valuelistPersist != null) {
        valueList = getRealValueList(application, valuelistPersist, format, dataproviderID);
        if (customValueListDataSet != null && valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
            valueList = ValueListFactory.fillRealValueList(application, valuelistPersist, IValueListConstants.CUSTOM_VALUES, ((CustomValueList) valueList).getFormat(), ((CustomValueList) valueList).getValueType(), customValueListDataSet);
        }
    } else {
        if ("autoVL".equals(getConfig().getDefaultValue())) {
            ITable table = getTableForDp();
            if (dataproviderID != null && table != null && table.getColumnType(dataproviderID) != 0) {
                valueList = new ColumnBasedValueList(application, table.getServerName(), table.getName(), dataproviderID);
            } else {
                // not supported empty valuelist (based on relations) just return an empty valuelist
                valueList = new CustomValueList(application, null, "", false, IColumnTypes.TEXT, null);
            }
        }
    }
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) ColumnBasedValueList(com.servoy.j2db.server.ngclient.ColumnBasedValueList) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) ValueList(com.servoy.j2db.persistence.ValueList) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList) ColumnBasedValueList(com.servoy.j2db.server.ngclient.ColumnBasedValueList) DBValueList(com.servoy.j2db.dataprocessing.DBValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ITable(com.servoy.j2db.persistence.ITable)

Example 5 with INGApplication

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

the class ClientFunctionPropertyType method toJSON.

@Override
public JSONWriter toJSON(JSONWriter writer, String key, BasicTagStringTypeSabloValue object, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    if (object != null) {
        INGApplication application = object.getDataAdapterList().getApplication();
        if (application.getRuntimeProperties().containsKey("NG2")) {
            clientConversion.convert("clientfunction");
            JSONUtils.addKeyIfPresent(writer, key);
            String uuid = application.registerClientFunction(object.getTagReplacedValue());
            writer.value(uuid);
            return writer;
        }
    }
    return super.toJSON(writer, key, object, pd, clientConversion, dataConverterContext);
}
Also used : INGApplication(com.servoy.j2db.server.ngclient.INGApplication)

Aggregations

INGApplication (com.servoy.j2db.server.ngclient.INGApplication)9 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 ITable (com.servoy.j2db.persistence.ITable)3 ValueList (com.servoy.j2db.persistence.ValueList)3 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)2 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)2 Form (com.servoy.j2db.persistence.Form)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)2 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 FoundsetLinkedConfig (com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig)2 JSONException (org.json.JSONException)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 DBValueList (com.servoy.j2db.dataprocessing.DBValueList)1 FindState (com.servoy.j2db.dataprocessing.FindState)1 FoundSetEvent (com.servoy.j2db.dataprocessing.FoundSetEvent)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1