use of com.servoy.j2db.dataprocessing.IRecordInternal 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;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ViewportRowDataProvider method writeRowData.
protected void writeRowData(int foundsetIndex, Set<String> columnNames, IFoundSetInternal foundset, JSONWriter w, DataConversion clientConversionInfo) throws JSONException {
// write viewport row contents
IRecordInternal record = foundset.getRecord(foundsetIndex);
populateRowData(record, columnNames, w, clientConversionInfo, shouldGenerateRowIds() ? record.getPKHashKey() + "_" + foundsetIndex : null);
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method getRelatedRecords.
private ArrayList<IRecordInternal> getRelatedRecords(IRecordInternal record, String relName) {
// similar code as the loop below is also in class DisplaysAdapter - just in case future fixes need to apply to both places
ArrayList<IRecordInternal> returnRelatedRecords = new ArrayList<IRecordInternal>();
if (record != null) {
// get the new records were are depending on
IRecordInternal currRecord = record;
// $NON-NLS-1$
String[] parts = relName.split("\\.");
for (int i = 0; currRecord != null && i < parts.length; i++) {
Object v = currRecord.getValue(parts[i]);
if (v instanceof ISwingFoundSet) {
currRecord = ((ISwingFoundSet) v).getRecord(((ISwingFoundSet) v).getSelectedIndex());
if (currRecord == null)
currRecord = ((ISwingFoundSet) v).getPrototypeState();
returnRelatedRecords.add(currRecord);
} else {
currRecord = null;
}
}
}
return returnRelatedRecords;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FormController method refreshAllPartRenderers.
@Override
protected void refreshAllPartRenderers(IRecordInternal[] records) {
if (!isFormVisible || application.isShutDown())
return;
// don't do anything yet when there are records but the selection is invalid
if (formModel.getSize() > 0 && (formModel.getSelectedIndex() < 0 || formModel.getSelectedIndex() >= formModel.getSize()))
return;
// let the ui know that it will be touched, so that locks can be taken if needed.
getFormUI().touch();
boolean executeOnRecordSelect = false;
IRecordInternal[] state = records;
if (state == null) {
if (formModel != null) {
state = new IRecordInternal[] { formModel.getPrototypeState() };
} else {
state = new IRecordInternal[] { new PrototypeState(null) };
}
}
if (dataRenderers[FORM_EDITOR] != null && !(records == null && formModel != null && formModel.getRawSize() > 0) && isStateChanged(state)) {
lastState = state;
executeOnRecordSelect = true;
}
for (int i = FORM_RENDERER + 1; i < dataRenderers.length; i++) {
IDataRenderer dataRenderer = dataRenderers[i];
if (dataRenderer != null) {
for (IRecordInternal r : state) dataRenderer.refreshRecord(r);
}
}
if (executeOnRecordSelect) {
// do this at the end because dataRenderer.refreshRecord(state) will update selection
// for related tabs - and we should execute js code after they have been updated
executeOnRecordSelect();
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class BasicFormController method setModel.
protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
if (newModel == formModel || adjustingModel) {
// same or adjusting do nothing
return true;
}
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
form.getTableName() }));
}
try {
IView view = getViewComponent();
if (view != null && view.isEditing()) {
// TODO if save fails don't set the newModel??
int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
return false;
}
}
adjustingModel = true;
if (formModel != null) {
try {
((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
((ISwingFoundSet) formModel).removeTableModelListener(this);
// to make sure all data is gc'ed
if (formModel instanceof FoundSet)
((FoundSet) formModel).flushAllCachedItems();
} catch (Exception ex) {
Debug.error(ex);
}
}
setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
if (formScope != null) {
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
if (formScope.getPrototype() == null) {
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
}
}
if (isFormVisible) {
((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
((ISwingFoundSet) formModel).addTableModelListener(this);
if (// it may not yet exist
view != null) {
view.setModel(formModel);
}
// this was former a call to aggregateChange, but now does now unwanted parent traverse...
int[] idx = null;
if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
int selIdx = formModel.getSelectedIndex();
if (selIdx != -1)
idx = new int[] { selIdx };
} else {
idx = formModel.getSelectedIndexes();
}
if (idx == null || idx.length == 0) {
refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
} else {
IRecordInternal[] row = new IRecordInternal[idx.length];
for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
refreshAllPartRenderers(row);
}
}
} finally {
adjustingModel = false;
}
return true;
}
Aggregations