Search in sources :

Example 1 with ServoyDataConverterContext

use of com.servoy.j2db.server.ngclient.ServoyDataConverterContext in project servoy-client by Servoy.

the class DataProviderDateTest method createSabloValue.

private TestDataproviderTypeSabloValue createSabloValue(boolean useLocalDate, String initialValue, String format) {
    ServoyDataConverterContext context = new ServoyDataConverterContext(new ServiceProvider());
    DataAdapterList dal = new DataAdapterList(context.getApplication());
    PropertyDescription pd = NGUtils.getDataProviderPropertyDescription(IColumnTypes.DATETIME, false, useLocalDate);
    TestDataproviderTypeSabloValue value = new TestDataproviderTypeSabloValue("mydate", dal, context, pd, format);
    value.setInitialValue(NGDatePropertyType.NG_INSTANCE.fromJSON(initialValue, false));
    return value;
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) IServoyDataConverterContext(com.servoy.j2db.server.ngclient.IServoyDataConverterContext) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList)

Example 2 with ServoyDataConverterContext

use of com.servoy.j2db.server.ngclient.ServoyDataConverterContext in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testFieldWithValueList.

@Test
public void testFieldWithValueList() throws RepositoryException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    ValueList vl = solution.getValueList("test");
    Assert.assertNotNull(vl);
    Field field = form.createNewField(new Point(0, 0));
    field.setDataProviderID("mycolumn");
    field.setFormat("#,###.00");
    field.setDisplayType(Field.TYPE_AHEAD);
    field.setValuelistID(vl.getID());
    // needed for a valuelist property type that searches it's form's table via the webform ui
    WebFormUI formUI = new WebFormUI(client.getFormManager().getForm(form.getName()));
    IDataAdapterList dataAdapterList = formUI.getDataAdapterList();
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), formUI, form);
    Object property = wc.getProperty("valuelistID");
    Assert.assertTrue(property != null ? property.getClass().getName() : "null", property instanceof ValueListTypeSabloValue && ((ValueListTypeSabloValue) property).getValueList() instanceof CustomValueList);
    Assert.assertEquals("#,###.00", ((CustomValueList) ((ValueListTypeSabloValue) property).getValueList()).getFormat().getDisplayFormat());
}
Also used : CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) Form(com.servoy.j2db.persistence.Form) ValueList(com.servoy.j2db.persistence.ValueList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) ValueListTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.ValueListTypeSabloValue) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) Point(java.awt.Point) FormElement(com.servoy.j2db.server.ngclient.FormElement) Field(com.servoy.j2db.persistence.Field) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Test(org.junit.Test)

Example 3 with ServoyDataConverterContext

use of com.servoy.j2db.server.ngclient.ServoyDataConverterContext in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testTabPanelWithTabs.

@Test
public void testTabPanelWithTabs() throws RepositoryException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    tabForm.setNavigatorID(-1);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(tabForm, client));
    TabPanel tabpanel = form.createNewTabPanel("tabpanel");
    tabpanel.createNewTab("tab1", null, tabForm);
    tabpanel.createNewTab("tab2", null, tabForm);
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
    Assert.assertEquals(2, tabs.size());
    Map<String, Object> map = tabs.get(1);
    Assert.assertSame(tabForm.getName(), map.get("containsFormId"));
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ServoyDataConverterContext

use of com.servoy.j2db.server.ngclient.ServoyDataConverterContext in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testSettingTextOfTabInTabpanel.

@Test
public void testSettingTextOfTabInTabpanel() throws RepositoryException, JSONException {
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    tabForm.setNavigatorID(-1);
    TabPanel tabpanel = form.createNewTabPanel("tabpanel");
    tabpanel.createNewTab("tab1", null, tabForm);
    tabpanel.createNewTab("tab2", null, tabForm);
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    TypedData<Map<String, Object>> changes = wc.getAndClearChanges();
    Assert.assertEquals(0, changes.content.size());
    List<Map<String, Object>> tabs = (List) wc.getProperty("tabs");
    Assert.assertEquals(2, tabs.size());
    Map<String, Object> map = tabs.get(0);
    map.put("text", new BasicTagStringTypeSabloValue("a test", null));
    changes = wc.getAndClearChanges();
    Assert.assertEquals(1, changes.content.size());
    String json = JSONUtils.writeChangesWithConversions(changes.content, changes.contentType, null);
    JSONAssert.assertEquals("{\"tabs\":{\"vEr\":1,\"g\":[{\"op\":[0,0,0],\"d\":[{\"rt\":\"servoydefault-tabpanel.tab\",\"vEr\":1,\"u\":[{\"k\":\"text\",\"v\":\"a test\"}]}],\"svy_types\":{\"0\":\"JSON_obj\"}}]},\"svy_types\":{\"tabs\":\"JSON_arr\"}}", json, true);
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) BasicTagStringTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.BasicTagStringTypeSabloValue) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ValueList(com.servoy.j2db.persistence.ValueList) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) CustomValueList(com.servoy.j2db.dataprocessing.CustomValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) List(java.util.List) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ServoyDataConverterContext

use of com.servoy.j2db.server.ngclient.ServoyDataConverterContext in project servoy-client by Servoy.

the class ComponentTypeSabloValue method fullToJSON.

/**
 * Writes the entire value of this property as JSON. This includes the template values, not just the runtime component properties.
 * This is currently needed and can get called if the property is nested inside other complex properties (json object/array) that sometimes
 * might want/need to send again the entire content.
 */
public JSONWriter fullToJSON(final JSONWriter writer, DataConversion conversionMarkers, ComponentPropertyType componentPropertyType) throws JSONException {
    // so that the client knows it must use the custom client side JS for what JSON it gets
    if (conversionMarkers != null)
        conversionMarkers.convert(ComponentPropertyType.TYPE_NAME);
    // create children of component as specified by this property
    final FormElement fe = formElementValue.element;
    writer.object();
    // get template model values
    final TypedData<Map<String, Object>> formElementProperties = fe.propertiesForTemplateJSON();
    // we'll need to update them with runtime values
    final TypedData<Map<String, Object>> runtimeProperties = childComponent.getProperties();
    // just for clear
    childComponent.getAndClearChanges();
    // add to useful properties only those formElement properties that didn't get overridden at runtime (so form element value is still used)
    boolean templateValuesRemoved = false;
    Iterator<Entry<String, Object>> formElementPropertyIterator = formElementProperties.content.entrySet().iterator();
    while (formElementPropertyIterator.hasNext()) {
        Entry<String, Object> fePropEntry = formElementPropertyIterator.next();
        if (runtimeProperties.content.containsKey(fePropEntry.getKey())) {
            // it has a non-default runtime value; so template value will be ignored/not sent
            if (!templateValuesRemoved) {
                // otherwise it's unmodifiable
                formElementProperties.content = new HashMap<String, Object>(formElementProperties.content);
                templateValuesRemoved = true;
            }
            formElementProperties.content.remove(fePropEntry.getKey());
        }
    }
    removeRecordDependentProperties(runtimeProperties);
    removeRecordDependentProperties(formElementProperties);
    IWebFormUI parent = childComponent.findParent(IWebFormUI.class);
    final FormElementContext formElementContext = new FormElementContext(fe, new ServoyDataConverterContext(parent.getController()), null);
    componentPropertyType.writeTemplateJSONContent(writer, formElementValue, forFoundsetTypedPropertyName, formElementContext, new IModelWriter() {

        @Override
        public void writeComponentModel() throws JSONException {
            writer.object();
            DataConversion dataConversion = new DataConversion();
            JSONUtils.writeData(FormElementToJSON.INSTANCE, writer, formElementProperties.content, formElementProperties.contentType, dataConversion, formElementContext);
            // always use full to JSON converter here; second arg. is null due to that
            childComponent.writeProperties(JSONUtils.FullValueToJSONConverter.INSTANCE, null, writer, runtimeProperties, dataConversion);
            JSONUtils.writeClientConversions(writer, dataConversion);
            writer.endObject();
        }
    }, recordBasedProperties, false);
    if (forFoundsetTypedPropertyName != null)
        recordBasedProperties.clearChanged();
    writeWholeViewportToJSON(writer);
    writer.endObject();
    return writer;
}
Also used : JSONException(org.json.JSONException) FormElement(com.servoy.j2db.server.ngclient.FormElement) DataConversion(org.sablo.websocket.utils.DataConversion) Entry(java.util.Map.Entry) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) IModelWriter(com.servoy.j2db.server.ngclient.property.ComponentPropertyType.IModelWriter) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) FormElementContext(com.servoy.j2db.server.ngclient.FormElementContext)

Aggregations

ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)7 FormElement (com.servoy.j2db.server.ngclient.FormElement)6 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)6 Form (com.servoy.j2db.persistence.Form)5 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)4 CustomValueList (com.servoy.j2db.dataprocessing.CustomValueList)3 IValueList (com.servoy.j2db.dataprocessing.IValueList)3 ValueList (com.servoy.j2db.persistence.ValueList)3 Dimension (java.awt.Dimension)3 TabPanel (com.servoy.j2db.persistence.TabPanel)2 WebComponent (com.servoy.j2db.persistence.WebComponent)2 List (java.util.List)2 Field (com.servoy.j2db.persistence.Field)1 FormElementContext (com.servoy.j2db.server.ngclient.FormElementContext)1 IServoyDataConverterContext (com.servoy.j2db.server.ngclient.IServoyDataConverterContext)1