use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.
the class FormElement method propertiesForTemplateJSON.
public TypedData<Map<String, Object>> propertiesForTemplateJSON() {
Map<String, Object> properties = new HashMap<>();
WebObjectSpecification componentSpec = getWebComponentSpec();
Map<String, PropertyDescription> propDescription = componentSpec.getProperties();
for (PropertyDescription pd : propDescription.values()) {
Object val = getRawPropertyValue(pd.getName());
properties.put(pd.getName(), val);
}
if (persistImpl == null || !persistImpl.isForm()) {
Dimension dim = getDesignSize();
if (dim != null)
properties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), dim);
Integer anchor = (Integer) getPropertyValue(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName());
if (anchor != null) {
properties.put(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName(), anchor);
}
}
Object offsetY = getPropertyValue("offsetY");
if (offsetY != null)
properties.put("offsetY", offsetY);
Object partHeight = getPropertyValue("partHeight");
if (partHeight != null)
properties.put("partHeight", partHeight);
Object formview = getPropertyValue("formview");
if (formview != null)
properties.put("formview", formview);
// get types for conversion
PropertyDescriptionBuilder propertyTypes = AggregatedPropertyType.newAggregatedPropertyBuilder();
for (Entry<String, Object> p : properties.entrySet()) {
PropertyDescription t = getWebComponentSpec().getProperty(p.getKey());
if (t != null)
propertyTypes.withProperty(p.getKey(), t);
}
PropertyDescription pd = propertyTypes.build();
return new TypedData<>(properties, pd.hasChildProperties() ? pd : null);
}
use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.
the class WebComponentSpecTest method testFormatTypeAsString.
@Test
public void testFormatTypeAsString() throws JSONException {
String property = "{name:'test',definition:'/test.js', model: {mydataprovider:'dataprovider',myformat:{for:'mydataprovider' , type:'format'}}}";
WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
Assert.assertEquals(2, spec.getProperties().size());
PropertyDescription pd = spec.getProperties().get("myformat");
Assert.assertNotNull(pd);
Assert.assertTrue(pd.getType() == TypesRegistry.getType("format"));
Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
Assert.assertEquals("mydataprovider", ((String[]) pd.getConfig())[0]);
}
use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.
the class WebComponentSpecTest method testFormatTypeAsArray.
@Test
public void testFormatTypeAsArray() throws JSONException {
String property = "{name:'test',definition:'/test.js', model: {mydataprovider:'dataprovider',myformat:{for:['mydataprovider'] , type:'format'}}}";
WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
Assert.assertEquals(2, spec.getProperties().size());
PropertyDescription pd = spec.getProperties().get("myformat");
Assert.assertNotNull(pd);
Assert.assertTrue(pd.getType() == TypesRegistry.getType("format"));
Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
Assert.assertEquals("mydataprovider", ((String[]) pd.getConfig())[0]);
}
use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.
the class WebComponentSpecTest method testOwnTypeProperyTypeRefernceInOtherOwnType.
@Test
public void testOwnTypeProperyTypeRefernceInOtherOwnType() throws JSONException {
String property = "{name:'test',definition:'/test.js', model: {myproperty:'mytype'}, types: {mytype:{model:{typeproperty:'mytype2'}},mytype2:{model:{typeproperty:'string'}}}}";
WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
Assert.assertEquals(1, spec.getProperties().size());
PropertyDescription pd = spec.getProperties().get("myproperty");
Assert.assertNotNull(pd);
Assert.assertNotNull(((ICustomType) pd.getType()).getCustomJSONTypeDefinition());
Object config = pd.getConfig();
Assert.assertNull(config);
Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
PropertyDescription wct = ((ICustomType) pd.getType()).getCustomJSONTypeDefinition();
Assert.assertEquals("test.mytype", wct.getName());
Assert.assertEquals(1, wct.getProperties().size());
PropertyDescription pd2 = wct.getProperties().get("typeproperty");
Assert.assertNotNull(pd2);
Assert.assertNotNull(((ICustomType) pd2.getType()).getCustomJSONTypeDefinition());
Assert.assertFalse(pd2.getType() instanceof CustomJSONArrayType<?, ?>);
config = pd2.getConfig();
Assert.assertNull(config);
PropertyDescription wct2 = ((ICustomType) pd2.getType()).getCustomJSONTypeDefinition();
Assert.assertEquals("test.mytype2", wct2.getName());
Assert.assertEquals(1, wct2.getProperties().size());
PropertyDescription pd3 = wct2.getProperty("typeproperty");
Assert.assertNotNull(pd3);
Assert.assertTrue(pd3.getType() == ServoyStringPropertyType.INSTANCE);
Assert.assertFalse(pd3.getType() instanceof CustomJSONArrayType<?, ?>);
}
use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.
the class WebComponentSpecTest method testArrayStringProperyType.
@Test
public void testArrayStringProperyType() throws JSONException {
String property = "{name:'test',definition:'/test.js', model: {myproperty:'string[]'}}";
WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
Assert.assertEquals(1, spec.getProperties().size());
PropertyDescription pd = spec.getProperties().get("myproperty");
Assert.assertNotNull(pd);
Assert.assertTrue(pd.getType() instanceof CustomJSONArrayType<?, ?>);
Assert.assertTrue(((CustomJSONArrayType) pd.getType()).getCustomJSONTypeDefinition().getType() == ServoyStringPropertyType.INSTANCE);
}
Aggregations