use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedTypeSabloValue 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.FoundsetLinkedTypeSabloValue in project servoy-client by Servoy.
the class DataAdapterList method startEdit.
public void startEdit(WebFormComponent webComponent, String property, String foundsetLinkedRowID) {
try {
webComponent.checkPropertyProtection(property);
} catch (IllegalChangeFromClientException ex) {
// ignore, this is just to check if we can edit it, if not, do not enter edit mode
return;
}
String dataProviderID = getDataProviderID(webComponent, property);
if (dataProviderID == null) {
Debug.log("startEdit called on a property that is not bound to a dataprovider: " + property + " of component: " + webComponent);
return;
}
IRecordInternal recordToUse = record;
if (!ScopesUtils.isVariableScope(dataProviderID)) {
Object propertyValue = webComponent.getProperty(property);
if (propertyValue instanceof FoundsetLinkedTypeSabloValue) {
if (foundsetLinkedRowID != null) {
// find the row of the foundset that the user started to edit; 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
recordToUse = getFoundsetLinkedRecord((FoundsetLinkedTypeSabloValue<?, ?>) propertyValue, foundsetLinkedRowID);
if (recordToUse == null) {
Debug.error("Error executing startEdit (from client) for foundset linked DP (cannot find record): dp=" + propertyValue + ", 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
}
if (recordToUse != null) {
int rowIndex = recordToUse.getParentFoundSet().getRecordIndex(recordToUse);
if (Arrays.binarySearch(recordToUse.getParentFoundSet().getSelectedIndexes(), rowIndex) < 0) {
recordToUse.getParentFoundSet().setSelectedIndex(rowIndex);
}
recordToUse.startEditing();
}
}
}
Aggregations