Search in sources :

Example 1 with TableWith3Cols

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

the class JsonTableTest method testTableEventCoalesceInUi_InsertAndRowOrderChanged.

/**
 * Tests that multiple model events are coalseced in JSON layer
 */
@Test
public void testTableEventCoalesceInUi_InsertAndRowOrderChanged() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.initTable();
    table.resetColumns();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    table.fill(2, false);
    table.fill(3, false);
    table.getColumnSet().setSortColumn(table.getColumns().get(1), false);
    table.fill(2, false);
    table.getColumnSet().setSortColumn(table.getColumns().get(1), true);
    // Apply event buffer --> only one insertion (with the correct order and a COLUMN_HEADERS_UPDATED event should remain)
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.optJSONArray("events");
    assertNotNull(events);
    assertEquals(2, events.length());
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) Test(org.junit.Test)

Example 2 with TableWith3Cols

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

the class JsonTableTest method testColumnStructureChangedEvent.

/**
 * If column structure changes, we need to resend every row including its new cells.
 */
@Test
public void testColumnStructureChangedEvent() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    table.getColumnSet().getColumn(0).setVisible(false);
    IJsonAdapter<? super TableWith3Cols> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----
    table.getColumnSet().getColumn(0).setVisible(true);
    JsonResponse response = m_uiSession.currentJsonResponse();
    response.fireProcessBufferedEvents();
    List<JsonEvent> events = response.getEventList();
    assertEquals(4, events.size());
    assertEquals(JsonTable.EVENT_COLUMN_STRUCTURE_CHANGED, events.get(0).getType());
    assertEquals(JsonEventType.PROPERTY.getEventType(), events.get(1).getType());
    assertEquals(JsonTable.EVENT_ALL_ROWS_DELETED, events.get(2).getType());
    assertEquals(JsonTable.EVENT_ROWS_INSERTED, events.get(3).getType());
}
Also used : JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) JsonResponse(org.eclipse.scout.rt.ui.html.json.JsonResponse) Test(org.junit.Test)

Example 3 with TableWith3Cols

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

the class JsonTableTest method testTableEventCoalesceInUi_RowInsertedAndDeleted.

/**
 * Tests that multiple model events are coalseced in JSON layer
 */
@Test
public void testTableEventCoalesceInUi_RowInsertedAndDeleted() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    // Response should contain no events
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // Add one row, then delete it --> this should trigger two TableEvents
    List<ITableRow> newRows = table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
    table.discardRows(newRows);
    // Events should not yet be in the response
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // But they should be in the event buffer
    assertEquals(2, jsonTable.eventBuffer().size());
    // When converting to JSON, the event buffer should be cleared and the events should
    // be coalesced and written to the response. --> Both events should cancel each other
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.optJSONArray("events");
    assertNull(events);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 4 with TableWith3Cols

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

the class JsonTableTest method testRemoveRowFilterAfterUpdates.

@Test
public void testRemoveRowFilterAfterUpdates() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    // Filter the first row
    ITableRowFilter filter = new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    };
    table.addRowFilter(filter);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    // Simulate that the full table is sent to the UI
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // Hidden row must not be sent to ui -> no row id
    ITableRow row = table.getRow(0);
    assertNull(jsonTable.getTableRowId(row));
    // Update the hidden row
    row.getCellForUpdate(0).setValue("Updated text");
    // Remove filter -> Insert event is generated, inserted row is removed from update event in JsonTable.preprocessBufferedEvents
    table.removeRowFilter(filter);
    assertEquals(3, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // Filtering is implemented by Only one deletion event should be emitted (no update event!)
    List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(2, eventList.size());
    assertEquals("rowsInserted", eventList.get(0).getType());
    assertEquals("rowOrderChanged", eventList.get(1).getType());
    JsonEvent jsonEvent = eventList.get(0);
    assertEquals(1, jsonEvent.getData().getJSONArray("rows").length());
    assertEquals(jsonTable.getTableRowId(row), jsonEvent.getData().getJSONArray("rows").getJSONObject(0).get("id"));
}
Also used : ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 5 with TableWith3Cols

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

the class JsonTableTest method testDeleteAfterInsertAndFilterNop.

/**
 * Use case: Insert, addFilter, removeFilter, delete row of an already inserted row.
 * <p>
 * This exotic case will generate a row order changed event with not enough rows because at the time the row order
 * change event is generated (in JsonTable.preprocessBufferedEvents), getTable().getRows() returns the already
 * modified list where the row is already deleted. This is the difference to the test above, where the deletion really
 * happens after the row order change.
 */
@Test
public void testDeleteAfterInsertAndFilterNop() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.initTable();
    table.fill(2, false);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTable);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    final ITableRow row0 = table.getRow(0);
    String row0Id = jsonTable.getTableRowId(table.getRow(0));
    String row1Id = jsonTable.getTableRowId(table.getRow(1));
    ITableRow newRow0 = table.addRow();
    ITableRow newRow1 = table.addRow();
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            return r == row0;
        }
    });
    // Remove filter again -> NOP
    table.removeRowFilter(table.getRowFilters().get(0));
    // delete the first row -> this will "destroy" the row order changed event
    table.deleteRow(0);
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    JSONArray events = response.optJSONArray("events");
    assertEquals(3, events.length());
    JSONObject event0 = events.getJSONObject(0);
    JSONObject event1 = events.getJSONObject(1);
    JSONObject event2 = events.getJSONObject(2);
    assertEquals("rowsInserted", event0.getString("type"));
    assertEquals("rowOrderChanged", event1.getString("type"));
    JSONArray rowIds = event1.optJSONArray("rowIds");
    assertTrue(rowIds.length() == 4);
    assertEquals(row1Id, rowIds.get(0));
    assertEquals(jsonTable.getTableRowId(newRow0), rowIds.get(1));
    assertEquals(jsonTable.getTableRowId(newRow1), rowIds.get(2));
    // <-- this is not correct but since it will be deleted it is fine
    assertEquals(row0Id, rowIds.get(3));
    assertEquals("rowsDeleted", event2.getString("type"));
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Aggregations

TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)30 Test (org.junit.Test)30 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)28 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)16 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONObject (org.json.JSONObject)11 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)10 JSONArray (org.json.JSONArray)9 JsonResponse (org.eclipse.scout.rt.ui.html.json.JsonResponse)2 ArrayList (java.util.ArrayList)1 HeaderCell (org.eclipse.scout.rt.client.ui.basic.table.HeaderCell)1 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1