Search in sources :

Example 56 with Form

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

the class JSForm method getVariables.

/**
 * An array consisting of all form variables for this form.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var variables = frm.getVariables();
 * for (var i in variables)
 * 	application.output(variables[i].name);
 *
 * @param returnInheritedElements boolean true to also return the elements from the parent form
 * @return an array of all variables on this form
 */
@JSFunction
public JSVariable[] getVariables(boolean returnInheritedElements) {
    List<JSVariable> variables = new ArrayList<JSVariable>();
    Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
    Iterator<ScriptVariable> scriptVariables = form2use.getScriptVariables(true);
    while (scriptVariables.hasNext()) {
        variables.add(new JSVariable(application, this, scriptVariables.next(), false));
    }
    return variables.toArray(new JSVariable[variables.size()]);
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) ArrayList(java.util.ArrayList) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 57 with Form

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

the class JSForm method getEventHandler.

public static <T extends AbstractBase> JSMethod getEventHandler(IApplication application, T persist, int methodid, IJSParent<?> parent, String propertyName) {
    if (methodid > 0) {
        IJSScriptParent<?> scriptParent = null;
        ScriptMethod scriptMethod = null;
        if (parent instanceof JSForm) {
            // form method
            scriptMethod = ((JSForm) parent).getSupportChild().getScriptMethod(methodid);
            if (scriptMethod == null) {
                Form f = ((JSForm) parent).getSupportChild();
                while (f != null && f.getExtendsID() > 0 && scriptMethod == null) {
                    f = application.getFlattenedSolution().getForm(f.getExtendsID());
                    if (f != null)
                        scriptMethod = f.getScriptMethod(methodid);
                }
                if (scriptMethod != null) {
                    scriptParent = application.getScriptEngine().getSolutionModifier().instantiateForm(f, false);
                }
            }
        }
        if (scriptMethod == null) {
            // foundset method
            if (parent instanceof JSDataSourceNode) {
                scriptMethod = ((JSDataSourceNode) parent).getSupportChild().getFoundsetMethod(methodid);
            } else if (parent instanceof JSForm && ((JSForm) parent).getForm().getDataSource() != null) {
                Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(((JSForm) parent).getForm().getDataSource(), false);
                scriptMethod = AbstractBase.selectById(foundsetMethods, methodid);
                if (scriptMethod != null) {
                    scriptParent = new JSDataSourceNode(application, ((JSForm) parent).getForm().getDataSource());
                }
            }
        }
        if (scriptMethod == null) {
            // global method
            scriptMethod = application.getFlattenedSolution().getScriptMethod(methodid);
        }
        if (scriptMethod != null) {
            if (scriptParent == 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);
                }
            }
            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());
            }
        }
    } else if (methodid == 0 && BaseComponent.isCommandProperty(propertyName)) {
        return (JSMethod) ISMDefaults.COMMAND_DEFAULT;
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) Iterator(java.util.Iterator) 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 58 with Form

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

the class JSForm method checkModification.

@Override
public final void checkModification() {
    // make copy if needed
    if (!isCopy) {
        setForm(application.getFlattenedSolution().createPersistCopy(getForm()));
        application.getFormManager().addForm(getForm(), false);
        // forms scope still uses the old copy of Script Providers
        Form oldform = getForm();
        List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
        for (IFormController formController : controllers) {
            FormScope formScope = formController.getFormScope();
            formScope.updateProviderswithCopy(oldform, getForm());
        }
        isCopy = true;
    } else {
        application.getFlattenedSolution().flushFlattendFormCache(getForm(), true);
    }
    getForm().setLastModified(System.currentTimeMillis());
    application.getFlattenedSolution().registerChangedForm(getForm());
    useFormCache = false;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) IFormController(com.servoy.j2db.IFormController) FormScope(com.servoy.j2db.scripting.FormScope)

Example 59 with Form

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

the class JSForm method getForm.

private Form getForm() {
    if (!isCopy) {
        // as long as the form is not already a copy, we have to get the real one
        // so that changes to other instances of JSForm that points to the same form are seen in this one.
        Form frm = application.getFlattenedSolution().getForm(form.getName());
        form = frm != null ? frm : form;
    }
    return form;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm)

Example 60 with Form

use of com.servoy.j2db.persistence.Form 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)

Aggregations

Form (com.servoy.j2db.persistence.Form)146 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)35 ArrayList (java.util.ArrayList)32 Point (java.awt.Point)26 FlattenedSolution (com.servoy.j2db.FlattenedSolution)24 IPersist (com.servoy.j2db.persistence.IPersist)22 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)20 JSONObject (org.json.JSONObject)20 Solution (com.servoy.j2db.persistence.Solution)16 Dimension (java.awt.Dimension)15 Part (com.servoy.j2db.persistence.Part)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)14 FormController (com.servoy.j2db.FormController)13 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)12 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)11 IForm (com.servoy.j2db.IForm)11 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)11 FormElement (com.servoy.j2db.server.ngclient.FormElement)11 HashMap (java.util.HashMap)11 JSFunction (org.mozilla.javascript.annotations.JSFunction)11