Search in sources :

Example 1 with ComponentTypeFormElementValue

use of com.servoy.j2db.server.ngclient.property.ComponentTypeFormElementValue in project servoy-client by Servoy.

the class FormComponentSabloValue method getComponents.

private ComponentTypeSabloValue[] getComponents() {
    FormComponentCache formComponentCache = getCache();
    if (currentFormComponentCache != formComponentCache) {
        List<FormElement> elements = formComponentCache.getFormComponentElements();
        List<ComponentTypeSabloValue> componentsList = new ArrayList<ComponentTypeSabloValue>(elements.size());
        PropertyPath path = new PropertyPath();
        path.add(component.getName());
        path.add("containedForm");
        path.add("childElements");
        JSONObject tags = new JSONObject();
        tags.put(ComponentTypeSabloValue.TAG_ADD_TO_ELEMENTS_SCOPE, true);
        PropertyDescription compPd = new PropertyDescriptionBuilder().withName(pd.getName()).withType(ComponentPropertyType.INSTANCE).withConfig(pd.getConfig()).withTags(tags).build();
        int j = 0;
        for (FormElement element : elements) {
            path.add(j);
            ComponentTypeFormElementValue elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, element, dal.getApplication().getFlattenedSolution());
            ComponentTypeSabloValue ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, element, component, dal);
            if (ctsv != null) {
                // if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
                j++;
                componentsList.add(ctsv);
            }
            path.backOneLevel();
            if (element.getWebComponentSpec() != null) {
                Collection<PropertyDescription> properties = element.getWebComponentSpec().getProperties(FormComponentPropertyType.INSTANCE);
                if (properties.size() > 0) {
                    for (PropertyDescription pd : properties) {
                        Object propertyValue = element.getPropertyValue(pd.getName());
                        Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, dal.getApplication().getFlattenedSolution());
                        if (frm == null)
                            continue;
                        FormComponentCache innerCache = FormElementHelper.INSTANCE.getFormComponentCache(element, pd, (JSONObject) propertyValue, frm, dal.getApplication().getFlattenedSolution());
                        List<FormElement> innerElements = innerCache.getFormComponentElements();
                        for (FormElement innerElement : innerElements) {
                            path.add(j);
                            elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, innerElement, dal.getApplication().getFlattenedSolution());
                            // use main property
                            ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, innerElement, component, dal);
                            if (ctsv != null) {
                                // if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
                                j++;
                                componentsList.add(ctsv);
                            }
                            path.backOneLevel();
                        }
                    }
                }
            }
        }
        // re-attach
        if (currentFormComponentCache != null && changeMonitor != null && webObjectContext != null) {
            for (ComponentTypeSabloValue componentTypeSabloValue : componentsList) {
                componentTypeSabloValue.attachToBaseObject(changeMonitor, webObjectContext);
            }
        }
        currentFormComponentCache = formComponentCache;
        components = componentsList.toArray(new ComponentTypeSabloValue[0]);
    }
    return components;
}
Also used : FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) Form(com.servoy.j2db.persistence.Form) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) ArrayList(java.util.ArrayList) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) ComponentTypeSabloValue(com.servoy.j2db.server.ngclient.property.ComponentTypeSabloValue) ComponentTypeFormElementValue(com.servoy.j2db.server.ngclient.property.ComponentTypeFormElementValue) PropertyDescription(org.sablo.specification.PropertyDescription) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

Form (com.servoy.j2db.persistence.Form)1 FormElement (com.servoy.j2db.server.ngclient.FormElement)1 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)1 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)1 ComponentTypeFormElementValue (com.servoy.j2db.server.ngclient.property.ComponentTypeFormElementValue)1 ComponentTypeSabloValue (com.servoy.j2db.server.ngclient.property.ComponentTypeSabloValue)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1 PropertyDescription (org.sablo.specification.PropertyDescription)1 PropertyDescriptionBuilder (org.sablo.specification.PropertyDescriptionBuilder)1