Search in sources :

Example 1 with IFoundSet

use of com.servoy.j2db.dataprocessing.IFoundSet in project servoy-client by Servoy.

the class FormController method selectPrevRecord.

public void selectPrevRecord() {
    if (form.getOnPreviousRecordCmdMethodID() == 0) {
        int edittingStoppedFlag = application.getFoundSetManager().getEditRecordList().stopEditing(false);
        if (ISaveConstants.STOPPED != edittingStoppedFlag && ISaveConstants.AUTO_SAVE_BLOCKED != edittingStoppedFlag) {
            return;
        }
        IFoundSet fs = getFoundSet();
        int nextIndex = fs.getSelectedIndex() - 1;
        if (nextIndex >= 0) {
            final Component comp = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
            fs.setSelectedIndex(nextIndex);
            application.invokeLater(new Runnable() {

                public void run() {
                    if (getView() == IForm.LOCKED_RECORD_VIEW || getView() == IForm.RECORD_VIEW) {
                        if (comp != null)
                            comp.requestFocus();
                    } else {
                        requestFocus();
                    }
                }
            });
        }
    } else {
        executeFormMethod(StaticContentSpecLoader.PROPERTY_ONPREVIOUSRECORDCMDMETHODID, null, Boolean.TRUE, true, true);
    }
}
Also used : IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) FormAndComponent(com.servoy.j2db.scripting.JSApplication.FormAndComponent)

Example 2 with IFoundSet

use of com.servoy.j2db.dataprocessing.IFoundSet in project servoy-client by Servoy.

the class FormController method selectNextRecord.

public void selectNextRecord() {
    if (form.getOnNextRecordCmdMethodID() == 0) {
        if ((application.getFoundSetManager().getEditRecordList().stopEditing(false) & (ISaveConstants.STOPPED + ISaveConstants.AUTO_SAVE_BLOCKED)) == 0) {
            return;
        }
        IFoundSet fs = getFoundSet();
        int nextIndex = fs.getSelectedIndex() + 1;
        if (nextIndex >= 0 && nextIndex < fs.getSize()) {
            final Component comp = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
            fs.setSelectedIndex(nextIndex);
            application.invokeLater(new Runnable() {

                public void run() {
                    if (getView() == IForm.LOCKED_RECORD_VIEW || getView() == IForm.RECORD_VIEW) {
                        if (comp != null)
                            comp.requestFocus();
                    } else {
                        requestFocus();
                    }
                }
            });
        }
    } else {
        executeFormMethod(StaticContentSpecLoader.PROPERTY_ONNEXTRECORDCMDMETHODID, null, Boolean.TRUE, true, true);
    }
}
Also used : IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) FormAndComponent(com.servoy.j2db.scripting.JSApplication.FormAndComponent)

Example 3 with IFoundSet

use of com.servoy.j2db.dataprocessing.IFoundSet in project servoy-client by Servoy.

the class JSDataSource method loadRecords.

/**
 * get a new foundset containing records based on a QBSelect query.
 *
 * @sample
 * var qb = datasources.db.example_data.orders.createSelect();
 * qb.result.add(qb.columns.orderid);
 * var fs = datasources.db.example_data.orders.loadRecords(qb);
 *
 * @param qbSelect a query builder object
 * @return a new JSFoundset
 * @throws ServoyException
 */
@JSFunction
public IFoundSet loadRecords(QBSelect qbSelect) throws ServoyException {
    IFoundSet foundset = application.getFoundSetManager().getFoundSet(datasource);
    foundset.loadByQuery(qbSelect);
    return checkDataSourceEquality(foundset) ? foundset : null;
}
Also used : IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 4 with IFoundSet

use of com.servoy.j2db.dataprocessing.IFoundSet in project servoy-client by Servoy.

the class JSDataSource method loadRecords.

/**
 * get a new foundset containing records based on an SQL query string with parameters.
 *
 * @sample
 * var query = "SELECT * FROM public.orders WHERE customerid = ? OR customerid = ? order by orderid asc";
 * var args = ['ROMEY', 'BERGS'];
 * var fs = datasources.db.example_data.orders.loadRecords(query, args);
 *
 * @param query an SQL query string with parameter placeholders
 * @param args an array of arguments for the query string
 * @return a new JSFoundset
 * @throws ServoyException
 */
@JSFunction
public IFoundSet loadRecords(String query, Object[] args) throws ServoyException {
    IFoundSet foundset = application.getFoundSetManager().getFoundSet(datasource);
    ((FoundSet) foundset).loadByQuery(query, args);
    return checkDataSourceEquality(foundset) ? foundset : null;
}
Also used : IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 5 with IFoundSet

use of com.servoy.j2db.dataprocessing.IFoundSet in project servoy-client by Servoy.

the class MapSerializer method convertToMap.

public static Map<String, Object> convertToMap(Object jsobj) {
    Map<String, Object> retval = new HashMap<String, Object>();
    if (jsobj == null || jsobj == Undefined.instance || jsobj instanceof IFoundSet || jsobj instanceof IRecord || !(jsobj instanceof NativeObject)) {
        return retval;
    }
    IdScriptableObject no = (IdScriptableObject) jsobj;
    Object[] noIDs = no.getIds();
    String propertyKey;
    Object propertyValue;
    for (Object element : noIDs) {
        // id can be Integer or String
        if (element instanceof Integer) {
            propertyKey = ((Integer) element).toString();
            propertyValue = no.get(((Integer) element).intValue(), no);
        } else if (element instanceof String) {
            propertyKey = (String) element;
            propertyValue = no.get((String) element, no);
        } else {
            // should not happen
            continue;
        }
        if (// allow but ignore functions nested in objects
        propertyValue instanceof Function) {
            continue;
        }
        if (propertyValue instanceof NativeObject) {
            propertyValue = convertToMap(propertyValue);
        }
        if (propertyValue instanceof Wrapper) {
            propertyValue = ((Wrapper) propertyValue).unwrap();
        }
        retval.put(propertyKey, propertyValue);
    }
    return retval;
}
Also used : NativeObject(org.mozilla.javascript.NativeObject) Function(org.mozilla.javascript.Function) Wrapper(org.mozilla.javascript.Wrapper) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) HashMap(java.util.HashMap) IRecord(com.servoy.j2db.dataprocessing.IRecord) NativeObject(org.mozilla.javascript.NativeObject) IdScriptableObject(org.mozilla.javascript.IdScriptableObject) IdScriptableObject(org.mozilla.javascript.IdScriptableObject)

Aggregations

IFoundSet (com.servoy.j2db.dataprocessing.IFoundSet)7 JSFunction (org.mozilla.javascript.annotations.JSFunction)3 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)2 FormAndComponent (com.servoy.j2db.scripting.JSApplication.FormAndComponent)2 IComponent (com.servoy.j2db.ui.IComponent)2 Component (java.awt.Component)2 JComponent (javax.swing.JComponent)2 FormController (com.servoy.j2db.FormController)1 FormManager (com.servoy.j2db.FormManager)1 IForm (com.servoy.j2db.IForm)1 IRecord (com.servoy.j2db.dataprocessing.IRecord)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Function (org.mozilla.javascript.Function)1 IdScriptableObject (org.mozilla.javascript.IdScriptableObject)1 NativeObject (org.mozilla.javascript.NativeObject)1 Wrapper (org.mozilla.javascript.Wrapper)1