Search in sources :

Example 61 with Form

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

the class JSForm method getPartYOffset.

/**
 * Returns the Y offset of a given part (see JSPart) of the form. This will include
 * all the super forms parts if this form extends a form. Use the height parameter for
 * targetting one of multiple subsummary parts.
 *
 * @sample
 * // get the subform
 * var form = solutionModel.getForm('SubForm');
 * // get the start offset of the body
 * var height = form.getPartYOffset(JSPart.BODY);
 * // place a new button based on the start offset.
 * form.newButton('mybutton',50,50+height,80,20,solutionModel.getGlobalMethod('globals', 'test'));
 *
 * @param type The type of the part whose Y offset will be returned.
 *
 * @param height The height of the part whose Y offset will be returned. This is used when
 *                        one of multiple Leading/Trailing Sumsummary parts is retrieved.
 *
 * @return A number holding the Y offset of the specified form part.
 */
@JSFunction
public int getPartYOffset(int type, int height) {
    Form ff = application.getFlattenedSolution().getFlattenedForm(getForm(), false);
    Iterator<Part> parts = ff.getParts();
    while (parts.hasNext()) {
        Part part = parts.next();
        if (part.getPartType() == type && (height == -1 || part.getHeight() == height)) {
            return ff.getPartStartYPos(part.getID());
        }
    }
    return -1;
}
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) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 62 with Form

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

the class JSSolutionModel method newFormInternal.

/**
 * @param name
 * @param superForm
 * @param isResponsive
 * @return
 */
private JSForm newFormInternal(String name, ISMForm superForm, Boolean isResponsive) {
    if (superForm == null) {
        throw new IllegalArgumentException("superForm cannot be null");
    }
    if (isResponsive != null && (superForm.isResponsiveLayout() || superForm.getParts().length > 0)) {
        throw new IllegalArgumentException("Cannot set the layout type of the child form because the superform '" + superForm.getName() + "' is not a logical form.");
    }
    try {
        Form form = createNewForm(null, name, null, superForm.getShowInMenu(), ((JSForm) superForm).getSupportChild().getSize());
        if (isResponsive != null)
            form.setResponsiveLayout(isResponsive.booleanValue());
        form.clearProperty(StaticContentSpecLoader.PROPERTY_DATASOURCE.getPropertyName());
        application.getFormManager().addForm(form, false);
        form.setExtendsID(((JSForm) superForm).getSupportChild().getID());
        return instantiateForm(form, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 63 with Form

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

the class JSSolutionModel method cloneForm.

/**
 * Makes an exact copy of the given form and gives it the new name.
 *
 * @sample
 * // get an existing form
 * var form = solutionModel.getForm("existingForm")
 * // make a clone/copy from it
 * var clone = solutionModel.cloneForm("clonedForm", form)
 * // add a new label to the clone
 * clone.newLabel("added label",50,50,80,20);
 * // show it
 * forms["clonedForm"].controller.show();
 *
 * @param newName the new name for the form clone
 *
 * @param jsForm the form to be cloned
 *
 * @return a JSForm
 */
@JSFunction
public JSForm cloneForm(String newName, IBaseSMForm jsForm) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form clone = fs.clonePersist(((JSForm) jsForm).getSupportChild(), IdentDocumentValidator.checkName(newName), fs.getSolutionCopy());
    application.getFormManager().addForm(clone, false);
    return instantiateForm(clone, true);
}
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 64 with Form

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

the class JSSolutionModel method cloneComponent.

/**
 * Makes an exact copy of the given component (JSComponent/JSField/JSLabel), gives it a new name and moves it to a new parent form, specified as a parameter.
 *
 * @sample
 * // get an existing field to clone.
 * var field = solutionModel.getForm("formWithField").getField("fieldName");
 * // get the target form for the copied/cloned field
 * var form = solutionModel.getForm("targetForm");
 * // make a clone/copy of the field and re parent it to the target form.
 * var clone = solutionModel.cloneComponent("clonedField",field,form);
 * // show it
 * forms["targetForm"].controller.show();
 *
 * @param newName the new name of the cloned component
 *
 * @param component the component to clone
 *
 * @param newParentForm the new parent form
 *
 * @return the exact copy of the given component
 */
@JSFunction
public JSComponent<?> cloneComponent(String newName, IBaseSMComponent component, IBaseSMForm newParentForm) {
    if (component == null || !(((JSBase) component).getBaseComponent(false).getParent() instanceof Form)) {
        throw new RuntimeException("only components of a form can be cloned");
    }
    JSForm parent = (JSForm) newParentForm;
    if (parent == null) {
        parent = (JSForm) ((JSBase) component).getJSParent();
    }
    parent.checkModification();
    Form form = parent.getSupportChild();
    FlattenedSolution fs = application.getFlattenedSolution();
    fs.clonePersist(((JSBase) component).getBaseComponent(false), IdentDocumentValidator.checkName(newName), form);
    return parent.getComponent(newName);
}
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 65 with Form

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

the class JSSolutionModel method removeForm.

/**
 * Removes the specified form during the persistent connected client session.
 *
 * NOTE: Make sure you call history.remove first in your Servoy method (script).
 *
 * @sample
 * //first remove it from the current history, to destroy any active form instance
 * var success = history.removeForm('myForm')
 * //removes the named form from this session, please make sure you called history.remove() first
 * if(success)
 * {
 * 	solutionModel.removeForm('myForm')
 * }
 *
 * @param name the specified name of the form to remove
 *
 * @return true is form has been removed, false if form could not be removed
 */
@JSFunction
public boolean removeForm(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form form = fs.getForm(name);
    if (form != null) {
        if (application.getFormManager().removeForm(form)) {
            fs.deletePersistCopy(form, false);
            return true;
        }
    }
    return false;
}
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)

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