Search in sources :

Example 6 with IWebFormUI

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

the class ComponentTypeSabloValue method createComponentIfNeededAndPossible.

protected void createComponentIfNeededAndPossible() {
    // so now we should be able to find a potentially linked foundset property value
    if (componentIsCreated || webObjectContext == null)
        return;
    final FoundsetTypeSabloValue foundsetPropValue = getFoundsetValue();
    if (foundsetPropValue != null)
        foundsetPropValue.addStateChangeListener(getFoundsetStateChangeListener());
    // foundset property value is not yet set or not yet attached to component
    if ((foundsetPropValue == null || foundsetPropValue.getDataAdapterList() == null) && forFoundsetTypedPropertyName != null)
        return;
    componentIsCreated = true;
    IWebFormUI formUI = getParentComponent().findParent(IWebFormUI.class);
    final IDataAdapterList dal = (foundsetPropValue != null ? foundsetPropValue.getDataAdapterList() : formUI.getDataAdapterList());
    if (foundsetPropValue != null) {
        // do this before creating the component so that any attach() methods of it's properties that register data links get caught
        ((FoundsetDataAdapterList) dal).addDataLinkedPropertyRegistrationListener(createDataLinkedPropertyRegistrationListener());
        foundsetLinkedPropOfComponentValueChangeHandler = new FoundsetLinkedValueChangeHandler(foundsetPropValue);
    }
    childComponent = ComponentFactory.createComponent(dal.getApplication(), dal, formElementValue.element, getParentComponent(), formUI.getController().getForm());
    if (foundsetPropValue != null) {
        dataLinkedPropertyRegistrationListener.componentIsNowAvailable();
    }
    childComponent.setDirtyPropertyListener(new IDirtyPropertyListener() {

        @Override
        public void propertyFlaggedAsDirty(String propertyName, boolean dirty, boolean granularUpdate) {
            if (dirty) {
                // this gets called whenever a property is flagged as dirty/changed/to be sent to browser
                if (forFoundsetTypedPropertyName != null && recordBasedProperties.contains(propertyName)) {
                    if (!((FoundsetDataAdapterList) dal).isQuietRecordChangeInProgress() && foundsetPropValue.getFoundset() != null && // if forFoundsetTypedPropertyName != null we are using a foundset DAL, so just cast
                    !foundsetPropValue.getFoundset().isInFindMode()) {
                        // for example valuelist properties can get filtered based on client sent filter in which case the property does change without
                        // any actual change in the record; in this case we need to mark it correctly in viewport as a change
                        foundsetLinkedPropOfComponentValueChangeHandler.valueChangedInFSLinkedUnderlyingValue(propertyName, viewPortChangeMonitor);
                    } else {
                        // else this change was probably determined by the fact that we reuse components, changing the record in the DAL to get data for a specific row;
                        // so we need to clear component changes for this property because we do not notify the parent here (we want to ignore the change) so
                        // we shouldn't keep the property marked as dirty - thus blocking future property changes to generate a valueChanged on parent's monitor
                        childComponent.clearChangedStatusForProperty(propertyName);
                    }
                } else {
                    // non-record related prop. changed...
                    monitor.valueChanged();
                }
            }
        }
    });
    for (String initialChangedProperty : childComponent.getProperties().content.keySet()) {
        if (forFoundsetTypedPropertyName == null || !recordBasedProperties.contains(initialChangedProperty)) {
            // non-record related prop. initially changed...
            monitor.valueChanged();
        }
    }
    childComponent.setComponentContext(new ComponentContext(formElementValue.propertyPath));
    if (componentPropertyDescription != null && Utils.getAsBoolean(componentPropertyDescription.getTag(TAG_ADD_TO_ELEMENTS_SCOPE))) {
        formUI.contributeComponentToElementsScope(formElementValue.element, formElementValue.element.getWebComponentSpec(), childComponent);
    }
    for (String handler : childComponent.getFormElement().getHandlers()) {
        Object value = childComponent.getFormElement().getPropertyValue(handler);
        if (value instanceof String) {
            IPersist function = formUI.getController().getApplication().getFlattenedSolution().searchPersist((String) value);
            Form form = formUI.getController().getForm();
            if (function == null) {
                Debug.warn("Script Method of value '" + value + "' not found trying just the form " + form);
                IPersist child = form.getChild(UUID.fromString((String) value));
                if (child != null) {
                    Debug.warn("Script Method " + child + " on the form " + form + " with uuid " + child.getUUID());
                    function = child;
                }
            }
            if (function != null) {
                childComponent.add(handler, function.getID());
            } else {
                Debug.warn("Event handler for " + handler + " with value '" + value + "' not found (form " + form + ", form element " + childComponent.getFormElement().getName() + ")");
            }
        } else if (value instanceof Number && ((Number) value).intValue() > 0) {
            childComponent.add(handler, ((Number) value).intValue());
        }
    }
    if (foundsetPropValue != null) {
        viewPortChangeMonitor = new ComponentTypeViewportDataChangeMonitor(monitor, new ComponentViewportRowDataProvider((FoundsetDataAdapterList) dal, childComponent, this), this);
        foundsetPropValue.addViewportDataChangeMonitor(viewPortChangeMonitor);
        setDataproviderNameToFoundset();
    }
    addPropagatingPropertyChangeListener(WebFormUI.READONLY, webObjectContext.getProperty(WebFormUI.READONLY));
    if (childComponent.hasChanges())
        monitor.valueChanged();
}
Also used : ComponentContext(com.servoy.j2db.server.ngclient.ComponentContext) Form(com.servoy.j2db.persistence.Form) IDirtyPropertyListener(org.sablo.IDirtyPropertyListener) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) IPersist(com.servoy.j2db.persistence.IPersist) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) JSONObject(org.json.JSONObject)

Example 7 with IWebFormUI

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

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

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

IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)9 JSONObject (org.json.JSONObject)5 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)4 Form (com.servoy.j2db.persistence.Form)3 FormElement (com.servoy.j2db.server.ngclient.FormElement)3 HashMap (java.util.HashMap)3 JSONException (org.json.JSONException)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 IFormElement (com.servoy.j2db.persistence.IFormElement)2 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)2 FormComponentCache (com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache)2 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)2 INGFormElement (com.servoy.j2db.server.ngclient.INGFormElement)2 Map (java.util.Map)2 JSONArray (org.json.JSONArray)2 Scriptable (org.mozilla.javascript.Scriptable)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1