Search in sources :

Example 31 with Part

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

the class CSSPositionPropertyType method toJSON.

private JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, FormElement formElement, FlattenedSolution fs, Form context) throws JSONException {
    JSONUtils.addKeyIfPresent(writer, key);
    writer.object();
    if (object != null) {
        writer.key("position").value("absolute");
        String top = object.top;
        String bottom = object.bottom;
        if (formElement != null && fs != null && context != null && !formElement.isInDesigner()) {
            // adjust the top for parts.
            IPersist persist = formElement.getPersistIfAvailable();
            if (persist instanceof BaseComponent) {
                AbstractContainer parentContainer = CSSPositionUtils.getParentContainer((BaseComponent) persist);
                Point location = CSSPositionUtils.getLocation(object, parentContainer.getSize());
                Form form = fs.getFlattenedForm(context);
                Part part = form.getPartAt(location.y);
                if (part != null) {
                    if (isSet(top)) {
                        int topStart = form.getPartStartYPos(part.getID());
                        if (topStart > 0) {
                            if (top.endsWith("px")) {
                                top = top.substring(0, top.length() - 2);
                            }
                            int topInteger = Utils.getAsInteger(top, -1);
                            if (topInteger != -1) {
                                top = String.valueOf(topInteger - topStart);
                            } else {
                                top = "calc(" + top + " - " + topStart + "px)";
                            }
                        }
                    }
                    if (isSet(bottom)) {
                        int extraHeight = form.getSize().height - part.getHeight();
                        if (extraHeight > 0) {
                            if (bottom.endsWith("px")) {
                                bottom = bottom.substring(0, bottom.length() - 2);
                            }
                            int bottomInteger = Utils.getAsInteger(bottom, -1);
                            if (bottomInteger != -1) {
                                bottom = String.valueOf(bottomInteger - extraHeight);
                            } else {
                                bottom = "calc(" + bottom + " - " + extraHeight + "px)";
                            }
                        }
                    }
                }
            }
        }
        if (isSet(top))
            writer.key("top").value(addPixels(top));
        if (isSet(object.left))
            writer.key("left").value(addPixels(object.left));
        if (isSet(bottom))
            writer.key("bottom").value(addPixels(bottom));
        if (isSet(object.right))
            writer.key("right").value(addPixels(object.right));
        if (isSet(object.height)) {
            if (isSet(top) && isSet(object.bottom)) {
                writer.key("min-height").value(addPixels(object.height));
            } else
                writer.key("height").value(addPixels(object.height));
        }
        if (isSet(object.width)) {
            if (isSet(object.left) && isSet(object.right)) {
                writer.key("min-width").value(addPixels(object.width));
            } else
                writer.key("width").value(addPixels(object.width));
        }
    }
    writer.endObject();
    return writer;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) IPersist(com.servoy.j2db.persistence.IPersist) Form(com.servoy.j2db.persistence.Form) Part(com.servoy.j2db.persistence.Part) Point(java.awt.Point) Point(java.awt.Point)

Example 32 with Part

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

the class WebFormUI method getPartHeight.

@Override
public int getPartHeight(int partType) {
    int totalHeight = 0;
    int bodyHeight = 0;
    for (Part part : Utils.iterate(formController.getForm().getParts())) {
        if (partType != Part.BODY) {
            if (part.getPartType() == partType) {
                return part.getHeight() - totalHeight;
            }
        }
        if (part.getPartType() == Part.BODY) {
            bodyHeight = part.getHeight() - totalHeight;
        }
        totalHeight = part.getHeight();
    }
    if (partType == Part.BODY) {
        Dimension size = (Dimension) properties.get("size");
        if (size != null)
            return size.height - totalHeight + bodyHeight;
        return bodyHeight;
    }
    return 0;
}
Also used : Part(com.servoy.j2db.persistence.Part) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 33 with Part

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

the class FormElementHelper method getRowHeight.

private int getRowHeight(Form form) {
    int rowHeight = 0;
    Part part = getBodyPart(form);
    int startPos = form.getPartStartYPos(part.getID());
    int endPos = part.getHeight();
    Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    while (it.hasNext()) {
        IPersist persist = it.next();
        if (persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
            continue;
        if (persist instanceof BaseComponent) {
            BaseComponent bc = (BaseComponent) persist;
            Point location = bc.getLocation();
            if (startPos <= location.y && endPos > location.y) {
                if (rowHeight == 0) {
                    rowHeight = bc.getSize().height;
                    break;
                }
            }
        }
    }
    return rowHeight == 0 ? 20 : rowHeight;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Point(java.awt.Point) Point(java.awt.Point)

Example 34 with Part

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

the class FormElementHelper method createBodyPortalFormElement.

private FormElement createBodyPortalFormElement(BodyPortal listViewPortal, FlattenedSolution fs, final boolean isInDesigner) {
    Form form = listViewPortal.getForm();
    Part bodyPart = null;
    for (Part prt : Utils.iterate(form.getParts())) {
        if (prt.getPartType() == Part.BODY) {
            bodyPart = prt;
            break;
        }
    }
    if (bodyPart != null) {
        try {
            String name = "svy_lvp_" + form.getName();
            int startPos = form.getPartStartYPos(bodyPart.getID());
            int endPos = bodyPart.getHeight();
            int bodyheight = endPos - startPos;
            JSONObject portal = new JSONObject();
            portal.put("name", name);
            portal.put("multiLine", !listViewPortal.isTableview());
            portal.put("rowHeight", !listViewPortal.isTableview() ? bodyheight : getRowHeight(form));
            int scrollbars = form.getScrollbars();
            if (!listViewPortal.isTableview()) {
                // handle horizontal scrollbar on form level for listview
                int verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_AS_NEEDED;
                if ((form.getScrollbars() & ISupportScrollbars.VERTICAL_SCROLLBAR_ALWAYS) != 0) {
                    verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_ALWAYS;
                } else if ((form.getScrollbars() & ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER) != 0) {
                    verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER;
                }
                scrollbars = ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER + verticalScrollBars;
            }
            portal.put("scrollbars", scrollbars);
            if (listViewPortal.isTableview()) {
                int headerHeight = 30;
                if (form.hasPart(Part.HEADER)) {
                    headerHeight = 0;
                }
                portal.put("headerHeight", headerHeight);
                portal.put("sortable", form.getOnSortCmdMethodID() != -1);
            }
            portal.put("readOnlyMode", form.getNgReadOnlyMode());
            JSONObject location = new JSONObject();
            location.put("x", 0);
            location.put("y", isInDesigner ? startPos : 0);
            portal.put("location", location);
            JSONObject size = new JSONObject();
            // size.put("width", (listViewPortal.isTableview() && !fillsWidth) ? getGridWidth(form) : form.getWidth());
            size.put("width", form.getWidth());
            size.put("height", bodyheight);
            portal.put("size", size);
            portal.put("visible", listViewPortal.getVisible());
            portal.put("enabled", listViewPortal.getEnabled());
            // empty contents; will be updated afterwards directly with form element values for components
            portal.put("childElements", new JSONArray());
            JSONObject relatedFoundset = new JSONObject();
            relatedFoundset.put("foundsetSelector", "");
            portal.put("relatedFoundset", relatedFoundset);
            PropertyPath propertyPath = new PropertyPath();
            propertyPath.setShouldAddElementName();
            FormElement portalFormElement = new FormElement("servoycore-portal", portal, form, name, fs, propertyPath, isInDesigner);
            PropertyDescription pd = portalFormElement.getWebComponentSpec().getProperties().get("childElements");
            if (pd != null)
                pd = ((CustomJSONArrayType<?, ?>) pd.getType()).getCustomJSONTypeDefinition();
            if (pd == null) {
                Debug.error(new RuntimeException("Cannot find component definition special type to use for portal."));
                return null;
            }
            ComponentPropertyType type = ((ComponentPropertyType) pd.getType());
            Map<String, Object> portalFormElementProperties = new HashMap<>(portalFormElement.getRawPropertyValues());
            portalFormElementProperties.put("anchors", IAnchorConstants.ALL);
            portalFormElementProperties.put("offsetY", startPos);
            portalFormElementProperties.put("partHeight", bodyPart.getHeight());
            portalFormElementProperties.put("formview", true);
            // now put real child component form element values in "childElements"
            Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            // contains actually ComponentTypeFormElementValue objects
            List<Object> children = new ArrayList<>();
            List<IPersist> labelFors = new ArrayList<>();
            propertyPath.add(portalFormElement.getName());
            propertyPath.add("childElements");
            // it's a generated table-view form portal (BodyPortal); we just
            // have to set the Portal's tabSeq to the first one of it's children for it to work properly
            int minBodyPortalTabSeq = -2;
            while (it.hasNext()) {
                IPersist persist = it.next();
                if (persist instanceof IFormElement) {
                    Point loc = CSSPositionUtils.getLocation((IFormElement) persist);
                    if (startPos <= loc.y && endPos > loc.y) {
                        if (listViewPortal.isTableview() && persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
                            continue;
                        propertyPath.add(children.size());
                        FormElement fe = getFormElement((IFormElement) persist, fs, propertyPath, isInDesigner);
                        if (listViewPortal.isTableview()) {
                            String elementName = ((IFormElement) persist).getName();
                            Iterator<GraphicalComponent> graphicalComponents = form.getGraphicalComponents();
                            boolean hasLabelFor = false;
                            while (graphicalComponents.hasNext()) {
                                GraphicalComponent gc = graphicalComponents.next();
                                if (gc.getLabelFor() != null && Utils.equalObjects(elementName, gc.getLabelFor()) && startPos <= gc.getLocation().y && endPos > gc.getLocation().y) {
                                    labelFors.add(gc);
                                    hasLabelFor = true;
                                    break;
                                }
                            }
                            Map<String, Object> feRawProperties = new HashMap<>(fe.getRawPropertyValues());
                            feRawProperties.put("componentIndex", Integer.valueOf(children.size()));
                            if (hasLabelFor)
                                feRawProperties.put("headerIndex", Integer.valueOf(labelFors.size() - 1));
                            fe.updatePropertyValuesDontUse(feRawProperties);
                        }
                        children.add(type.getFormElementValue(null, pd, propertyPath, fe, fs));
                        propertyPath.backOneLevel();
                        Collection<PropertyDescription> tabSequenceProperties = fe.getWebComponentSpec().getProperties(NGTabSeqPropertyType.NG_INSTANCE);
                        for (PropertyDescription tabSeqProperty : tabSequenceProperties) {
                            String tabSeqPropertyName = tabSeqProperty.getName();
                            Integer tabSeqVal = (Integer) fe.getPropertyValue(tabSeqPropertyName);
                            // default is 0 == DEFAULT tab sequence
                            if (tabSeqVal == null)
                                tabSeqVal = Integer.valueOf(0);
                            if (minBodyPortalTabSeq < 0 || (minBodyPortalTabSeq > tabSeqVal.intValue() && tabSeqVal.intValue() >= 0))
                                minBodyPortalTabSeq = tabSeqVal.intValue();
                        }
                    }
                }
            }
            propertyPath.backOneLevel();
            propertyPath.backOneLevel();
            portalFormElementProperties.put("childElements", children.toArray());
            if (listViewPortal.isTableview()) {
                propertyPath.add("headers");
                List<Object> headers = new ArrayList<>();
                for (IPersist persist : labelFors) {
                    if (persist instanceof IFormElement) {
                        propertyPath.add(headers.size());
                        FormElement fe = getFormElement((IFormElement) persist, fs, propertyPath, isInDesigner);
                        headers.add(type.getFormElementValue(null, pd, propertyPath, fe, fs));
                        propertyPath.backOneLevel();
                    }
                }
                propertyPath.backOneLevel();
                propertyPath.backOneLevel();
                portalFormElementProperties.put("headers", headers.toArray());
            }
            // table view tab seq. is the minimum of it's children tabSeq'es
            portalFormElementProperties.put("tabSeq", Integer.valueOf(minBodyPortalTabSeq));
            portalFormElement.updatePropertyValuesDontUse(portalFormElementProperties);
            return portalFormElement;
        } catch (JSONException ex) {
            Debug.error("Cannot create list view portal component", ex);
        }
    }
    return null;
}
Also used : FormComponentPropertyType(com.servoy.j2db.server.ngclient.property.types.FormComponentPropertyType) ComponentPropertyType(com.servoy.j2db.server.ngclient.property.ComponentPropertyType) Form(com.servoy.j2db.persistence.Form) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) CustomJSONArrayType(org.sablo.specification.property.CustomJSONArrayType) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Point(java.awt.Point) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) PropertyDescription(org.sablo.specification.PropertyDescription) IFormElement(com.servoy.j2db.persistence.IFormElement) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) PropertyPath(com.servoy.j2db.server.ngclient.property.types.PropertyPath) IBasicWebObject(com.servoy.j2db.persistence.IBasicWebObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IChildWebObject(com.servoy.j2db.persistence.IChildWebObject)

Example 35 with Part

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

the class FormElementHelper method fillsWidth.

private boolean fillsWidth(Form form) {
    if ((form.getScrollbars() & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) == ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) {
        Part part = getBodyPart(form);
        int startPos = form.getPartStartYPos(part.getID());
        int endPos = part.getHeight();
        Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
        while (it.hasNext()) {
            IPersist persist = it.next();
            if (persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
                continue;
            if (persist instanceof BaseComponent) {
                BaseComponent bc = (BaseComponent) persist;
                if ((bc.getAnchors() & (IAnchorConstants.WEST + IAnchorConstants.EAST)) == (IAnchorConstants.WEST + IAnchorConstants.EAST)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Point(java.awt.Point)

Aggregations

Part (com.servoy.j2db.persistence.Part)36 Point (java.awt.Point)17 Form (com.servoy.j2db.persistence.Form)14 IPersist (com.servoy.j2db.persistence.IPersist)9 IFormElement (com.servoy.j2db.persistence.IFormElement)8 Dimension (java.awt.Dimension)8 ArrayList (java.util.ArrayList)8 BaseComponent (com.servoy.j2db.persistence.BaseComponent)7 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)6 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)6 IStyleRule (com.servoy.j2db.util.IStyleRule)5 IStyleSheet (com.servoy.j2db.util.IStyleSheet)5 FormController (com.servoy.j2db.FormController)4 IForm (com.servoy.j2db.IForm)4 Color (java.awt.Color)4 Portal (com.servoy.j2db.persistence.Portal)3 IComponent (com.servoy.j2db.ui.IComponent)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3