Search in sources :

Example 16 with FormElement

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

the class FormTemplateObjectWrapper method wrap.

@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
    TemplateModel model = wrapperCache.get(obj);
    if (model != null)
        return model;
    Object wrapped;
    if (obj instanceof Form) {
        wrapped = getFormWrapper((Form) obj);
    } else if (obj instanceof Object[]) {
        this.flattenedForm = context.getSolution().getFlattenedForm((Form) ((Object[]) obj)[0]);
        wrapped = new FormWrapper(flattenedForm, (String) ((Object[]) obj)[1], useControllerProvider, context, design, runtimeProperties != null ? runtimeProperties.getJSONObject("") : null);
    } else if (obj == DefaultNavigator.INSTANCE) {
        wrapped = new FormElement(DefaultNavigator.INSTANCE, context.getSolution(), new PropertyPath(), design);
        JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(((FormElement) wrapped).getName()) : null;
        if (object != null) {
            wrapped = new FormElementContext((FormElement) wrapped, context, object);
        }
    } else if (obj instanceof Part) {
        wrapped = new PartWrapper((Part) obj, flattenedForm, context, design);
    } else if (obj instanceof IFormElement) {
        FormElement fe = null;
        if (formUI != null) {
            List<FormElement> cachedFormElements = formUI.getFormElements();
            for (FormElement cachedFE : cachedFormElements) {
                if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
                    fe = cachedFE;
                    break;
                }
            }
            if (fe == null) {
                Form parentForm = (Form) ((IFormElement) obj).getAncestor(IRepository.FORMS);
                if (parentForm != null && parentForm.isFormComponent()) {
                    for (WebComponent webComponent : formUI.getAllComponents()) {
                        if (webComponent instanceof WebFormComponent) {
                            FormElement cachedFE = ((WebFormComponent) webComponent).getFormElement();
                            if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
                                fe = cachedFE;
                                break;
                            }
                        }
                    }
                }
            }
        }
        FormElement formElement = fe != null ? fe : FormElementHelper.INSTANCE.getFormElement((IFormElement) obj, context.getSolution(), null, false);
        JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(formElement.getName()) : null;
        wrapped = new FormElementContext(formElement, context, object);
    } else {
        wrapped = obj;
    }
    TemplateModel wrap = super.wrap(wrapped);
    wrapperCache.put(obj, wrap);
    return wrap;
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) TemplateModel(freemarker.template.TemplateModel) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement) WebComponent(org.sablo.WebComponent) JSONObject(org.json.JSONObject) Part(com.servoy.j2db.persistence.Part) PropertyPath(com.servoy.j2db.server.ngclient.property.types.PropertyPath) JSONObject(org.json.JSONObject) FormElementContext(com.servoy.j2db.server.ngclient.FormElementContext)

Example 17 with FormElement

use of com.servoy.j2db.server.ngclient.FormElement 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 18 with FormElement

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

the class FormWrapper method getCSSPositionElementNames.

private Map<String, Boolean> getCSSPositionElementNames() {
    Map<String, Boolean> names = new HashMap<String, Boolean>();
    names.putAll(formComponentCSSPositionElementNames);
    List<IFormElement> persists = form.getFlattenedObjects(null);
    for (IFormElement persist : persists) {
        if (form.getUseCssPosition().booleanValue() || CSSPositionUtils.isInAbsoluteLayoutMode(persist)) {
            FormElement formElement = FormElementHelper.INSTANCE.getFormElement(persist, context.getSolution(), null, design);
            String name = formElement.getDesignId() != null ? formElement.getDesignId() : formElement.getName();
            if (!names.containsKey(name))
                names.put(name, Boolean.TRUE);
        }
    }
    return names;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) HashMap(java.util.HashMap) FormElement(com.servoy.j2db.server.ngclient.FormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Example 19 with FormElement

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

the class CSSPositionPropertyType method toJSON.

public JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    FormElement fe = null;
    if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent) {
        fe = ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement();
    }
    FlattenedSolution fs = null;
    Form form = null;
    if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
        fs = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
        if (((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm() != null) {
            form = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm().getForm();
        }
    }
    return toJSON(writer, key, object, pd, clientConversion, fe, fs, form);
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IDesignToFormElement(com.servoy.j2db.server.ngclient.property.types.NGConversions.IDesignToFormElement)

Example 20 with FormElement

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

Aggregations

FormElement (com.servoy.j2db.server.ngclient.FormElement)22 IFormElement (com.servoy.j2db.persistence.IFormElement)12 Form (com.servoy.j2db.persistence.Form)11 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)10 HashMap (java.util.HashMap)10 JSONObject (org.json.JSONObject)9 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)6 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 Dimension (java.awt.Dimension)5 Map (java.util.Map)5 Test (org.junit.Test)5 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)4 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)4 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)4 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)4 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)4 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)3 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 IPersist (com.servoy.j2db.persistence.IPersist)3