use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.
the class FoundsetTest method largeFoundsetUsage.
@Test
public void largeFoundsetUsage() throws JSONException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustomseparatefoundsetbean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setBounds(0, 1);
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"serverSize\":200,\"foundsetId\":1,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":true,\"viewPort\":{\"startIndex\":0,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.0;_0\",\"lastname\":\"value01\",\"firstname\":\"value00\"}]}}").similar(new JSONObject(stringWriter.toString())));
// foundset loads more records due to server side access - client should be aware of new size and hasMoreRows
rawPropertyValue.getFoundset().getRecord(200);
StringWriter stringWriter2 = new StringWriter();
JSONWriter jsonWriter2 = new JSONWriter(stringWriter2);
rawPropertyValue.changesToJSON(jsonWriter2, new DataConversion(), allowBrowserConverterContext);
// bounds is 0,1 we should only get size update, but no rows
Assert.assertEquals(new JSONObject("{\"upd_serverSize\":799}").toString(), new JSONObject(stringWriter2.toString()).toString());
viewPort.setBounds(0, 15);
rawPropertyValue.getFoundset().getRecord(200);
StringWriter stringWriter2_1 = new StringWriter();
JSONWriter jsonWriter2_1 = new JSONWriter(stringWriter2_1);
rawPropertyValue.changesToJSON(jsonWriter2_1, new DataConversion(), allowBrowserConverterContext);
// bounds is 0,15 we should get the rows now
Assert.assertEquals(new JSONObject("{\"upd_viewPort\":{\"startIndex\":0,\"size\":15,\"rows\":[{\"_svyRowId\":\"1.0;_0\",\"firstname\":\"value00\",\"lastname\":\"value01\"},{\"_svyRowId\":\"1.1;_1\",\"firstname\":\"value10\",\"lastname\":\"value11\"},{\"_svyRowId\":\"1.2;_2\",\"firstname\":\"value20\",\"lastname\":\"value21\"},{\"_svyRowId\":\"1.3;_3\",\"firstname\":\"value30\",\"lastname\":\"value31\"},{\"_svyRowId\":\"1.4;_4\",\"firstname\":\"value40\",\"lastname\":\"value41\"},{\"_svyRowId\":\"1.5;_5\",\"firstname\":\"value50\",\"lastname\":\"value51\"},{\"_svyRowId\":\"1.6;_6\",\"firstname\":\"value60\",\"lastname\":\"value61\"},{\"_svyRowId\":\"1.7;_7\",\"firstname\":\"value70\",\"lastname\":\"value71\"},{\"_svyRowId\":\"1.8;_8\",\"firstname\":\"value80\",\"lastname\":\"value81\"},{\"_svyRowId\":\"1.9;_9\",\"firstname\":\"value90\",\"lastname\":\"value91\"},{\"_svyRowId\":\"2.10;_10\",\"firstname\":\"value100\",\"lastname\":\"value101\"},{\"_svyRowId\":\"2.11;_11\",\"firstname\":\"value110\",\"lastname\":\"value111\"},{\"_svyRowId\":\"2.12;_12\",\"firstname\":\"value120\",\"lastname\":\"value121\"},{\"_svyRowId\":\"2.13;_13\",\"firstname\":\"value130\",\"lastname\":\"value131\"},{\"_svyRowId\":\"2.14;_14\",\"firstname\":\"value140\",\"lastname\":\"value141\"}]}}").toString(), new JSONObject(stringWriter2_1.toString()).toString());
// foundset loads more records due to client side wanting more records
viewPort.setBounds(800, 1);
StringWriter stringWriter3 = new StringWriter();
JSONWriter jsonWriter3 = new JSONWriter(stringWriter3);
rawPropertyValue.changesToJSON(jsonWriter3, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"upd_serverSize\":943,\"upd_hasMoreRows\":false,\"upd_viewPort\":{\"startIndex\":800,\"size\":1,\"rows\":[{\"_svyRowId\":\"3.800;_800\",\"lastname\":\"value8001\",\"firstname\":\"value8000\"}]}}").similar(new JSONObject(stringWriter3.toString())));
}
use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportAllRecordDeleted.
@Test
public void foundsetViewportAllRecordDeleted() throws JSONException, ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
FoundSet foundset = (FoundSet) form.getFormModel();
viewPort.setBounds(5, 5);
foundset.setSelectedIndex(6);
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
// just to clear changed flags
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
// create an empty separate foundset from the same datasource
FoundSet sepEmpFs = (FoundSet) client.getFoundSetManager().getNewFoundSet("mem:test");
foundset.js_loadRecords(sepEmpFs);
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
JSONAssert.assertEquals("{\"upd_serverSize\":0,\"upd_selectedRowIndexes\":[],\"upd_viewPort\":{\"startIndex\":0,\"size\":0,\"upd_rows\":[{\"startIndex\":0,\"endIndex\":4,\"type\":2}]}}", stringWriter.toString(), true);
}
use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportChangeData.
@Test
public // change rows in/near viewport
void foundsetViewportChangeData() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
// right now the viewport change monitor will NOT ignore updates because the value is directly sent to the client (through the updateController code)
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setBounds(1, 1);
viewPort.changeMonitor.clearChanges();
rawPropertyValue.getFoundset().getRecord(0).startEditing();
rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more");
rawPropertyValue.getFoundset().getRecord(0).stopEditing();
Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
rawPropertyValue.getFoundset().getRecord(1).startEditing();
rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more");
rawPropertyValue.getFoundset().getRecord(1).stopEditing();
Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
// now simulate a send to client
rawPropertyValue.toJSON(new JSONStringer(), new DataConversion(), new BrowserConverterContext(wc, PushToServerEnum.allow));
rawPropertyValue.getFoundset().getRecord(0).startEditing();
rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more nor not test1 any more");
rawPropertyValue.getFoundset().getRecord(0).stopEditing();
Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
rawPropertyValue.getFoundset().getRecord(1).startEditing();
rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more nor not test2 any more");
rawPropertyValue.getFoundset().getRecord(1).stopEditing();
Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
}
use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.
the class FoundsetTest method setPreferredViewport.
@Test
public // change selected index in main foundset and related foundset should change
void setPreferredViewport() throws // change selected index in main foundset and related foundset should change
JSONException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc1 = form.getFormUI().getWebComponent("mycustombean");
WebFormComponent wc2 = form.getFormUI().getWebComponent("mydynamiccustombean");
FoundsetTypeSabloValue customBeanFoundSet = (FoundsetTypeSabloValue) wc1.getRawPropertyValue("myfoundset");
FoundsetTypeSabloValue dynamicBeanRelatedFoundset = (FoundsetTypeSabloValue) wc2.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext2 = new BrowserConverterContext(wc1, PushToServerEnum.allow);
dynamicBeanRelatedFoundset.getViewPort().setPreferredViewportSize(8);
// selection is now 0, so set to 1 and then back again
customBeanFoundSet.getFoundset().setSelectedIndex(1);
customBeanFoundSet.getFoundset().setSelectedIndex(0);
Assert.assertEquals(8, dynamicBeanRelatedFoundset.getViewPort().getSize());
Assert.assertEquals(0, dynamicBeanRelatedFoundset.getViewPort().getStartIndex());
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
dynamicBeanRelatedFoundset.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"serverSize\":12,\"foundsetId\":3,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
// selection is now 0, so set to 1 and then back again
customBeanFoundSet.getFoundset().setSelectedIndex(1);
dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"upd_serverSize\":4,\"upd_foundsetId\":4,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":4,\"rows\":[{\"_svyRowId\":\"1.4;_0\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"1.8;_1\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.12;_2\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.16;_3\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"}]}}", stringWriter.toString());
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
customBeanFoundSet.getFoundset().setSelectedIndex(0);
dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
Assert.assertEquals("{\"upd_serverSize\":12,\"upd_foundsetId\":3,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
}
use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportAllRecordChangedAndDeleted.
@Test
public // change rows in/near viewport
void foundsetViewportAllRecordChangedAndDeleted() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setBounds(0, form.getFormModel().getSize());
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"serverSize\":18,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":18,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.2;_1\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_2\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_3\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_4\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_5\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_6\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_7\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_8\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_9\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_10\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_11\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_12\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_13\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_14\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_15\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_16\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_17\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
form.getFormModel().fireFoundSetChanged();
form.getFormModel().deleteRecord(0);
stringWriter = new StringWriter();
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
Assert.assertTrue(new JSONObject("{\"serverSize\":17,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":17,\"rows\":[{\"_svyRowId\":\"1.2;_0\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_2\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_3\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_4\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_5\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_6\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_7\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_8\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_9\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_10\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_11\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_12\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_13\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_14\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_15\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_16\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
}
Aggregations