use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FoundsetTypeSabloValue method setEditingRowByPkHash.
public boolean setEditingRowByPkHash(String pkHashAndIndex) {
Pair<String, Integer> splitHashAndIndex = splitPKHashAndIndex(pkHashAndIndex);
int recordIndex = splitHashAndIndex.getRight().intValue();
IRecordInternal recordByIndexHint = foundset.getRecord(recordIndex);
String pkHash = splitHashAndIndex.getLeft();
if (recordByIndexHint == null || !pkHash.equals(recordByIndexHint.getPKHashKey())) {
recordIndex = foundset.getRecordIndex(pkHash, recordIndex);
if (recordIndex != -1) {
foundset.setSelectedIndex(recordIndex);
return true;
} else
return false;
} else
foundset.setSelectedIndex(recordIndex);
return true;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FoundsetTypeSabloValue method updateFoundset.
/**
* Find the foundset to be used based on the design value of "foundsetSelector".\n
* It can be either:
* <ul>
* <li>a related foundset based on the component's current record (as one would access it in scripting). Example: "customers_to_orders";</li>
* <li>the component's foundset (as if in scripting you would say 'foundset') - if foundsetSelector is not specified at design time or null;</li>
* <li>a new foundset based on the given datasource (as if you would do DatabaseManager.getFoundset(datasource) in scripting). Example: "db:/example_data/customers".</li>
* </ul>
*
* @param record the record this component is attached to; can be null. (form not linked to table or no records for example)
*
* @return true if the foundset was update, false otherwise.
*/
protected void updateFoundset(IRecordInternal record) {
// this foundset is only meant to be set from Rhino scripting; do not automatically set it and do not automatically clear it once it's set from Rhino
if (foundsetSelector == null)
return;
IFoundSetInternal newFoundset = null;
if (FORM_FOUNDSET_SELECTOR.equals(foundsetSelector)) {
// it is the form's foundset then
if (record != null) {
newFoundset = record.getParentFoundSet();
}
} else if (!DataSourceUtils.isDatasourceUri(foundsetSelector)) {
// it is a relation then or a shared named foundset (set somewhere on a form in designer)
if (record != null) {
Object o = record.getValue(foundsetSelector);
if (o instanceof IFoundSetInternal) {
// it is a related foundset then if we were able to get it from current record
newFoundset = (IFoundSetInternal) o;
if (chainedRelatedFoundsetSelectionMonitor == null) {
chainedRelatedFoundsetSelectionMonitor = new ChainedRelatedFoundsetSelectionMonitor(new IRelatedFoundsetChainSelectionChangeListener() {
@Override
public void selectionChanged(IRecordInternal rootRecord, String nestedRelationNames) {
updateFoundset(rootRecord);
}
});
}
chainedRelatedFoundsetSelectionMonitor.update(newFoundset, record, foundsetSelector);
} else {
// if it is not a related foundset it must be a shared/named foundset
try {
newFoundset = (IFoundSetInternal) getFoundSetManager().getNamedFoundSet(foundsetSelector);
} catch (ServoyException e) {
Debug.error(e);
}
}
}
} else // DataSourceUtils.isDatasourceUri(foundsetSelector)
{
// that will only reinitialize constantly this FoundsetType/Table with a new foundset - on every dataprovider change.
if (foundset != null)
newFoundset = foundset;
else {
try {
// if we want to use this type on services as well we need extra code here to get the application
newFoundset = (IFoundSetInternal) getFoundSetManager().getFoundSet(foundsetSelector);
if (((JSONObject) designJSONValue).optBoolean(FoundsetPropertyType.LOAD_ALL_RECORDS_FOR_SEPARATE, false)) {
newFoundset.loadAllRecords();
}
} catch (ServoyException e) {
if (record != null && !(record instanceof PrototypeState))
Debug.error(e);
}
}
}
updateFoundset(newFoundset);
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FoundsetTypeViewport method correctAndSetViewportBoundsInternal.
/**
* Corrects bounds given new bounds to be valid and then applies them to current viewport.
*
* This method can also load more records into the foundset (thus firing foundset events) in case of large foundsets with 'hadMoreRecords' true,
* in case the given new bounds require new records.
*/
protected void correctAndSetViewportBoundsInternal(int newStartIndex, int newSize) {
if (foundset != null) {
// this can trigger a query for more records if foundset hadMoreRows is true; that in turn can update through listener serverSize and hadMoreRows related flags on the change monitor
IRecordInternal firstRec = foundset.getRecord(newStartIndex);
if (firstRec != null) {
if (newSize > 0) {
// this can trigger a query for more records if foundset hadMoreRows is true; that in turn can update through listener serverSize and hadMoreRows related flags on the change monitor
IRecordInternal lastRec = foundset.getRecord(newStartIndex + newSize - 1);
// do this after getRecord above would potentially load more records, trigger inserted event and potentially wrongly adjust current viewport bounds
startIndex = newStartIndex;
if (lastRec == null) {
size = foundset.getSize() - startIndex;
} else {
size = newSize;
}
} else {
startIndex = newStartIndex;
size = 0;
}
} else {
startIndex = 0;
size = 0;
}
} else {
startIndex = 0;
size = 0;
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class WebFormUI method init.
/**
* this is a full recreate ui.
*
* @param formController
* @param dal
* @return
* @throws RepositoryException
*/
public void init() {
clearComponents();
cachedElements.clear();
fcc = null;
groups = null;
IDataAdapterList previousDataAdapterList = dataAdapterList;
dataAdapterList = new DataAdapterList(formController);
initContainerScopeIfNeeded(formController);
ElementScope elementsScope = initElementScope(formController);
List<FormElement> formElements = getFormElements();
for (FormElement fe : formElements) {
// TODO do something similar for child elements (so properties of type 'components' which contain componentSpecs in them)
WebObjectSpecification componentSpec = fe.getWebComponentSpec(false);
if (componentSpec == null) {
getApplication().reportError("Didn't find a spec file for component " + fe + " when creating form: " + formController.getName(), null);
continue;
}
WebFormComponent component = ComponentFactory.createComponent(getApplication(), dataAdapterList, fe, this, getController().getForm());
contributeComponentToElementsScope(elementsScope, fe, componentSpec, component);
}
DefaultNavigatorWebComponent nav = (DefaultNavigatorWebComponent) getComponent(DefaultNavigator.NAME_PROP_VALUE);
if (nav != null) {
nav.newFoundset(null);
}
// special support for the default navigator
if (formController.getForm().getNavigatorID() == Form.NAVIGATOR_DEFAULT) {
add(new DefaultNavigatorWebComponent(dataAdapterList));
}
if (previousDataAdapterList != null) {
IRecordInternal record = ((DataAdapterList) previousDataAdapterList).getRecord();
if (record != null) {
dataAdapterList.setRecord(record, false);
previousDataAdapterList.setRecord(null, false);
nav = (DefaultNavigatorWebComponent) getComponent(DefaultNavigator.NAME_PROP_VALUE);
if (nav != null)
nav.newFoundset(record.getParentFoundSet());
}
previousDataAdapterList.destroy();
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class NGFoundSetManager method getFoundsetTypeSabloValue.
private FoundsetTypeSabloValue getFoundsetTypeSabloValue(IFoundSetInternal foundset, JSONObject dataproviders) {
FoundsetTypeSabloValue foundsetTypeSabloValue = foundsetTypeSabloValueMap.get(foundset);
if (foundsetTypeSabloValue == null) {
foundsetTypeSabloValue = new FoundsetTypeSabloValue(new JSONObject(), null, null, new FoundsetPropertyTypeConfig(false, false, null, false, 15, false)) {
@Override
protected void updateFoundset(IRecordInternal record) {
if (record != null) {
super.updateFoundset(record);
}
}
};
foundsetTypeSabloValue.updateFoundset(foundset);
foundsetTypeSabloValueMap.put(foundset, foundsetTypeSabloValue);
}
foundsetTypeSabloValue.initializeDataproviders(dataproviders);
foundsetTypeSabloValue.getViewPort().setBounds(0, foundsetTypeSabloValue.getFoundset().getSize());
return foundsetTypeSabloValue;
}
Aggregations