Search in sources :

Example 56 with IRecordInternal

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;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal)

Example 57 with IRecordInternal

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);
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IRelatedFoundsetChainSelectionChangeListener(com.servoy.j2db.server.ngclient.property.ChainedRelatedFoundsetSelectionMonitor.IRelatedFoundsetChainSelectionChangeListener) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) ServoyException(com.servoy.j2db.util.ServoyException)

Example 58 with IRecordInternal

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;
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal)

Example 59 with IRecordInternal

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();
    }
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ElementScope(com.servoy.j2db.scripting.ElementScope) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 60 with IRecordInternal

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;
}
Also used : FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) JSONObject(org.json.JSONObject) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FoundsetPropertyTypeConfig(com.servoy.j2db.server.ngclient.property.FoundsetPropertyTypeConfig)

Aggregations

IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)63 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)26 Point (java.awt.Point)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 FormController (com.servoy.j2db.FormController)9 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)7 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)7 RepositoryException (com.servoy.j2db.persistence.RepositoryException)7 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 ServoyException (com.servoy.j2db.util.ServoyException)7 JSONObject (org.json.JSONObject)7 IComponent (com.servoy.j2db.ui.IComponent)6 ArrayList (java.util.ArrayList)6 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)5 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 JComponent (javax.swing.JComponent)5 Component (org.apache.wicket.Component)5 ApplicationException (com.servoy.j2db.ApplicationException)4