Search in sources :

Example 1 with FormComponentCache

use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.

the class FormComponentSabloValue method getCache.

public FormComponentCache getCache() {
    Container parent = component.findParent(WebFormUI.class);
    if (parent instanceof WebFormUI) {
        // cache it on the FormUI object, because FormElementHelper can only cache when it is not solution model, but then the cache is constantly changing..
        FormComponentCache fcc = ((WebFormUI) parent).getFormComponentCache(component);
        if (fcc != null)
            return fcc;
        fcc = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
        ((WebFormUI) parent).cacheFormComponentCache(component, fcc);
        return fcc;
    }
    return FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
}
Also used : Container(org.sablo.Container) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)

Example 2 with FormComponentCache

use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache 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)

Example 3 with FormComponentCache

use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.

the class FormWrapper method checkFormComponents.

private void checkFormComponents(List<IFormElement> components, FormElement formComponentFormElement, Set<String> recursiveCheck) {
    // if it's not a form component then .spec will not contain properties of type FormComponentPropertyType.INSTANCE and nothing will happen below
    WebObjectSpecification spec = formComponentFormElement.getWebComponentSpec();
    if (spec != null) {
        Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
        if (properties.size() > 0) {
            for (PropertyDescription pd : properties) {
                Object config = pd.getConfig();
                boolean isRepeating = config instanceof ComponentTypeConfig && ((ComponentTypeConfig) config).forFoundset != null;
                Object propertyValue = formComponentFormElement.getPropertyValue(pd.getName());
                Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
                if (frm == null)
                    continue;
                if (!recursiveCheck.add(frm.getName())) {
                    // $NON-NLS-1$
                    Debug.error("recursive reference found between (List)FormComponents: " + recursiveCheck);
                    continue;
                }
                FormComponentCache cache = FormElementHelper.INSTANCE.getFormComponentCache(formComponentFormElement, pd, (JSONObject) propertyValue, frm, context.getSolution());
                Dimension frmSize = frm.getSize();
                for (FormElement element : cache.getFormComponentElements()) {
                    IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
                    if ((!isRepeating || design))
                        components.add(persistOfElement);
                    formComponentParentSizes.put(element.getName(), frmSize);
                    if (!frm.isResponsiveLayout()) {
                        formComponentsLayout.put(element.getName(), Boolean.TRUE);
                    }
                    if (frm.getUseCssPosition()) {
                        String name = element.getDesignId() != null ? element.getDesignId() : element.getName();
                        if (!formComponentCSSPositionElementNames.containsKey(name)) {
                            formComponentCSSPositionElementNames.put(name, Boolean.TRUE);
                        }
                    }
                    checkFormComponents(components, element, recursiveCheck);
                }
                formComponentTemplates.put(cache.getHtmlTemplateUUIDForAngular(), cache.getTemplate());
                recursiveCheck.remove(frm.getName());
            }
        }
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IFormElement(com.servoy.j2db.persistence.IFormElement) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) JSONObject(org.json.JSONObject) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 4 with FormComponentCache

use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.

the class FormComponentPropertyType method toSabloComponentValue.

@Override
public Object toSabloComponentValue(Object formElementValue, PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
    Form form = getForm(formElementValue, dataAdapterList.getApplication().getFlattenedSolution());
    if (form != null) {
        if (pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) pd.getConfig()).forFoundset != null) {
            return new FormComponentSabloValue(formElement, (JSONObject) formElementValue, pd, dataAdapterList, component, form);
        } else {
            FormComponentCache formComponentCache = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, (JSONObject) formElementValue, form, dataAdapterList.getApplication().getFlattenedSolution());
            List<FormElement> elements = formComponentCache.getFormComponentElements();
            IWebFormUI formUI = component.findParent(IWebFormUI.class);
            for (FormElement element : elements) {
                WebFormComponent child = ComponentFactory.createComponent(dataAdapterList.getApplication(), dataAdapterList, element, component.getParent(), dataAdapterList.getForm().getForm());
                formUI.contributeComponentToElementsScope(element, element.getWebComponentSpec(), child);
            }
        }
    }
    return formElementValue;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 5 with FormComponentCache

use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.

the class FormComponentPropertyType method toRhinoValue.

@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
    Scriptable newObject = DefaultScope.newObject(startScriptable);
    WebFormComponent webFormComponent = (WebFormComponent) componentOrService;
    FlattenedSolution fs = webFormComponent.getDataConverterContext().getSolution();
    FormComponentCache cache = null;
    if (webComponentValue instanceof FormComponentSabloValue) {
        cache = ((FormComponentSabloValue) webComponentValue).getCache();
    } else {
        Form form = getForm(webComponentValue, fs);
        if (form == null)
            return null;
        // TODO return here a NativeScriptable object that understand the full hiearchy?
        cache = FormElementHelper.INSTANCE.getFormComponentCache(webFormComponent.getFormElement(), pd, (JSONObject) webComponentValue, form, fs);
    }
    IWebFormUI formUI = webFormComponent.findParent(IWebFormUI.class);
    String prefix = FormElementHelper.getStartElementName(webFormComponent.getFormElement(), pd);
    for (FormElement fe : cache.getFormComponentElements()) {
        String name = fe.getName();
        if (name != null && !name.startsWith(FormElement.SVY_NAME_PREFIX)) {
            RuntimeWebComponent webComponent = formUI.getRuntimeWebComponent(fe.getRawName());
            if (webComponent != null) {
                newObject.put(name.substring(prefix.length()), newObject, webComponent);
            }
        }
    }
    return newObject;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) JSONObject(org.json.JSONObject) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Scriptable(org.mozilla.javascript.Scriptable) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Aggregations

FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)6 Form (com.servoy.j2db.persistence.Form)5 IFormElement (com.servoy.j2db.persistence.IFormElement)4 FormElement (com.servoy.j2db.server.ngclient.FormElement)4 JSONObject (org.json.JSONObject)4 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)2 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)2 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 ComponentTypeConfig (com.servoy.j2db.server.ngclient.property.ComponentTypeConfig)2 ArrayList (java.util.ArrayList)2 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)2 IForm (com.servoy.j2db.IForm)1 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)1 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)1 WebComponent (com.servoy.j2db.persistence.WebComponent)1 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)1 RuntimeWebComponent (com.servoy.j2db.server.ngclient.component.RuntimeWebComponent)1