Search in sources :

Example 66 with Form

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

the class JSSolutionModel method newForm.

protected JSForm newForm(String name, String dataSource, String styleName, boolean show_in_menu, int width, int height, boolean isResponsive) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Style style = null;
        if (styleName != null) {
            style = fs.getStyle(styleName);
        }
        Form form = createNewForm(style, IdentDocumentValidator.checkName(name), dataSource, show_in_menu, new Dimension(width, height));
        if (!isResponsive) {
            form.createNewPart(Part.BODY, height);
        } else {
            form.setResponsiveLayout(true);
        }
        if (fs.getSolution().getSolutionType() == SolutionMetaData.MOBILE) {
            // mobile solution, make the form mobile
            form.putCustomMobileProperty(IMobileProperties.MOBILE_FORM.propertyName, Boolean.TRUE);
            // set internal style name
            form.setStyleName("_servoy_mobile");
        }
        application.getFormManager().addForm(form, false);
        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) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Style(com.servoy.j2db.persistence.Style) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Dimension(java.awt.Dimension)

Example 67 with Form

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

the class JSBase method getOverridePersistIfNeeded.

public static AbstractBase getOverridePersistIfNeeded(AbstractBase persist, AbstractBase finalPersist, IJSParent parent) {
    AbstractBase baseComponent = finalPersist;
    if (persist != null && persist.getAncestor(IRepository.FORMS) != null) {
        IJSParent<?> jsparent = parent;
        while (jsparent != null) {
            if (jsparent.getSupportChild() instanceof Form)
                break;
            jsparent = jsparent.getJSParent();
        }
        if (jsparent != null && jsparent.getSupportChild() instanceof Form && !jsparent.getSupportChild().getUUID().equals(persist.getAncestor(IRepository.FORMS).getUUID())) {
            // inherited persist
            try {
                IPersist parentPersist = persist;
                while (PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist) != null) {
                    parentPersist = PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist);
                }
                // first check if the override persist already exists, and return it in that case
                List<IPersist> children = PersistHelper.getHierarchyChildren((AbstractBase) parent.getSupportChild());
                IPersist form = parent.getSupportChild() instanceof Form ? parent.getSupportChild() : parent.getSupportChild().getAncestor(IRepository.FORMS);
                if (form != null) {
                    for (IPersist p : children) {
                        if (parentPersist.getID() == ((ISupportExtendsID) p).getExtendsID() && form.equals(p.getAncestor(IRepository.FORMS))) {
                            return (AbstractBase) p;
                        }
                    }
                } else {
                    // should not happen
                    Debug.error("Cannot find form of persist " + parent.getSupportChild());
                }
                baseComponent = (AbstractBase) persist.cloneObj(parent.getSupportChild(), false, null, false, false, false);
                baseComponent.copyPropertiesMap(null, true);
                ((ISupportExtendsID) baseComponent).setExtendsID(parentPersist.getID());
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    }
    return baseComponent;
}
Also used : Form(com.servoy.j2db.persistence.Form) IPersist(com.servoy.j2db.persistence.IPersist) ISupportExtendsID(com.servoy.j2db.persistence.ISupportExtendsID) AbstractBase(com.servoy.j2db.persistence.AbstractBase)

Example 68 with Form

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

the class JSBaseContainer method createLayoutContainer.

protected JSLayoutContainer createLayoutContainer(int x, int y, String spec, JSONObject config) {
    checkModification();
    try {
        AbstractContainer container = getContainer();
        Form form = (Form) container.getAncestor(IRepository.FORMS);
        if (form.isResponsiveLayout()) {
            String packageName = null;
            String specName = null;
            if (spec != null) {
                String[] split = spec.split("-");
                if (split.length == 1) {
                    specName = spec.trim();
                } else if (split.length == 2) {
                    specName = split[1].trim();
                    packageName = split[0].trim();
                } else {
                    Debug.warn("Illegal spec given: " + spec);
                }
            }
            if (specName == null || packageName == null) {
                if (container instanceof LayoutContainer) {
                    LayoutContainer parent = (LayoutContainer) (getContainer());
                    packageName = parent.getPackageName();
                    if (specName == null && parent.getAllowedChildren() != null && !parent.getAllowedChildren().isEmpty()) {
                        specName = parent.getAllowedChildren().get(0);
                        if (specName.contains("."))
                            specName = specName.split("\\.")[1];
                    }
                }
            }
            if (specName == null) {
                // the parent container could be a layout container or the form
                // check if we have a sibling of the container we want to create
                LayoutContainer sibling = container.getLayoutContainers().hasNext() ? container.getLayoutContainers().next() : null;
                if (sibling != null) {
                    packageName = sibling.getPackageName();
                    specName = sibling.getSpecName();
                }
            }
            LayoutContainer layoutContainer = getContainer().createNewLayoutContainer();
            layoutContainer.setLocation(new Point(x, y));
            layoutContainer.setPackageName(packageName);
            layoutContainer.setSpecName(specName);
            JSLayoutContainer jsLayoutContainer = application.getScriptEngine().getSolutionModifier().createLayoutContainer(this, layoutContainer);
            JSONObject conf = config;
            if (config == null) {
                Map<String, PackageSpecification<WebLayoutSpecification>> layoutSpecifications = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications();
                if (packageName != null && specName != null && layoutSpecifications != null && layoutSpecifications.get(packageName) != null) {
                    WebLayoutSpecification layoutSpec = layoutSpecifications.get(packageName).getSpecification(specName);
                    if (layoutSpec != null && (layoutSpec.getConfig() instanceof JSONObject || layoutSpec.getConfig() instanceof String)) {
                        conf = layoutSpec.getConfig() instanceof String ? new JSONObject((String) layoutSpec.getConfig()) : ((JSONObject) layoutSpec.getConfig());
                    }
                }
            }
            return configLayoutContainer(jsLayoutContainer, layoutContainer, conf);
        } else {
            // check if form was just created with the solution model and suggest correct method to use
            if (application.getFlattenedSolution().getSolutionCopy().getAllObjectsAsList().contains(form) && !application.getSolution().getAllObjectsAsList().contains(form)) {
                throw new RuntimeException("Form " + form.getName() + " is not a responsive form, cannot add a layout container on it. Please use solutionModel.newForm('" + form.getName() + "',true) to create a responsive form.");
            }
            throw new RuntimeException("Form " + form.getName() + " is not responsive, cannot add a layout container on it. Please use a responsive form or create a responsive form with solutionModel.newForm(formName, true);");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) Form(com.servoy.j2db.persistence.Form) Point(java.awt.Point) RepositoryException(com.servoy.j2db.persistence.RepositoryException) WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) JSONObject(org.json.JSONObject) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) PackageSpecification(org.sablo.specification.PackageSpecification)

Example 69 with Form

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

the class PersistHelper method getFlattenedPersist.

public static ISupportChilds getFlattenedPersist(FlattenedSolution flattenedSolution, Form parent, ISupportChilds persist) {
    ISupportChilds flattenedPersist = persist;
    if (flattenedPersist instanceof Form) {
        flattenedPersist = flattenedSolution.getFlattenedForm(flattenedPersist);
    }
    if (flattenedPersist instanceof LayoutContainer && !(flattenedPersist instanceof FlattenedLayoutContainer)) {
        FlattenedForm ff = flattenedSolution.getFlattenedForm(parent) instanceof FlattenedForm ? (FlattenedForm) flattenedSolution.getFlattenedForm(parent) : flattenedSolution.createFlattenedForm(parent);
        flattenedPersist = new FlattenedLayoutContainer(ff, (LayoutContainer) flattenedPersist);
    }
    return flattenedPersist;
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) FlattenedLayoutContainer(com.servoy.j2db.persistence.FlattenedLayoutContainer) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) FlattenedLayoutContainer(com.servoy.j2db.persistence.FlattenedLayoutContainer)

Example 70 with Form

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

the class PersistHelper method getSuperPersist.

public static IPersist getSuperPersist(final ISupportExtendsID persist) {
    if (persist instanceof IFlattenedPersistWrapper && ((IFlattenedPersistWrapper) persist).getWrappedPersist() instanceof Form) {
        return ((IFlattenedPersistWrapper<Form>) persist).getWrappedPersist().getExtendsForm();
    }
    if (persist instanceof Form) {
        return ((Form) persist).getExtendsForm();
    }
    final int extendsID = persist.getExtendsID();
    if (extendsID > 0) {
        try {
            Form form = (Form) ((AbstractBase) persist).getAncestor(IRepository.FORMS);
            if (form != null) {
                form = form.getExtendsForm();
                while (form != null) {
                    IPersist superPersist = form.getSuperPersist(extendsID);
                    // });
                    if (superPersist != null) {
                        return superPersist;
                    }
                    form = form.getExtendsForm();
                }
            }
        } finally {
        // System.err.println("getting super persist for " + persist.getID() + " extends: " + extendsID + " time " + (System.currentTimeMillis() - time));
        }
    }
    return null;
}
Also used : IFlattenedPersistWrapper(com.servoy.j2db.persistence.IFlattenedPersistWrapper) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) IPersist(com.servoy.j2db.persistence.IPersist) 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