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