Search in sources :

Example 1 with ListBoxTable

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable in project scout.rt by eclipse.

the class JsonTableTest method testTableEventCoalesceInUi_ReplaceRows.

@Test
public void testTableEventCoalesceInUi_ReplaceRows() throws Exception {
    ListBoxTable listbox = new ListBoxTable();
    ILookupRow<Long> row1 = new LookupRow<Long>(1L, "Row1");
    ILookupRow<Long> row2 = new LookupRow<Long>(2L, "Row2").withActive(false);
    ILookupRow<Long> row3 = new LookupRow<Long>(3L, "Row3");
    ILookupRow<Long> row4 = new LookupRow<Long>(4L, "Row4");
    ArrayList<ITableRow> rowsInitial = new ArrayList<ITableRow>();
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row1));
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row2));
    rowsInitial.add(listbox.getTableRowBuilder().createTableRow(row3));
    ITable table = listbox.getTable();
    table.addRows(rowsInitial);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTable);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    JSONArray events = response.optJSONArray("events");
    ArrayList<ITableRow> rowsUpdate = new ArrayList<ITableRow>();
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row1));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row2));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row3));
    rowsUpdate.add(listbox.getTableRowBuilder().createTableRow(row4));
    table.replaceRows(rowsUpdate);
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    events = response.optJSONArray("events");
    JSONObject lastEvent = events.optJSONObject(events.length() - 1);
    assertEquals(lastEvent.optString("type"), "rowOrderChanged");
    JSONArray rowIds = lastEvent.optJSONArray("rowIds");
    assertTrue(rowIds.length() == 3);
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)1 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)1 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1