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;
}
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;
}
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;
}
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);
}
}
}
}
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);
}
Aggregations