Search in sources :

Example 11 with AbstractContainer

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

the class JSBaseContainer method getWebComponents.

/**
 * Returns all JSWebComponents of this form/container.
 * If this method is called on a form, then it will return all web components on that form.
 * If the form is responsive, it will return the web components from all the containers.
 *
 * @sample
 * var webComponents = myForm.getWebComponents(false);
 * for (var i in webComponents)
 * {
 * 	if (webComponents[i].name != null)
 * 		application.output(webComponents[i].name);
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return the list of all JSWebComponents on this forms
 */
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSWebComponent[] getWebComponents(boolean returnInheritedElements) {
    List<JSWebComponent> webComponents = new ArrayList<JSWebComponent>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<WebComponent> iterator = form2use.getWebComponents();
    while (iterator.hasNext()) {
        WebComponent webComponent = iterator.next();
        webComponents.add(createWebComponent(getCorrectIJSParent(this, webComponent), webComponent, application, false));
    }
    return webComponents.toArray(new JSWebComponent[webComponents.size()]);
}
Also used : WebComponent(com.servoy.j2db.persistence.WebComponent) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 12 with AbstractContainer

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

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

AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)13 ArrayList (java.util.ArrayList)10 JSFunction (org.mozilla.javascript.annotations.JSFunction)9 Form (com.servoy.j2db.persistence.Form)4 Point (java.awt.Point)4 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)3 IPersist (com.servoy.j2db.persistence.IPersist)3 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 WebComponent (com.servoy.j2db.persistence.WebComponent)2 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 Bean (com.servoy.j2db.persistence.Bean)1 Field (com.servoy.j2db.persistence.Field)1 IBasicWebComponent (com.servoy.j2db.persistence.IBasicWebComponent)1 IFormElement (com.servoy.j2db.persistence.IFormElement)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)1