Search in sources :

Example 76 with Form

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

the class JSSolutionModel method getForm.

/**
 * Gets the specified form object and returns information about the form (see JSForm node).
 *
 * @sample
 * var myForm = solutionModel.getForm('existingFormName');
 * //get the style of the form (for all other properties see JSForm node)
 * var styleName = myForm.styleName;
 *
 * @param name the specified name of the form
 *
 * @return a JSForm
 */
@JSFunction
public JSForm getForm(String name) {
    if (name == null)
        return null;
    Form form = application.getFormManager().getPossibleForm(name);
    if (form == null) {
        FlattenedSolution fs = application.getFlattenedSolution();
        form = fs.getForm(name);
        if (form == null) {
            // search ignoring case
            Iterator<Form> forms = fs.getForms(false);
            String lowerCaseName = Utils.toEnglishLocaleLowerCase(name);
            Form f;
            while (forms.hasNext() && form == null) {
                f = forms.next();
                if (Utils.toEnglishLocaleLowerCase(f.getName()).equals(lowerCaseName))
                    form = f;
            }
        }
    }
    if (form != null) {
        return instantiateForm(form, false);
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 77 with Form

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

the class JSSolutionModel method revertForm.

/**
 * Reverts the specified form to the original (blueprint) version of the form; will result in an exception error if the form is not an original form.
 *
 * NOTE: Make sure you call history.remove first in your Servoy method (script) or call form.controller.recreateUI() before the script ends.
 *
 * @sample
 * // revert the form to the original solution form, removing any changes done to it through the solution model.
 * var revertedForm = solutionModel.revertForm('myForm')
 * // add a label on a random place.
 * revertedForm.newLabel("MyLabel",Math.random()*100,Math.random()*100,80,20);
 * // make sure that the ui is up to date.
 * forms.myForm.controller.recreateUI();
 *
 * @param name the specified name of the form to revert
 *
 * @return a JSForm object
 */
@JSFunction
public JSForm revertForm(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form form = fs.revertForm(name);
    if (form != null) {
        application.getFormManager().addForm(form, false);
        return instantiateForm(form, false);
    } else {
        form = application.getFormManager().getPossibleForm(name);
        if (form != null) {
            application.getFormManager().removeForm(form);
        }
    }
    return null;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 78 with Form

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

the class JSSolutionModel method getParentContainer.

private IJSParent<?> getParentContainer(IPersist persist) {
    IJSParent<?> parent = null;
    List<AbstractContainer> parentHierarchy = new ArrayList<AbstractContainer>();
    IPersist currentParent = persist.getParent();
    while (currentParent != null) {
        if (currentParent instanceof AbstractContainer) {
            parentHierarchy.add(0, (AbstractContainer) currentParent);
        }
        if (currentParent instanceof Form)
            break;
        currentParent = currentParent.getParent();
    }
    for (AbstractContainer container : parentHierarchy) {
        if (container instanceof LayoutContainer) {
            parent = new JSLayoutContainer(parent, application, (LayoutContainer) persist);
        }
        if (container instanceof Form) {
            parent = instantiateForm((Form) container, false);
        }
    }
    return parent;
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList)

Example 79 with Form

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

the class RuntimeWindow method showObject.

public void showObject(Object form) throws ServoyException {
    String f = null;
    if (form instanceof BasicFormController) {
        f = ((BasicFormController) form).getName();
    } else if (form instanceof FormScope) {
        f = ((FormScope) form).getFormController().getName();
    } else if (form instanceof FormController.JSForm) {
        f = ((FormController.JSForm) form).getFormPanel().getName();
    } else if (form instanceof String) {
        f = (String) form;
    } else if (form instanceof JSForm) {
        f = ((JSForm) form).getName();
    }
    if (f != null) {
        Form frm = application.getFlattenedSolution().getForm(f);
        IBasicFormManager fm = application.getFormManager();
        if (frm == null && fm.isPossibleForm(f))
            frm = fm.getPossibleForm(f);
        if (!application.getFlattenedSolution().formCanBeInstantiated(frm)) {
            // abstract form
            throw new ApplicationException(ServoyException.ABSTRACT_FORM, new Object[] { f });
        }
        show(f);
    }
}
Also used : ApplicationException(com.servoy.j2db.ApplicationException) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) IBasicFormManager(com.servoy.j2db.IBasicFormManager) BasicFormController(com.servoy.j2db.BasicFormController)

Example 80 with Form

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

the class JSForm method getParts.

/**
 * Gets all the parts from the form (optionally also from the parent form), ordered by there height (lowerbound) property, from top == 0 to bottom.
 *
 * @sample
 * var allParts = form.getParts()
 * for (var i=0; i<allParts.length; i++) {
 *	if (allParts[i].getPartType() == JSPart.BODY)
 *		application.output('body Y offset: ' + allParts[i].getPartYOffset());
 * }
 *
 * @param returnInheritedElements boolean true to also return the parts from parent form
 * @return An array of JSPart instances corresponding to the parts of the form.
 */
@JSFunction
public JSPart[] getParts(boolean returnInheritedElements) {
    List<JSPart> lst = new ArrayList<JSPart>();
    Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
    Iterator<Part> parts = form2use.getParts();
    while (parts.hasNext()) {
        lst.add(JSPart.createPart(this, parts.next(), false));
    }
    return lst.toArray(new JSPart[lst.size()]);
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) Part(com.servoy.j2db.persistence.Part) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

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