use of com.servoy.j2db.server.ngclient.property.DataproviderConfig in project servoy-client by Servoy.
the class DataAdapterList method pushChanges.
public void pushChanges(WebFormComponent webComponent, String beanProperty, Object value, String foundsetLinkedRowID) {
// TODO should this all (svy-apply/push) move to DataProviderType client/server side implementation instead of these specialized calls, instanceof checks and string parsing (see getProperty or getPropertyDescription)?
String dataProviderID = getDataProviderID(webComponent, beanProperty);
if (dataProviderID == null) {
Debug.log("apply called on a property that is not bound to a dataprovider: " + beanProperty + ", value: " + value + " of component: " + webComponent);
return;
}
Object newValue = value;
// Check security
webComponent.checkPropertyProtection(beanProperty);
IRecordInternal editingRecord = record;
if (newValue instanceof FoundsetLinkedTypeSabloValue) {
if (foundsetLinkedRowID != null) {
// find the row of the foundset that changed; we can't use client's index (as server-side indexes might have changed meanwhile on server); so we are doing it based on client sent rowID
editingRecord = getFoundsetLinkedRecord((FoundsetLinkedTypeSabloValue<?, ?>) newValue, foundsetLinkedRowID);
if (editingRecord == null) {
Debug.error("Error pushing data from client to server for foundset linked DP (cannot find record): dp=" + newValue + ", rowID=" + foundsetLinkedRowID);
return;
}
}
// hmm, this is strange - usually we should always get rowID, even if foundset linked is actually set by developer to a global or form variable - even though there rowID is not actually needed; just treat this as if it is not record linked
newValue = ((FoundsetLinkedTypeSabloValue) newValue).getWrappedValue();
}
if (newValue instanceof DataproviderTypeSabloValue)
newValue = ((DataproviderTypeSabloValue) newValue).getValue();
if (editingRecord == null || editingRecord.startEditing() || editingRecord.getParentFoundSet().getColumnIndex(dataProviderID) == -1) {
Object v;
// will update property with "image_data", property_filename with "pic.jpg" and property_mimetype with "image/jpeg"
if (newValue instanceof HashMap) {
// defining value
v = ((HashMap<?, ?>) newValue).get("");
Iterator<Entry<?, ?>> newValueIte = ((HashMap) newValue).entrySet().iterator();
while (newValueIte.hasNext()) {
Entry<?, ?> e = newValueIte.next();
if (!"".equals(e.getKey())) {
try {
com.servoy.j2db.dataprocessing.DataAdapterList.setValueObject(editingRecord, formController.getFormScope(), dataProviderID + e.getKey(), e.getValue());
} catch (IllegalArgumentException ex) {
Debug.trace(ex);
getApplication().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, ex));
}
}
}
} else {
v = newValue;
}
Object oldValue = null;
Exception setValueException = null;
try {
oldValue = com.servoy.j2db.dataprocessing.DataAdapterList.setValueObject(editingRecord, formController.getFormScope(), dataProviderID, v);
if (value instanceof DataproviderTypeSabloValue)
((DataproviderTypeSabloValue) value).checkValueForChanges(editingRecord);
} catch (IllegalArgumentException e) {
Debug.trace(e);
getApplication().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
setValueException = e;
webComponent.setInvalidState(true);
}
DataproviderConfig dataproviderConfig = getDataproviderConfig(webComponent, beanProperty);
String onDataChange = dataproviderConfig.getOnDataChange();
if (onDataChange != null) {
JSONObject event = EventExecutor.createEvent(onDataChange, editingRecord.getParentFoundSet().getSelectedIndex());
event.put("data", createDataproviderInfo(editingRecord, formController.getFormScope(), dataProviderID));
Object returnValue = null;
Exception exception = null;
String onDataChangeCallback = null;
if (!Utils.equalObjects(oldValue, v) && setValueException == null && webComponent.hasEvent(onDataChange)) {
// $NON-NLS-1$ //$NON-NLS-2$
getApplication().getWebsocketSession().getClientService("$sabloLoadingIndicator").executeAsyncNowServiceCall("showLoading", null);
try {
returnValue = webComponent.executeEvent(onDataChange, new Object[] { oldValue, v, event });
} catch (Exception e) {
Debug.error("Error during onDataChange webComponent=" + webComponent, e);
exception = e;
} finally {
// $NON-NLS-1$ //$NON-NLS-2$
getApplication().getWebsocketSession().getClientService("$sabloLoadingIndicator").executeAsyncNowServiceCall("hideLoading", null);
}
onDataChangeCallback = dataproviderConfig.getOnDataChangeCallback();
} else if (setValueException != null) {
returnValue = setValueException.getMessage();
exception = setValueException;
onDataChangeCallback = dataproviderConfig.getOnDataChangeCallback();
} else if (webComponent.isInvalidState() && exception == null) {
onDataChangeCallback = dataproviderConfig.getOnDataChangeCallback();
webComponent.setInvalidState(false);
}
if (onDataChangeCallback != null) {
WebObjectFunctionDefinition call = createWebObjectFunction(onDataChangeCallback);
webComponent.invokeApi(call, new Object[] { event, returnValue, exception == null ? null : exception.getMessage() });
}
}
}
}
use of com.servoy.j2db.server.ngclient.property.DataproviderConfig in project servoy-client by Servoy.
the class DataproviderPropertyType method parseConfig.
@Override
@SuppressWarnings("nls")
public Object parseConfig(JSONObject json) {
String onDataChange = null;
String onDataChangeCallback = null;
// String forFoundSet = null; // see FoundsetLinkedPropertyType for how dataproviders linked to foundsets work
boolean hasParseHtml = false;
String displayTagsPropertyName = null;
boolean displayTags = false;
boolean resolveValuelist = false;
if (json != null) {
JSONObject onDataChangeObj = json.optJSONObject("ondatachange");
if (onDataChangeObj != null) {
onDataChange = onDataChangeObj.optString("onchange", null);
onDataChangeCallback = onDataChangeObj.optString("callback", null);
}
hasParseHtml = json.has(HTMLStringPropertyType.CONFIG_OPTION_PARSEHTML) ? json.optBoolean(HTMLStringPropertyType.CONFIG_OPTION_PARSEHTML) : false;
displayTagsPropertyName = json.optString(DataproviderConfig.DISPLAY_TAGS_PROPERTY_NAME_CONFIG_OPT, null);
displayTags = json.has(DataproviderConfig.DISPLAY_TAGS_CONFIG_OPT) ? json.optBoolean(DataproviderConfig.DISPLAY_TAGS_CONFIG_OPT, false) : false;
resolveValuelist = json.has(DataproviderConfig.RESOLVE_VALUELIST_CONFIG_OPT) ? json.optBoolean(DataproviderConfig.RESOLVE_VALUELIST_CONFIG_OPT, false) : false;
}
return new DataproviderConfig(onDataChange, onDataChangeCallback, hasParseHtml, displayTagsPropertyName, displayTags, resolveValuelist);
}
use of com.servoy.j2db.server.ngclient.property.DataproviderConfig 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);
}
use of com.servoy.j2db.server.ngclient.property.DataproviderConfig in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method attachToBaseObject.
@Override
public void attachToBaseObject(IChangeListener changeNotifier, IWebObjectContext webObjectCntxt) {
this.changeMonitor = changeNotifier;
this.webObjectContext = webObjectCntxt;
if (webObjectCntxt instanceof INGWebObjectContext)
this.dataAdapterList = ((INGWebObjectContext) webObjectCntxt).getDataAdapterList();
computeShouldResolveValuelistConfig();
// register data link and find mode listeners as needed
dataLinks = ((DataproviderPropertyType) dpPD.getType()).getDataLinks(dataProviderID, servoyDataConverterContext.getForm() != null ? servoyDataConverterContext.getForm().getForm() : null);
dataAdapterList.addDataLinkedProperty(this, dataLinks);
// they weren't cached in form element; get them again
boolean isFindModeAware = ((DataproviderPropertyType) dpPD.getType()).isFindModeAware(dataProviderID, servoyDataConverterContext.getForm() != null ? servoyDataConverterContext.getForm().getForm() : null);
if (isFindModeAware)
dataAdapterList.addFindModeAwareProperty(this);
DataproviderConfig config = (DataproviderConfig) dpPD.getConfig();
String dtpn = config.getDisplayTagsPropertyName();
Object dtPropVal = null;
if (dtpn != null) {
dtPropVal = webObjectCntxt.getProperty(dtpn);
if (dtPropVal == null)
dtPropVal = Boolean.FALSE;
}
displaysTags = dtpn != null && ((Boolean) dtPropVal).booleanValue() == true || (dtpn == null && config.shouldDisplayTags());
dataProviderOrRecordChanged(dataAdapterList.getRecord(), null, false, false, false);
}
use of com.servoy.j2db.server.ngclient.property.DataproviderConfig in project servoy-client by Servoy.
the class WebFormComponent method markPropertyContentsUpdated.
@Override
protected boolean markPropertyContentsUpdated(String key) {
if (isInvalidState()) {
DataproviderConfig dataproviderConfig = DataAdapterList.getDataproviderConfig(this, key);
if (dataproviderConfig != null && dataproviderConfig.getOnDataChangeCallback() != null) {
WebObjectFunctionDefinition function = DataAdapterList.createWebObjectFunction(dataproviderConfig.getOnDataChangeCallback());
JSONObject event = EventExecutor.createEvent(dataproviderConfig.getOnDataChangeCallback(), dataAdapterList.getForm().getFormModel().getSelectedIndex());
invokeApi(function, new Object[] { event, null, null });
setInvalidState(false);
}
}
boolean modified = super.markPropertyContentsUpdated(key);
return modified;
}
Aggregations