Search in sources :

Example 81 with Form

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

the class JSForm method getMethods.

/**
 * Returns all existing form methods for this form.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var methods = frm.getMethods();
 * for (var m in methods)
 * 	application.output(methods[m].getName());
 *
 * @param returnInheritedElements boolean true to also return the elements from the parent form
 * @return all form methods for the form
 */
@JSFunction
public JSMethod[] getMethods(boolean returnInheritedElements) {
    List<JSMethod> methods = new ArrayList<JSMethod>();
    Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
    Iterator<ScriptMethod> scriptMethods = form2use.getScriptMethods(true);
    while (scriptMethods.hasNext()) {
        methods.add(new JSMethod(this, scriptMethods.next(), application, false));
    }
    return methods.toArray(new JSMethod[methods.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) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 82 with Form

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

the class JSForm method setExtendsForm.

@JSSetter
public void setExtendsForm(Object superForm) {
    checkModification();
    Form f = null;
    if (superForm instanceof JSForm) {
        f = ((JSForm) superForm).getSupportChild();
    } else if (superForm instanceof String) {
        f = application.getFlattenedSolution().getForm((String) superForm);
    }
    if (f == null) {
        if (superForm != null) {
            // this kind of argument is not supported or wrong
            throw new RuntimeException("extendsForm must receive either null, a JSForm object or a valid form name");
        }
        getForm().setExtendsID(AbstractBase.DEFAULT_INT);
    } else {
        // }
        if (f.isResponsiveLayout() != getForm().isResponsiveLayout()) {
            if (getForm().isResponsiveLayout()) {
                if (// only if it is not an abstract form
                f.getParts().hasNext()) {
                    throw new RuntimeException("Form '" + getForm().getName() + "' is a responsive layout form, it cannot extend form '" + f.getName() + "' which is an absolute layout form.");
                }
            } else {
                throw new RuntimeException("Form '" + getForm().getName() + "' is an absolute layout form, it cannot extend form '" + f.getName() + "' which is a responsive layout form.");
            }
        }
        getForm().setExtendsID(f.getID());
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) JSSetter(org.mozilla.javascript.annotations.JSSetter)

Example 83 with Form

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

the class JSForm method getMethodId.

public static int getMethodId(IApplication application, AbstractBase base, ScriptMethod method) {
    ISupportChilds parent = method.getParent();
    Form f = getFormParent(base);
    // quick check if it is solution or own form..
    if (parent instanceof Solution || parent.getUUID().equals(f.getUUID())) {
        return method.getID();
    }
    // it could be a extends form
    while (f != null && f.getExtendsID() > 0) {
        f = application.getFlattenedSolution().getForm(f.getExtendsID());
        if (f != null && parent.getUUID().equals(f.getUUID())) {
            return method.getID();
        }
    }
    // or a foundset method
    Iterator<ScriptMethod> foundsetMethods = application.getFlattenedSolution().getFoundsetMethods(f.getDataSource(), false);
    while (foundsetMethods.hasNext()) {
        if (foundsetMethods.next().getID() == method.getID()) {
            return method.getID();
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    throw new RuntimeException("Method " + method.getName() + " must be a solution method, foundset method or a forms own method");
}
Also used : ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 84 with Form

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

the class JSBaseContainer method newWebComponent.

/**
 * Creates a new JSWebComponent (spec based component) object on the RESPONSIVE form.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
 * var container = myForm.getLayoutContainer("row1")
 * var bean = container.newWebComponent('bean','mypackage-testcomponent',1);
 *
 * @param name the specified name of the JSWebComponent object
 * @param type the webcomponent name as it appears in the spec
 * @param position the position of JSWebComponent object in its parent container
 *
 * @return a JSWebComponent object
 */
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSWebComponent newWebComponent(String name, String type, int position) {
    checkModification();
    try {
        AbstractContainer container = getContainer();
        Form form = (Form) container.getAncestor(IRepository.FORMS);
        if (form.isResponsiveLayout()) {
            if (name == null) {
                String componentName = type;
                int index = componentName.indexOf("-");
                if (index != -1) {
                    componentName = componentName.substring(index + 1);
                }
                // $NON-NLS-1$//$NON-NLS-2$
                componentName = componentName.replaceAll("-", "_");
                // $NON-NLS-1$
                name = componentName + "_" + id.incrementAndGet();
                IJSParent<?> parent = this;
                while (!(parent instanceof JSForm)) {
                    parent = parent.getJSParent();
                }
                if (parent instanceof JSForm) {
                    while (findComponent((JSForm) parent, name) != null) {
                        name = componentName + "_" + id.incrementAndGet();
                    }
                }
            }
            WebComponent webComponent = container.createNewWebComponent(IdentDocumentValidator.checkName(name), type);
            webComponent.setLocation(new Point(position, position));
            return createWebComponent(this, webComponent, application, true);
        } else {
            throw new RuntimeException("Form " + form.getName() + " is not responsive. Cannot create component without specifying the location and size.");
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : WebComponent(com.servoy.j2db.persistence.WebComponent) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) Form(com.servoy.j2db.persistence.Form) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 85 with Form

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

the class JSBaseContainer method getCorrectIJSParent.

/**
 * When creating a JSWebComponent from a who-knows-how-deeply-nested (in case of responsive forms) webComponent in a form and we only know the form,
 * then we need to get step by step the solution model objects in order to use the correct direct parent for the child SM object creation.
 *
 * @param startingContainer
 * @param possiblyNestedChild nested child component
 * @return the direct parent (IJSParent) of the given webComponent.
 */
private IJSParent<?> getCorrectIJSParent(JSBaseContainer<?> startingContainer, IPersist possiblyNestedChild) {
    ArrayList<ISupportChilds> parentHierarchy = new ArrayList<>();
    ISupportChilds parent = possiblyNestedChild.getParent();
    while (parent != (startingContainer.getContainer() instanceof IFlattenedPersistWrapper<?> ? ((IFlattenedPersistWrapper<?>) startingContainer.getContainer()).getWrappedPersist() : startingContainer.getContainer()) && !(parent instanceof Form)) {
        parentHierarchy.add(parent);
        parent = parent.getParent();
    }
    for (int i = parentHierarchy.size(); --i >= 0; ) {
        ISupportChilds container = parentHierarchy.get(i);
        if (container instanceof LayoutContainer) {
            startingContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer((IJSParent<?>) startingContainer, (LayoutContainer) container);
        } else {
            // $NON-NLS-1$
            throw new RuntimeException("unexpected parent: " + container);
        }
    }
    return startingContainer;
}
Also used : IFlattenedPersistWrapper(com.servoy.j2db.persistence.IFlattenedPersistWrapper) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) Form(com.servoy.j2db.persistence.Form) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList) Point(java.awt.Point)

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