Search in sources :

Example 11 with LayoutContainer

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

the class JSBaseContainer method getLayoutContainers.

/**
 * Returns all JSLayoutContainers objects of this container
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var containers = frm.getLayoutContainers();
 * for (var c in containers)
 * {
 * 		var fname = containers[c].name;
 * 		application.output(fname);
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return all JSLayoutContainers objects of this container
 */
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSLayoutContainer[] getLayoutContainers(boolean returnInheritedElements) {
    List<JSLayoutContainer> containers = new ArrayList<JSLayoutContainer>();
    AbstractContainer container = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<LayoutContainer> iterator = container.getLayoutContainers();
    while (iterator.hasNext()) {
        containers.add(application.getScriptEngine().getSolutionModifier().createLayoutContainer(this, iterator.next()));
    }
    return containers.toArray(new JSLayoutContainer[containers.size()]);
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 12 with LayoutContainer

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

the class DesignFormLayoutStructureGenerator method generateLayoutContainer.

public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, int nested) {
    WebLayoutSpecification spec = null;
    if (container.getPackageName() != null) {
        PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
        if (pkg != null) {
            spec = pkg.getSpecification(container.getSpecName());
        }
    }
    writer.print("<");
    writer.print(container.getTagType());
    if (container.getName() != null) {
        writer.print(" svy-name='");
        writer.print(container.getName());
        writer.print("' ");
    }
    if (container.getElementId() != null) {
        writer.print(" id='");
        writer.print(container.getElementId());
        writer.print("' ");
    }
    Map<String, String> attributes = new HashMap<String, String>(container.getMergedAttributes());
    if (spec != null) {
        for (String propertyName : spec.getAllPropertiesNames()) {
            PropertyDescription pd = spec.getProperty(propertyName);
            if (pd.getDefaultValue() != null && !attributes.containsKey(propertyName)) {
                attributes.put(propertyName, pd.getDefaultValue().toString());
            }
        }
    }
    for (Entry<String, String> entry : attributes.entrySet()) {
        writer.print(" ");
        try {
            StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
            if (entry.getValue() != null && entry.getValue().length() > 0) {
                writer.print("=\"");
                StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
                writer.print("\"");
            }
        } catch (IOException e) {
            Debug.error(e);
        }
    }
    writer.print(" svy-id='");
    writer.print(container.getID());
    writer.print("'");
    writer.print(">\n");
    Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    while (components.hasNext()) {
        int count = 0;
        while (count++ < nested) {
            writer.print('\t');
        }
        IPersist component = components.next();
        if (component instanceof LayoutContainer) {
            generateLayoutContainer((LayoutContainer) component, form, fs, writer, nested + 1);
        } else if (component instanceof IFormElement) {
            generateFormElement(writer, (IFormElement) component, form, fs);
        }
    }
    int count = 1;
    while (count++ < nested) {
        writer.print('\t');
    }
    writer.print("</");
    writer.print(container.getTagType());
    writer.print(">\n");
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) PropertyDescription(org.sablo.specification.PropertyDescription) WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer)

Example 13 with LayoutContainer

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

the class FormLayoutStructureGenerator method generateLayout.

public static void generateLayout(Form form, String realFormName, FlattenedSolution fs, PrintWriter writer, DesignProperties design) {
    try {
        FormLayoutGenerator.generateFormStartTag(writer, form, realFormName, false, design != null);
        Iterator<IPersist> components = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        while (components.hasNext()) {
            IPersist component = components.next();
            if (component instanceof LayoutContainer) {
                generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, FormElementHelper.INSTANCE);
            } else if (component instanceof IFormElement) {
                FormLayoutGenerator.generateFormElement(writer, FormElementHelper.INSTANCE.getFormElement((IFormElement) component, fs, null, false), form);
            }
        }
        FormLayoutGenerator.generateFormEndTag(writer, design != null);
    } catch (Exception e) {
        Debug.error(e);
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) IOException(java.io.IOException)

Example 14 with LayoutContainer

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

the class ChildrenJSONGenerator method visit.

@SuppressWarnings("nls")
@Override
public Object visit(IPersist o) {
    if (o == skip)
        return IPersistVisitor.CONTINUE_TRAVERSAL;
    if (!isSecurityVisible(o))
        return IPersistVisitor.CONTINUE_TRAVERSAL;
    if (o instanceof IFormElement) {
        FormElement fe = null;
        if (part != null) {
            int startPos = form.getPartStartYPos(part.getID());
            int endPos = part.getHeight();
            Point location = CSSPositionUtils.getLocation((IFormElement) o);
            if (location != null && (startPos > location.y || endPos <= location.y)) {
                return IPersistVisitor.CONTINUE_TRAVERSAL;
            }
        }
        if (cache != null) {
            // this is for form component elements finding
            fe = cache.getFormElement((IFormElement) o, this.context.getSolution(), null, designer);
        }
        if (fe == null && formUI != null) {
            List<FormElement> cachedFormElements = formUI.getFormElements();
            for (FormElement cachedFE : cachedFormElements) {
                if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), o)) {
                    fe = cachedFE;
                    break;
                }
            }
        }
        fe = fe != null ? fe : FormElementHelper.INSTANCE.getFormElement((IFormElement) o, this.context.getSolution(), null, designer);
        writer.object();
        writeFormElement(writer, o, form, fe, formUI, context, designer);
        if (o instanceof WebComponent) {
            WebObjectSpecification spec = fe.getWebComponentSpec();
            if (spec != null) {
                Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
                if (properties.size() > 0) {
                    boolean isResponsive = false;
                    List<String> children = new ArrayList<>();
                    for (PropertyDescription pd : properties) {
                        Object propertyValue = fe.getPropertyValue(pd.getName());
                        Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
                        if (frm == null)
                            continue;
                        isResponsive = frm.isResponsiveLayout();
                        // listformcomponents that are responsive must be also send over here (the components are also send over in the FormComponentSabloValue)
                        // this will result in duplicate component data, but we need the structure (and the component names in the right place)
                        // if (!isResponsive && pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig)pd.getConfig()).forFoundset != null)
                        // continue;
                        children.add("children_" + pd.getName());
                        writer.key("children_" + pd.getName());
                        writer.array();
                        FormComponentCache fccc = FormElementHelper.INSTANCE.getFormComponentCache(fe, pd, (JSONObject) propertyValue, frm, context.getSolution());
                        if (isResponsive) {
                            // layout containers are not in the cache we need to generate manually the model
                            frm.acceptVisitor(new ChildrenJSONGenerator(writer, context, frm, new IFormElementCache() {

                                @Override
                                public FormElement getFormElement(IFormElement component, FlattenedSolution flattendSol, PropertyPath path, boolean design) {
                                    for (FormElement formElement : fccc.getFormComponentElements()) {
                                        if (component.getID() == formElement.getPersistIfAvailable().getID()) {
                                            return formElement;
                                        }
                                    }
                                    return FormElementHelper.INSTANCE.getFormElement(component, flattendSol, path, design);
                                }
                            }, null, this.form, false, designer), PositionComparator.XY_PERSIST_COMPARATOR);
                        } else {
                            for (FormElement element : fccc.getFormComponentElements()) {
                                IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
                                persistOfElement.acceptVisitor(new ChildrenJSONGenerator(writer, context, null, null, null, this.form, false, designer), FORM_INDEX_WITH_HIERARCHY_COMPARATOR);
                            }
                        }
                        writer.endArray();
                    }
                    writer.key("formComponent");
                    writer.array();
                    children.stream().forEach((child) -> writer.value(child));
                    writer.endArray();
                }
            }
        }
        writer.endObject();
    } else if (o instanceof LayoutContainer) {
        writer.object();
        LayoutContainer layoutContainer = (LayoutContainer) o;
        writeLayoutContainer(writer, layoutContainer, formUI, designer);
        writer.key("children");
        writer.array();
        o.acceptVisitor(new ChildrenJSONGenerator(writer, context, o, cache, null, this.form, false, designer), PositionComparator.XY_PERSIST_COMPARATOR);
        writer.endArray();
        writer.endObject();
        return IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
    }
    return IPersistVisitor.CONTINUE_TRAVERSAL;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) Point(java.awt.Point) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) WebComponent(com.servoy.j2db.persistence.WebComponent) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) PropertyPath(com.servoy.j2db.server.ngclient.property.types.PropertyPath) JSONObject(org.json.JSONObject)

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