Search in sources :

Example 6 with BaseComponent

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

the class JSPortal method setY.

/**
 * @see com.servoy.j2db.scripting.solutionmodel.JSComponent#setY(int)
 */
@Override
@JSSetter
public void setY(int y) {
    int yDif = y - getY();
    Iterator<IPersist> allObjects = getBaseComponent(true).getAllObjects();
    while (allObjects.hasNext()) {
        IPersist persist = allObjects.next();
        if (persist instanceof BaseComponent) {
            BaseComponent baseComponent = (BaseComponent) persist;
            Point location = baseComponent.getLocation();
            ((BaseComponent) persist).setLocation(new Point(location.x, location.y + yDif));
        }
    }
    super.setY(y);
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) Point(java.awt.Point) Point(java.awt.Point) JSSetter(org.mozilla.javascript.annotations.JSSetter)

Example 7 with BaseComponent

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

the class FormLayoutGenerator method generateFormElementWrapper.

public static void generateFormElementWrapper(PrintWriter writer, FormElement fe, Form form, boolean isResponsive) {
    String designId = getDesignId(fe);
    String name = fe.getName();
    boolean selectable = fe.isFormComponentChild() ? name.indexOf('$' + FormElement.SVY_NAME_PREFIX) == -1 : true;
    if (designId != null) {
        writer.print("<div ng-style=\"layout('");
        writer.print(designId);
        writer.print("')\"");
        JSONObject ngClass = new JSONObject();
        ngClass.put("invisible_element", "<getDesignFormControllerScope().model('" + designId + "').svyVisible == false<".toString());
        // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
        ngClass.put("highlight_element", "<getDesignFormControllerScope().highlightElement('" + designId + "') == true<".toString());
        if (fe.isFormComponentChild()) {
            ngClass.put("formComponentChild", true);
        }
        writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
        String cls = "svy-wrapper";
        Form currentForm = form;
        if (form instanceof FlattenedForm)
            currentForm = ((FlattenedForm) form).getForm();
        if (fe.getPersistIfAvailable() != null && Utils.isInheritedFormElement(fe.getPersistIfAvailable(), currentForm)) {
            cls += !currentForm.equals(fe.getPersistIfAvailable().getAncestor(IRepository.FORMS)) ? " inherited_element" : " override_element";
        }
        writer.print(" class=\"" + cls + "\" ");
    } else {
        // calculations during link-phase based on the size of the parent container
        if (fe.getPersistIfAvailable() != null && "servoycore-listformcomponent".equals(fe.getTypeName())) {
            writer.print("<div svy-ng-style=\"layout.");
        } else {
            writer.print("<div ng-style=\"layout.");
        }
        writer.print(name);
        writer.print("\" class=\"svy-wrapper\" ");
    }
    if (!isResponsive && fe.getPersistIfAvailable() instanceof BaseComponent) {
        BaseComponent bc = (BaseComponent) fe.getPersistIfAvailable();
        String style = "";
        if (!form.getUseCssPosition().booleanValue() && !CSSPositionUtils.isInAbsoluteLayoutMode(bc)) {
            int anchors = bc.getAnchors();
            if (((anchors & IAnchorConstants.EAST) > 0) && ((anchors & IAnchorConstants.WEST) > 0)) {
                style += "min-width:" + bc.getSize().width + "px;";
            }
            if (((anchors & IAnchorConstants.NORTH) > 0) && ((anchors & IAnchorConstants.SOUTH) > 0)) {
                style += "min-height:" + bc.getSize().height + "px";
            }
        }
        if (!style.isEmpty()) {
            writer.print(" style='");
            writer.print(style);
            writer.print("'");
        }
    } else if (fe.getPersistIfAvailable() == null && "servoycore-portal".equals(fe.getTypeName()) && (form.getView() == IForm.LIST_VIEW || form.getView() == IFormConstants.VIEW_TYPE_LIST_LOCKED)) {
        writer.print(" style='min-width:");
        writer.print(form.getMinWidth());
        writer.print("px'");
    }
    if (designId != null) {
        writer.print(" svy-id='");
        writer.print(designId);
        writer.print("'");
        if (!selectable) {
            writer.print(" svy-non-selectable='noname'");
        }
        writer.print(" name='");
        writer.print(name);
        writer.print("'");
        List<String>[] typeAndPropertyNames = fe.getSvyTypesAndPropertiesNames();
        if (typeAndPropertyNames[0].size() > 0) {
            writer.print(" svy-types='");
            writer.print("[" + String.join(",", typeAndPropertyNames[0]) + "]");
            writer.print("'");
        }
        String directEditPropertyName = getDirectEditProperty(fe);
        if (directEditPropertyName != null) {
            writer.print(" directEditPropertyName='");
            writer.print(directEditPropertyName);
            writer.print("'");
        }
        List<String> forbiddenComponentNames = fe.getForbiddenComponentNames();
        if (forbiddenComponentNames.size() > 0) {
            writer.print(" svy-forbidden-components='");
            writer.print("[" + String.join(",", forbiddenComponentNames) + "]");
            writer.print("'");
        }
        if (isNotSelectable(fe))
            writer.print(" svy-non-selectable");
    }
    writer.print(">");
}
Also used : FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) BaseComponent(com.servoy.j2db.persistence.BaseComponent) JSONObject(org.json.JSONObject) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with BaseComponent

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

the class FormWrapper method getBodyComponents.

public Collection<BaseComponent> getBodyComponents() {
    Part part = getBodyPart();
    List<BaseComponent> baseComponents = new ArrayList<>();
    if (part == null)
        return baseComponents;
    int startPos = form.getPartStartYPos(part.getID());
    int endPos = part.getHeight();
    List<IFormElement> persists = form.getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    for (IFormElement persist : persists) {
        if (persist instanceof GraphicalComponent && isTableView && ((GraphicalComponent) persist).getLabelFor() != null)
            continue;
        Point location = CSSPositionUtils.getLocation(persist);
        if (startPos <= location.y && endPos > location.y) {
            if (isSecurityVisible(persist))
                baseComponents.add((BaseComponent) persist);
        }
    }
    return baseComponents;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) BaseComponent(com.servoy.j2db.persistence.BaseComponent) Part(com.servoy.j2db.persistence.Part) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) Point(java.awt.Point) Point(java.awt.Point)

Example 9 with BaseComponent

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

the class PartWrapper method getBaseComponents.

public static Collection<BaseComponent> getBaseComponents(Part part, Form context, IServoyDataConverterContext converterContext, boolean isDesign, boolean flatten) {
    if (!isDesign && part.getPartType() == Part.BODY) {
        switch(context.getView()) {
            case FormController.TABLE_VIEW:
            case FormController.LOCKED_TABLE_VIEW:
            case IForm.LIST_VIEW:
            case FormController.LOCKED_LIST_VIEW:
                return Arrays.asList(new BaseComponent[] { new BodyPortal(context) });
        }
    }
    List<BaseComponent> baseComponents = new ArrayList<>();
    int startPos = context.getPartStartYPos(part.getID());
    int endPos = part.getHeight();
    Comparator<? super IFormElement> comparator = null;
    if (context.isResponsiveLayout()) {
        comparator = PositionComparator.XY_PERSIST_COMPARATOR;
    } else {
        comparator = FlattenedForm.FORM_INDEX_WITH_HIERARCHY_COMPARATOR;
    }
    List<IFormElement> persists = null;
    if (flatten) {
        persists = context.getFlattenedObjects(comparator);
    } else {
        persists = new ArrayList(context.getAllObjectsAsList());
        Iterator<IFormElement> it = persists.iterator();
        while (it.hasNext()) {
            IPersist persist = it.next();
            if (!(persist instanceof BaseComponent)) {
                it.remove();
            }
        }
        Collections.sort(persists, comparator);
    }
    for (IFormElement persist : persists) {
        Point location = CSSPositionUtils.getLocation(persist);
        if (startPos <= location.y && endPos > location.y && persist instanceof BaseComponent) {
            if (isSecurityVisible(persist, converterContext.getSolution(), context))
                baseComponents.add((BaseComponent) persist);
        }
    }
    return baseComponents;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) BodyPortal(com.servoy.j2db.server.ngclient.BodyPortal) ArrayList(java.util.ArrayList) Point(java.awt.Point) Point(java.awt.Point)

Example 10 with BaseComponent

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

Aggregations

BaseComponent (com.servoy.j2db.persistence.BaseComponent)15 Point (java.awt.Point)10 IPersist (com.servoy.j2db.persistence.IPersist)8 Part (com.servoy.j2db.persistence.Part)7 ArrayList (java.util.ArrayList)5 Form (com.servoy.j2db.persistence.Form)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IFormElement (com.servoy.j2db.persistence.IFormElement)4 JSONObject (org.json.JSONObject)3 IForm (com.servoy.j2db.IForm)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 Portal (com.servoy.j2db.persistence.Portal)2 TabPanel (com.servoy.j2db.persistence.TabPanel)2 BodyPortal (com.servoy.j2db.server.ngclient.BodyPortal)2 IComponent (com.servoy.j2db.ui.IComponent)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2