Search in sources :

Example 6 with LayoutContainer

use of com.servoy.j2db.persistence.LayoutContainer 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 7 with LayoutContainer

use of com.servoy.j2db.persistence.LayoutContainer 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 8 with LayoutContainer

use of com.servoy.j2db.persistence.LayoutContainer 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 9 with LayoutContainer

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

the class JSLayoutContainer method getLayoutContainer.

private LayoutContainer getLayoutContainer() {
    if (!isCopy) {
        // as long as the layoutcontainer is not already a copy, we have to get the real one
        // so that changes to other instances of JSLayoutContainer that points to the same container are seen in this one.
        LayoutContainer lc = (LayoutContainer) parent.getSupportChild().getChild(layoutContainer.getUUID());
        layoutContainer = lc != null ? lc : layoutContainer;
    }
    return layoutContainer;
}
Also used : FlattenedLayoutContainer(com.servoy.j2db.persistence.FlattenedLayoutContainer) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer)

Example 10 with LayoutContainer

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

LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)14 ArrayList (java.util.ArrayList)6 Form (com.servoy.j2db.persistence.Form)5 IFormElement (com.servoy.j2db.persistence.IFormElement)5 IPersist (com.servoy.j2db.persistence.IPersist)5 WebLayoutSpecification (org.sablo.specification.WebLayoutSpecification)4 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)3 FlattenedLayoutContainer (com.servoy.j2db.persistence.FlattenedLayoutContainer)3 Point (java.awt.Point)3 IOException (java.io.IOException)3 JSONObject (org.json.JSONObject)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)2 FormElement (com.servoy.j2db.server.ngclient.FormElement)2 HashMap (java.util.HashMap)2 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)1 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 IFlattenedPersistWrapper (com.servoy.j2db.persistence.IFlattenedPersistWrapper)1