use of com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent in project servoy-client by Servoy.
the class NGCustomJSONObjectType method toFormElementValue.
@Override
public Map<String, FormElementT> toFormElementValue(JSONObject designValue, PropertyDescription mainProperty, FlattenedSolution flattenedSolution, INGFormElement formElement, PropertyPath propertyPath) {
if (designValue != null) {
Map<String, FormElementT> formElementValues = new HashMap<>(designValue.length());
Iterator<String> keys = designValue.keys();
while (keys.hasNext()) {
String key = keys.next();
try {
propertyPath.add(key);
PropertyDescription property = getCustomJSONTypeDefinition().getProperty(key);
if (property != null)
formElementValues.put(key, (FormElementT) NGConversions.INSTANCE.convertDesignToFormElementValue(designValue.opt(key), property, flattenedSolution, formElement, propertyPath));
} finally {
propertyPath.backOneLevel();
}
}
for (PropertyDescription pd : getCustomJSONTypeDefinition().getProperties().values()) {
if (!formElementValues.containsKey(pd.getName())) {
if (pd.hasDefault()) {
propertyPath.add(pd.getName());
formElementValues.put(pd.getName(), (FormElementT) NGConversions.INSTANCE.convertDesignToFormElementValue(pd.getDefaultValue(), pd, flattenedSolution, formElement, propertyPath));
propertyPath.backOneLevel();
} else if (pd.getType() instanceof IDesignDefaultToFormElement<?, ?, ?>) {
propertyPath.add(pd.getName());
formElementValues.put(pd.getName(), (FormElementT) ((IDesignDefaultToFormElement<?, ?, ?>) pd.getType()).toDefaultFormElementValue(pd, flattenedSolution, formElement, propertyPath));
propertyPath.backOneLevel();
} else if (pd.getType().defaultValue(pd) != null || pd.getType() instanceof IFormElementDefaultValueToSabloComponent) {
propertyPath.add(pd.getName());
formElementValues.put(pd.getName(), (FormElementT) NGConversions.IDesignToFormElement.TYPE_DEFAULT_VALUE_MARKER);
propertyPath.backOneLevel();
}
}
}
return formElementValues;
}
return null;
}
use of com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent in project servoy-client by Servoy.
the class ServoyClientService method initDefaults.
protected void initDefaults(WebObjectSpecification spec) {
PropertyPath propertyPath = new PropertyPath();
IServoyDataConverterContext dataConverterContext = getDataConverterContext();
// was used inside a service
for (String propName : spec.getAllPropertiesNames()) {
PropertyDescription pd = spec.getProperty(propName);
try {
Object formElementEquivalentValue = null;
// IMPORTANT NOTE: if you change anything in following if-else please update FormElement.initTemplateProperties as well
if (pd.hasDefault()) {
propertyPath.add(pd.getName());
formElementEquivalentValue = NGConversions.INSTANCE.convertDesignToFormElementValue(pd.getDefaultValue(), pd, dataConverterContext.getSolution(), null, propertyPath);
propertyPath.backOneLevel();
} else if (pd.getType() instanceof IDesignDefaultToFormElement<?, ?, ?>) {
propertyPath.add(pd.getName());
formElementEquivalentValue = ((IDesignDefaultToFormElement<?, ?, ?>) pd.getType()).toDefaultFormElementValue(pd, dataConverterContext.getSolution(), null, propertyPath);
propertyPath.backOneLevel();
} else if (pd.getType().defaultValue(pd) != null || pd.getType() instanceof IFormElementDefaultValueToSabloComponent) {
// remember that we can use type specified default value when this gets transformed to JSON
formElementEquivalentValue = NGConversions.IDesignToFormElement.TYPE_DEFAULT_VALUE_MARKER;
}
// simulate form element -> web component conversion
if (formElementEquivalentValue != null) {
// here form element, web component and dal params are null as this is a service - it will only work for property types that do not use those in this conversion
setProperty(propName, NGConversions.INSTANCE.convertFormElementToSabloComponentValue(formElementEquivalentValue, pd, null, null, null));
// we do not use .setDefaultProperty(...) as that is meant actually as 'template' value for components which is not the case for services
}
} catch (Exception e) {
Debug.log("Default value could not be determined for property '" + propName + "' of service '" + name + "'. Type: '" + pd.getType().getName() + "'. See stack-trace. It is possible that the service .spec is using a property type that is only meant to work with components, not services. A null default will be assumed instead.", e);
}
}
}
use of com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent in project servoy-client by Servoy.
the class FormElement method initTemplateProperties.
private void initTemplateProperties(Map<String, PropertyDescription> specProperties, Map<String, Object> map, FlattenedSolution fs, PropertyPath propertyPath) {
if (specProperties != null && map != null) {
for (PropertyDescription pd : specProperties.values()) {
// IMPORTANT NOTE: if you change anything here please update NGClientWebSocketSession.createClientService as well
if (!map.containsKey(pd.getName())) {
if (pd.hasDefault()) {
propertyPath.add(pd.getName());
map.put(pd.getName(), NGConversions.INSTANCE.convertDesignToFormElementValue(pd.getDefaultValue(), pd, fs, this, propertyPath));
propertyPath.backOneLevel();
} else if (pd.getType() instanceof IDesignDefaultToFormElement<?, ?, ?>) {
propertyPath.add(pd.getName());
map.put(pd.getName(), ((IDesignDefaultToFormElement<?, ?, ?>) pd.getType()).toDefaultFormElementValue(pd, fs, this, propertyPath));
propertyPath.backOneLevel();
} else if (pd.getType().defaultValue(pd) != null || pd.getType() instanceof IFormElementDefaultValueToSabloComponent) {
// remember that we can use type specified default value when this gets transformed to JSON
map.put(pd.getName(), NGConversions.IDesignToFormElement.TYPE_DEFAULT_VALUE_MARKER);
}
}
Object formElementValue = map.get(pd.getName());
if (inDesigner && pd.getType() == VisiblePropertyType.INSTANCE) {
Object isVisibleObj = map.get(pd.getName());
if (isVisibleObj instanceof Boolean) {
isVisible = isVisible && ((Boolean) isVisibleObj).booleanValue();
map.put(pd.getName(), Boolean.TRUE);
}
}
}
}
}
Aggregations