Search in sources :

Example 1 with IFormComponentType

use of com.servoy.j2db.util.IFormComponentType in project servoy-client by Servoy.

the class JSNGWebComponent method setHandler.

@Override
public void setHandler(String handlerName, JSMethod value) {
    WebComponent webComponent = getBaseComponent(false);
    WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(webComponent.getTypeName());
    if (spec != null) {
        String name = handlerName;
        if (spec.getHandler(name) == null) {
            name = name + "MethodID";
        }
        if (spec.getHandler(name) != null) {
            setJSONProperty(name, value);
            getBaseComponent(true).putMethodParameters(name, new ArrayList(), value instanceof JSMethodWithArguments ? Arrays.asList(((JSMethodWithArguments) value).getArguments()) : null);
        } else {
            int i = name.indexOf('.');
            if (i > 0) {
                String firstPart = name.substring(0, i);
                PropertyDescription property = spec.getProperty(firstPart);
                if (property != null && property.getType() instanceof IFormComponentType) {
                    // undefined means remove the property
                    Object convertedValue = fromRhinoToDesignValue(value, property, application, this, handlerName);
                    webComponent.setProperty(firstPart, convertedValue);
                    // TODO store the method parameters/arguments..
                    return;
                }
            }
            Debug.log("Error: component " + webComponent.getTypeName() + " does not declare a handler named " + handlerName + ".");
        }
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebComponent(com.servoy.j2db.persistence.WebComponent) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IFormComponentType(com.servoy.j2db.util.IFormComponentType)

Example 2 with IFormComponentType

use of com.servoy.j2db.util.IFormComponentType in project servoy-client by Servoy.

the class JSNGWebComponent method resetJSONProperty.

@Override
public void resetJSONProperty(String propertyName) {
    try {
        WebComponent webComponent = getBaseComponent(true);
        WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(webComponent.getTypeName());
        Pair<PropertyDescription, String> propAndName = getPropertyDescriptionAndName(propertyName, spec);
        PropertyDescription pd = propAndName.getLeft();
        if (pd != null && pd.getType() instanceof IFormComponentType) {
            IFormComponentRhinoConverter converter = ((IFormComponentType) pd.getType()).getFormComponentRhinoConverter(pd.getName(), webComponent.getProperty(pd.getName()), application, this);
            // undefined means remove the property
            Object convertedValue = fromRhinoToDesignValue(Context.getUndefinedValue(), propAndName.getLeft(), application, this, propertyName);
            webComponent.setProperty(propAndName.getRight(), convertedValue);
        } else if (pd != null)
            webComponent.clearProperty(propertyName);
    } catch (JSONException e) {
        Debug.error(e);
    }
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebComponent(com.servoy.j2db.persistence.WebComponent) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) IFormComponentRhinoConverter(com.servoy.j2db.util.IFormComponentRhinoConverter) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IFormComponentType(com.servoy.j2db.util.IFormComponentType)

Example 3 with IFormComponentType

use of com.servoy.j2db.util.IFormComponentType in project servoy-client by Servoy.

the class JSNGWebComponent method getPropertyDescriptionAndName.

private Pair<PropertyDescription, String> getPropertyDescriptionAndName(String propertyName, WebObjectSpecification spec) {
    if (spec == null)
        return new Pair<PropertyDescription, String>(null, propertyName);
    String name = propertyName;
    PropertyDescription pd = spec.getProperty(name);
    if (pd == null) {
        int i = name.indexOf('.');
        if (i > 0) {
            String firstPart = name.substring(0, i);
            PropertyDescription property = spec.getProperty(firstPart);
            if (property != null && property.getType() instanceof IFormComponentType) {
                pd = property;
                name = firstPart;
            }
        }
    }
    if (pd == null && spec.getHandler(name) != null)
        pd = spec.getHandler(name).getAsPropertyDescription();
    if (pd == null) {
        // now try it if it is a more legacy name where the id is stripped from
        pd = spec.getProperty(name + "ID");
        if (pd != null)
            name = name + "ID";
    }
    return new Pair<PropertyDescription, String>(pd, name);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) IFormComponentType(com.servoy.j2db.util.IFormComponentType) Pair(com.servoy.j2db.util.Pair)

Example 4 with IFormComponentType

use of com.servoy.j2db.util.IFormComponentType in project servoy-client by Servoy.

the class JSNGWebComponent method fromRhinoToDesignValue.

public static Object fromRhinoToDesignValue(Object value, PropertyDescription pd, IApplication application, JSWebComponent webComponent, String propertyName) {
    Object result = null;
    if (pd != null && pd.getType() instanceof IFormComponentType) {
        String firstPart = propertyName;
        int i = firstPart.indexOf('.');
        if (i > 0) {
            firstPart = firstPart.substring(0, i);
        }
        IFormComponentRhinoConverter converter = ((IFormComponentType) pd.getType()).getFormComponentRhinoConverter(firstPart, webComponent.getBaseComponent(true).getProperty(firstPart), application, webComponent);
        result = converter.setRhinoToDesignValue(firstPart == propertyName ? "" : propertyName.substring(firstPart.length() + 1), value);
    } else if (pd != null && pd.getType() instanceof IRhinoDesignConverter) {
        result = ((IRhinoDesignConverter) pd.getType()).fromRhinoToDesignValue(value, pd, application, webComponent);
    } else {
        result = JSWebComponent.defaultRhinoToDesignValue(value, application);
    }
    return result;
}
Also used : IFormComponentRhinoConverter(com.servoy.j2db.util.IFormComponentRhinoConverter) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IRhinoDesignConverter(com.servoy.j2db.util.IRhinoDesignConverter) IFormComponentType(com.servoy.j2db.util.IFormComponentType)

Example 5 with IFormComponentType

use of com.servoy.j2db.util.IFormComponentType in project servoy-client by Servoy.

the class JSNGWebComponent method fromDesignToRhinoValue.

public static Object fromDesignToRhinoValue(Object value, PropertyDescription pd, IApplication application, JSWebComponent webComponent, String propertyName) {
    Object result = value;
    if (pd != null && pd.getType() instanceof IFormComponentType) {
        String firstPart = propertyName;
        int i = firstPart.indexOf('.');
        if (i > 0) {
            firstPart = firstPart.substring(0, i);
        }
        IFormComponentRhinoConverter converter = ((IFormComponentType) pd.getType()).getFormComponentRhinoConverter(firstPart, value, application, webComponent);
        result = converter.getDesignToRhinoValue(firstPart == propertyName ? "" : propertyName.substring(firstPart.length() + 1));
    } else if (pd != null && pd.getType() instanceof IRhinoDesignConverter) {
        result = ((IRhinoDesignConverter) pd.getType()).fromDesignToRhinoValue(value, pd, application, webComponent);
    }
    return result == null ? Context.getUndefinedValue() : ServoyJSONObject.jsonNullToNull(result);
}
Also used : IFormComponentRhinoConverter(com.servoy.j2db.util.IFormComponentRhinoConverter) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IRhinoDesignConverter(com.servoy.j2db.util.IRhinoDesignConverter) IFormComponentType(com.servoy.j2db.util.IFormComponentType)

Aggregations

IFormComponentType (com.servoy.j2db.util.IFormComponentType)6 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 JSONObject (org.json.JSONObject)5 PropertyDescription (org.sablo.specification.PropertyDescription)4 WebComponent (com.servoy.j2db.persistence.WebComponent)3 IFormComponentRhinoConverter (com.servoy.j2db.util.IFormComponentRhinoConverter)3 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)3 IRhinoDesignConverter (com.servoy.j2db.util.IRhinoDesignConverter)2 Pair (com.servoy.j2db.util.Pair)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1