Search in sources :

Example 1 with ScriptMethod

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

the class EventCallTest method fillTestSolution.

@Override
protected void fillTestSolution() throws ServoyException {
    Form form = solution.createNewForm(validator, null, "test", null, false, new Dimension(600, 400));
    form.setNavigatorID(-1);
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar", IColumnTypes.INTEGER);
    GraphicalComponent button = form.createNewGraphicalComponent(new Point(10, 10));
    button.setShowClick(true);
    button.setShowFocus(true);
    ScriptMethod sm = form.createNewScriptMethod(DummyValidator.INSTANCE, "test");
    sm.setDeclaration("function test() {testVar = 10}");
    button.setOnActionMethodID(sm.getID());
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar2", IColumnTypes.TEXT);
    GraphicalComponent button2 = form.createNewGraphicalComponent(new Point(10, 10));
    button2.setName(uuid);
    button2.setShowClick(true);
    button2.setShowFocus(true);
    ScriptMethod sm2 = form.createNewScriptMethod(DummyValidator.INSTANCE, "test2");
    sm2.setDeclaration("function test2() {testVar2 = elements['" + uuid + "'].getName()}");
    button2.setOnActionMethodID(sm2.getID());
}
Also used : Form(com.servoy.j2db.persistence.Form) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 2 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 3 with ScriptMethod

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

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, String uuidOrName, IJSParent<?> parent, String propertyName) {
    if (uuidOrName != null) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(uuidOrName);
        ;
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof TableNode && parent instanceof JSDataSourceNode) {
                scriptParent = (JSDataSourceNode) parent;
            } else if (scriptMethod.getParent() instanceof Solution) {
                // global
                scriptParent = null;
            } else {
                // form method
                scriptParent = getJSFormParent(parent);
                if (scriptMethod.getParent() != scriptParent.getSupportChild() && scriptParent.getSupportChild() instanceof Form) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm((Form) scriptParent.getSupportChild(), false);
                }
            }
            List<Object> arguments = persist.getFlattenedMethodArguments(propertyName);
            if (arguments == null || arguments.size() == 0) {
                return new JSMethod(scriptParent, scriptMethod, application, false);
            } else {
                return new JSMethodWithArguments(application, scriptParent, scriptMethod, false, arguments.toArray());
            }
        }
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) TableNode(com.servoy.j2db.persistence.TableNode) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 4 with ScriptMethod

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

the class JSForm method js_setOnRecordEditStartMethod.

/**
 * @deprecated As of release 4.1, replaced by setOnRecordEditStart(JSMethod).
 */
@Deprecated
@ServoyClientSupport(ng = false, wc = true, sc = true)
public void js_setOnRecordEditStartMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnRecordEditStartMethodID(scriptMethod.getID());
        } else {
            getForm().setOnRecordEditStartMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnRecordEditStartMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 5 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