Search in sources :

Example 1 with IRhinoToSabloComponent

use of com.servoy.j2db.server.ngclient.property.types.NGConversions.IRhinoToSabloComponent in project servoy-client by Servoy.

the class RuntimeWebComponent method put.

@Override
public void put(String name, Scriptable start, Object value) {
    if (isInvalidValue(name, value))
        return;
    List<Pair<String, String>> oldVisibleForms = getVisibleForms();
    if (specProperties != null && specProperties.contains(name)) {
        Object previousVal = null;
        PropertyDescription pd = webComponentSpec.getProperties().get(name);
        if (pd.getType() instanceof ISabloComponentToRhino && !(pd.getType() instanceof IRhinoToSabloComponent)) {
            // the it has sablo to rhino conversion but not the other way around then we should just use the
            // value from the conversion so call get(String,Scriptable)
            previousVal = get(name, start);
        } else
            previousVal = component.getProperty(name);
        Object val = NGConversions.INSTANCE.convertRhinoToSabloComponentValue(value, previousVal, pd, component);
        if (val != previousVal)
            component.setProperty(name, val);
        if (pd != null && pd.getType() instanceof VisiblePropertyType) {
            // search all labelfor elements
            for (WebComponent siblingComponent : component.getParent().getComponents()) {
                Collection<PropertyDescription> labelFors = siblingComponent.getSpecification().getProperties(LabelForPropertyType.INSTANCE);
                if (labelFors != null) {
                    for (PropertyDescription labelForProperty : labelFors) {
                        if (Utils.equalObjects(component.getName(), siblingComponent.getProperty(labelForProperty.getName()))) {
                            // sibling component is labelfor, so set value to all its visible properties
                            Collection<PropertyDescription> visibleProperties = siblingComponent.getSpecification().getProperties(VisiblePropertyType.INSTANCE);
                            if (visibleProperties != null) {
                                for (PropertyDescription visibleProperty : visibleProperties) {
                                    previousVal = siblingComponent.getProperty(visibleProperty.getName());
                                    val = NGConversions.INSTANCE.convertRhinoToSabloComponentValue(value, previousVal, visibleProperty, siblingComponent);
                                    if (val != previousVal)
                                        siblingComponent.setProperty(name, val);
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
    } else if (prototypeScope != null) {
        if (!apiFunctions.containsKey(name)) {
            // check if we have a setter for this property
            if (name != null && name.length() > 0) {
                String uName = new StringBuffer(name.substring(0, 1).toUpperCase()).append(name.substring(1)).toString();
                if (apiFunctions.containsKey("set" + uName) && apiFunctions.containsKey("get" + uName)) {
                    // call setter
                    Function propertySetter = apiFunctions.get("set" + uName);
                    propertySetter.call(Context.getCurrentContext(), start, start, new Object[] { value });
                } else {
                    prototypeScope.put(name, start, value);
                }
            }
        }
    }
    updateVisibleContainers(oldVisibleForms);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) IRhinoToSabloComponent(com.servoy.j2db.server.ngclient.property.types.NGConversions.IRhinoToSabloComponent) WebComponent(org.sablo.WebComponent) WebComponentFunction(com.servoy.j2db.server.ngclient.scripting.WebComponentFunction) BaseFunction(org.mozilla.javascript.BaseFunction) Function(org.mozilla.javascript.Function) ISabloComponentToRhino(com.servoy.j2db.server.ngclient.property.types.NGConversions.ISabloComponentToRhino) VisiblePropertyType(org.sablo.specification.property.types.VisiblePropertyType) Pair(com.servoy.j2db.util.Pair)

Aggregations

IRhinoToSabloComponent (com.servoy.j2db.server.ngclient.property.types.NGConversions.IRhinoToSabloComponent)1 ISabloComponentToRhino (com.servoy.j2db.server.ngclient.property.types.NGConversions.ISabloComponentToRhino)1 WebComponentFunction (com.servoy.j2db.server.ngclient.scripting.WebComponentFunction)1 Pair (com.servoy.j2db.util.Pair)1 BaseFunction (org.mozilla.javascript.BaseFunction)1 Function (org.mozilla.javascript.Function)1 WebComponent (org.sablo.WebComponent)1 PropertyDescription (org.sablo.specification.PropertyDescription)1 VisiblePropertyType (org.sablo.specification.property.types.VisiblePropertyType)1