Search in sources :

Example 21 with WebFormComponent

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

the class ValueListTypeSabloValue method getTableForDp.

/**
 * If this valuelist is for a dataprovider and that dataprovider is for a foundset (or even from form's foundset) then this method gives the correct table to search in for that DP.
 * The DP might not be from this table though, it could still be a global variable or form variable.
 *
 * @return the table to search DP in
 */
private ITable getTableForDp() {
    ITable table;
    if (foundsetPropertySabloValue != null)
        table = foundsetPropertyTable;
    else {
        IWebFormUI formUI = ((WebFormComponent) webObjectContext.getUnderlyingWebObject()).findParent(WebFormUI.class);
        table = formUI.getController().getTable();
    }
    return table;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) ITable(com.servoy.j2db.persistence.ITable)

Example 22 with WebFormComponent

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

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

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

the class ComponentTypeSabloValue method detach.

@Override
public void detach() {
    // already detached or nothing to clean up.
    if (webObjectContext == null)
        return;
    if (forFoundsetPropertyListener != null) {
        webObjectContext.removePropertyChangeListener(forFoundsetTypedPropertyName, forFoundsetPropertyListener);
        FoundsetTypeSabloValue foundsetPropValue = getFoundsetValue();
        if (foundsetPropValue != null) {
            if (foundsetStateChangeListener != null) {
                foundsetPropValue.removeStateChangeListener(foundsetStateChangeListener);
                foundsetStateChangeListener = null;
            }
            if (viewPortChangeMonitor != null) {
                foundsetPropValue.removeViewportDataChangeMonitor(viewPortChangeMonitor);
                viewPortChangeMonitor = null;
            }
            if (dataLinkedPropertyRegistrationListener != null) {
                FoundsetDataAdapterList dal = foundsetPropValue.getDataAdapterList();
                if (dal != null)
                    dal.removeDataLinkedPropertyRegistrationListener(dataLinkedPropertyRegistrationListener);
            }
            foundsetPropValue.setRecordDataLinkedPropertyIDToColumnDP(childComponent.getName(), null);
        }
    }
    if (readonlyPropertyListener != null)
        webObjectContext.removePropertyChangeListener(WebFormUI.READONLY, readonlyPropertyListener);
    // unregister this component from formcontroller "elements" scope if needed
    WebFormComponent parentComponent = getParentComponent();
    IWebFormUI formUI = parentComponent != null ? parentComponent.findParent(IWebFormUI.class) : null;
    if (formUI != null && componentPropertyDescription != null && Utils.getAsBoolean(componentPropertyDescription.getTag(TAG_ADD_TO_ELEMENTS_SCOPE))) {
        formUI.removeComponentFromElementsScope(formElementValue.element, formElementValue.element.getWebComponentSpec(), childComponent);
    }
    if (childComponent != null) {
        childComponent.dispose();
        childComponent = null;
    }
    componentIsCreated = false;
    // reset to form element's record based properties or null
    initRecordBasedProperties();
    this.monitor = null;
    this.webObjectContext = null;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent)

Example 25 with WebFormComponent

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

WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)31 Test (org.junit.Test)14 Form (com.servoy.j2db.persistence.Form)12 FormElement (com.servoy.j2db.server.ngclient.FormElement)10 IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)10 JSONObject (org.json.JSONObject)10 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)10 StringWriter (java.io.StringWriter)7 JSONWriter (org.json.JSONWriter)7 DataConversion (org.sablo.websocket.utils.DataConversion)7 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)6 Point (java.awt.Point)6 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)5 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)5 Map (java.util.Map)5 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)4 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)4 HashMap (java.util.HashMap)4 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3