Search in sources :

Example 1 with ISabloComponentToRhino

use of com.servoy.j2db.server.ngclient.property.types.NGConversions.ISabloComponentToRhino 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)

Example 2 with ISabloComponentToRhino

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

the class WebServiceScriptable method getIds.

@Override
public Object[] getIds() {
    ArrayList<String> al = new ArrayList<>();
    IWebObjectContext service = null;
    if (application != null) {
        service = (IWebObjectContext) application.getWebsocketSession().getClientService(serviceSpecification.getName());
    }
    for (String name : serviceSpecification.getAllPropertiesNames()) {
        PropertyDescription pd = serviceSpecification.getProperty(name);
        IPropertyType<?> type = pd.getType();
        if (service == null || !(type instanceof ISabloComponentToRhino<?>) || ((ISabloComponentToRhino) type).isValueAvailableInRhino(service.getProperty(name), pd, service)) {
            al.add(name);
        }
    }
    al.addAll(serviceSpecification.getApiFunctions().keySet());
    return al.toArray();
}
Also used : IWebObjectContext(org.sablo.IWebObjectContext) PropertyDescription(org.sablo.specification.PropertyDescription) ISabloComponentToRhino(com.servoy.j2db.server.ngclient.property.types.NGConversions.ISabloComponentToRhino) ArrayList(java.util.ArrayList)

Aggregations

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