Search in sources :

Example 1 with LayoutContainer

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

the class ContainersScope method fillNames.

private static void fillNames(Iterator<LayoutContainer> iterator, Map<String, List<String>> namesToLayout, FlattenedSolution fs) {
    while (iterator.hasNext()) {
        LayoutContainer lc = iterator.next();
        if (lc.getName() != null) {
            WebLayoutSpecification spec = null;
            if (lc.getPackageName() != null) {
                PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(lc.getPackageName());
                if (pkg != null) {
                    spec = pkg.getSpecification(lc.getSpecName());
                }
            }
            if (spec != null) {
                List<String> styleClassValues = new ArrayList<String>();
                String cssClasses = lc.getCssClasses();
                if (cssClasses != null) {
                    styleClassValues.addAll(Arrays.asList(cssClasses.split(" ")));
                }
                namesToLayout.put(lc.getName(), styleClassValues);
            } else {
                Debug.warn("Couldn't register form container '" + lc.getName() + "' to the 'containers' because spec '" + lc.getPackageName() + "' not found");
            }
        }
        fillNames(lc.getLayoutContainers(), namesToLayout, fs);
        findFormComponentContainers(lc.getWebComponents(), namesToLayout, fs);
    }
}
Also used : WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList)

Example 2 with LayoutContainer

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

the class FormLayoutGenerator method generateFormComponent.

public static String generateFormComponent(Form form, FlattenedSolution fs, IFormElementCache cache) {
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    Iterator<? extends IPersist> componentsIterator = null;
    if (!form.isResponsiveLayout()) {
        List<IPersist> components = fs.getFlattenedForm(form).getAllObjectsAsList();
        List<IFormElement> formElements = new ArrayList<>();
        for (IPersist persist : components) {
            if (persist instanceof IFormElement) {
                formElements.add((IFormElement) persist);
            }
        }
        Collections.sort(formElements, new Comparator<IFormElement>() {

            public int compare(IFormElement o1, IFormElement o2) {
                int result = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR.compare(o1, o2);
                if (result == 0) {
                    result = TabSeqComparator.compareTabSeq(getTabSeq(o1), o1, getTabSeq(o2), o2);
                }
                return result;
            }
        });
        componentsIterator = formElements.iterator();
    } else {
        componentsIterator = fs.getFlattenedForm(form).getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    }
    while (componentsIterator.hasNext()) {
        IPersist component = componentsIterator.next();
        // if (PartWrapper.isSecurityVisible(component, fs, form))
        if (component instanceof LayoutContainer) {
            FormLayoutStructureGenerator.generateLayoutContainer((LayoutContainer) component, form, fs, writer, null, cache);
        } else if (component instanceof IFormElement) {
            FormElement fe = cache.getFormElement((IFormElement) component, fs, null, false);
            if (form != null && !form.isResponsiveLayout()) {
                FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, form.isResponsiveLayout());
            }
            FormLayoutGenerator.generateFormElement(writer, fe, form);
            if (form != null && !form.isResponsiveLayout()) {
                FormLayoutGenerator.generateEndDiv(writer);
            }
        }
    }
    return out.getBuffer().toString();
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) StringWriter(java.io.StringWriter) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) ArrayList(java.util.ArrayList) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) PrintWriter(java.io.PrintWriter)

Example 3 with LayoutContainer

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

the class FormLayoutStructureGenerator method isEvenLayoutContainer.

public static boolean isEvenLayoutContainer(LayoutContainer c) {
    int i = 0;
    LayoutContainer container = c;
    while (container.getParent() instanceof LayoutContainer) {
        container = (LayoutContainer) container.getParent();
        i++;
    }
    return i % 2 == 0;
}
Also used : LayoutContainer(com.servoy.j2db.persistence.LayoutContainer)

Example 4 with LayoutContainer

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

the class FormLayoutStructureGenerator method generateLayoutContainer.

public static void generateLayoutContainer(LayoutContainer container, Form form, FlattenedSolution fs, PrintWriter writer, DesignProperties design, IFormElementCache cache) {
    WebLayoutSpecification spec = null;
    if (container.getPackageName() != null) {
        PackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().get(container.getPackageName());
        if (pkg != null) {
            spec = pkg.getSpecification(container.getSpecName());
        }
    }
    boolean isCSSPositionContainer = CSSPositionUtils.isCSSPositionContainer(spec);
    writer.print("<");
    writer.print(container.getTagType());
    Set<String> writtenAttributes = new HashSet<>();
    if (design != null) {
        writer.print(" svy-id='");
        writer.print(container.getUUID().toString());
        writer.print("'");
        writer.print(" svy-location='");
        writer.print(container.getLocation().x);
        writer.print("'");
        boolean highSet = false;
        JSONObject ngClass = new JSONObject();
        String layoutStyleClasses = "";
        String solutionStyleClasses = "";
        if (spec != null) {
            writer.print(" svy-layoutname='");
            writer.print(spec.getPackageName() + "." + spec.getName());
            writer.print("'");
            ngClass.put("svy-layoutcontainer", true);
            if (// is this inherited?
            !(container.getAncestor(IRepository.FORMS).getID() == form.getID())) {
                ngClass.put("inheritedElement", true);
            }
            String designClass = spec.getDesignStyleClass() != null && spec.getDesignStyleClass().length() > 0 ? spec.getDesignStyleClass() : "customDivDesign";
            if ("customDivDesign".equals(designClass) && hasSameDesignClassAsParent(container, spec)) {
                designClass = isEvenLayoutContainer(container) ? "customDivDesignOdd" : "customDivDesignEven";
            }
            highSet = true;
            if (design.mainContainer != container.getID()) {
                // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
                ngClass.put(designClass, "<showWireframe<");
            } else {
                writer.print(" data-maincontainer='true'");
                ngClass.put(designClass, "<false<");
            }
            // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
            ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
            List<String> containerStyleClasses = getStyleClassValues(spec, container.getCssClasses());
            solutionStyleClasses = getSolutionSpecificClasses(spec, container);
            if (!containerStyleClasses.isEmpty()) {
                layoutStyleClasses = containerStyleClasses.stream().collect(Collectors.joining(" "));
                writer.print(" class='" + layoutStyleClasses + "'");
            }
            if (container.getCssClasses() != null && container.getCssClasses().trim().length() > 0) {
                writtenAttributes.add("class");
            }
            if (spec.getAllowedChildren().size() > 0 || spec.getExcludedChildren() != null) {
                // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
                ngClass.put("drop_highlight", "<canContainDraggedElement('" + spec.getPackageName() + "." + spec.getName() + "')<");
            }
        }
        if (!highSet)
            ngClass.put("highlight_element", "<design_highlight=='highlight_element'<");
        if (ngClass.length() > 0) {
            writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
        }
        if (writtenAttributes.contains("class")) {
            writer.print(" svy-layout-class='" + layoutStyleClasses + "'");
            writer.print(" svy-solution-layout-class='" + solutionStyleClasses + "'");
        }
        writer.print(" svy-title='" + getLayouContainerTitle(container) + "'");
    }
    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("' ");
    }
    writer.print(" svy-autosave ");
    if (isCSSPositionContainer) {
        // we need to specify the height
        writer.print(" style='height:");
        writer.print(container.getSize().height);
        writer.print("px;position: relative;' ");
    }
    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());
            }
        }
    }
    String classes = attributes.get("class");
    if (classes == null)
        classes = "svy-layoutcontainer";
    else
        classes += " svy-layoutcontainer";
    attributes.put("class", classes);
    for (Entry<String, String> entry : attributes.entrySet()) {
        if (design != null && writtenAttributes.contains(entry.getKey()))
            continue;
        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(">");
    Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    while (components.hasNext()) {
        IPersist component = components.next();
        if (component instanceof LayoutContainer) {
            generateLayoutContainer((LayoutContainer) component, form, fs, writer, design, cache);
        } else if (component instanceof IFormElement) {
            FormElement fe = cache.getFormElement((IFormElement) component, fs, null, design != null);
            if (!isSecurityVisible(fs, fe.getPersistIfAvailable(), form)) {
                continue;
            }
            if (isCSSPositionContainer) {
                FormLayoutGenerator.generateFormElementWrapper(writer, fe, form, false);
            }
            FormLayoutGenerator.generateFormElement(writer, fe, form);
            if (isCSSPositionContainer) {
                FormLayoutGenerator.generateEndDiv(writer);
            }
        }
    }
    writer.print("</");
    writer.print(container.getTagType());
    writer.print(">");
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) PropertyDescription(org.sablo.specification.PropertyDescription) WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer) HashSet(java.util.HashSet)

Example 5 with LayoutContainer

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

the class JSLayoutContainer method checkModification.

@Override
public void checkModification() {
    parent.checkModification();
    LayoutContainer tempPersist = layoutContainer;
    if (!isCopy) {
        // then get the replace the item with the item of the copied relation.
        setLayoutContainer((LayoutContainer) parent.getSupportChild().getChild(getLayoutContainer().getUUID()));
        isCopy = true;
    }
    layoutContainer = (LayoutContainer) JSBase.getOverridePersistIfNeeded(tempPersist, layoutContainer, getJSParent());
}
Also used : FlattenedLayoutContainer(com.servoy.j2db.persistence.FlattenedLayoutContainer) LayoutContainer(com.servoy.j2db.persistence.LayoutContainer)

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