Search in sources :

Example 6 with ScriptMethod

use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.

the class SQLSheet method processCopyValues.

void processCopyValues(IRecordInternal s) {
    SQLDescription desc = getSQLDescription(SELECT);
    if (desc == null) {
        return;
    }
    List<?> list = desc.getDataProviderIDsDilivery();
    for (int i = 0; i < list.size(); i++) {
        try {
            String id = (String) list.get(i);
            Column c = table.getColumn(id);
            if (c != null) {
                ColumnInfo ci = c.getColumnInfo();
                if (ci != null && ci.getAutoEnterType() == ColumnInfo.LOOKUP_VALUE_AUTO_ENTER) {
                    String lookupDataProviderID = ci.getLookupValue();
                    Object obj = s.getValue(lookupDataProviderID);
                    if (ScopesUtils.isVariableScope(lookupDataProviderID) && !s.has(lookupDataProviderID)) {
                        ScriptMethod globalScriptMethod = application.getFlattenedSolution().getScriptMethod(null, lookupDataProviderID);
                        if (globalScriptMethod != null) {
                            try {
                                IServer server = application.getSolution().getServer(table.getServerName());
                                obj = application.getScriptEngine().getScopesScope().executeGlobalFunction(globalScriptMethod.getScopeName(), globalScriptMethod.getName(), new Object[] { new JSColumn(c, server, table) }, false, false);
                            } catch (Exception e) {
                                Debug.error(e);
                            }
                        }
                    }
                    // Protect to writing null to null-protected columns. An exception gets written in the log.
                    if (!((obj == null) && !c.getAllowNull()))
                        s.setValue(id, obj, false);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 7 with ScriptMethod

use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.

the class FoundSetManager method getTriggerFunctions.

private List<TriggerFunction> getTriggerFunctions(ITable table, TypedProperty<Integer> property, Scriptable foundsetScope) {
    FlattenedSolution solutionRoot = getApplication().getFlattenedSolution();
    IExecutingEnviroment scriptEngine = getApplication().getScriptEngine();
    return stream(solutionRoot.getTableNodes(table)).map(tableNode -> {
        Object function = null;
        Scriptable scope = null;
        ScriptMethod scriptMethod = solutionRoot.getScriptMethod(((Integer) tableNode.getProperty(property.getPropertyName())).intValue());
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof Solution) {
                // global method
                GlobalScope gs = scriptEngine.getScopesScope().getGlobalScope(scriptMethod.getScopeName());
                if (gs != null) {
                    scope = gs;
                    function = gs.get(scriptMethod.getName());
                }
            } else if (foundsetScope != null) {
                // foundset method
                scope = foundsetScope;
                function = scope.getPrototype().get(scriptMethod.getName(), scope);
            }
        }
        if (function instanceof Function) {
            return new TriggerFunction((Function) function, scope, tableNode);
        }
        return null;
    }).filter(Objects::nonNull).collect(toList());
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) Function(org.mozilla.javascript.Function) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Scriptable(org.mozilla.javascript.Scriptable) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 8 with ScriptMethod

use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.

the class JSForm method js_setOnShowAllRecordsCmdMethod.

/**
 * @deprecated As of release 4.1, replaced by setOnShowAllRecordsCmd(JSMethod).
 */
@Deprecated
public void js_setOnShowAllRecordsCmdMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnShowAllRecordsCmdMethodID(scriptMethod.getID());
        } else {
            getForm().setOnShowAllRecordsCmdMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnShowAllRecordsCmdMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 9 with ScriptMethod

use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.

the class JSForm method js_setOnOmitRecordCmdMethod.

/**
 * @deprecated As of release 4.1, replaced by setOnOmitRecordCmd(JSMethod).
 */
@Deprecated
public void js_setOnOmitRecordCmdMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnOmitRecordCmdMethodID(scriptMethod.getID());
        } else {
            getForm().setOnOmitRecordCmdMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnOmitRecordCmdMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 10 with ScriptMethod

use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.

the class JSForm method js_setOnFindCmdMethod.

/**
 * @deprecated  As of release 4.1, replaced by setOnFindCmd(JSMethod).
 */
@Deprecated
public void js_setOnFindCmdMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnFindCmdMethodID(scriptMethod.getID());
        } else {
            getForm().setOnFindCmdMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnFindCmdMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Aggregations

ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)55 JSFunction (org.mozilla.javascript.annotations.JSFunction)31 Function (org.mozilla.javascript.Function)27 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Solution (com.servoy.j2db.persistence.Solution)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 Form (com.servoy.j2db.persistence.Form)11 TableNode (com.servoy.j2db.persistence.TableNode)9 ServoyException (com.servoy.j2db.util.ServoyException)8 ArrayList (java.util.ArrayList)7 GlobalScope (com.servoy.j2db.scripting.GlobalScope)6 Scriptable (org.mozilla.javascript.Scriptable)5 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)4 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)4 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)3 ApplicationException (com.servoy.j2db.ApplicationException)3 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)3 IPersist (com.servoy.j2db.persistence.IPersist)3 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)3 FormScope (com.servoy.j2db.scripting.FormScope)3