Search in sources :

Example 11 with ITableRowFilter

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter in project scout.rt by eclipse.

the class JsonTableTest method testAddRowFilterAfterUpdates.

@Test
public void testAddRowFilterAfterUpdates() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    // Simulate that the full table is sent to the UI
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // Now filter the first row
    ITableRow row = table.getRow(0);
    String row0Id = jsonTable.getOrCreateRowId(row);
    assertNotNull(row0Id);
    assertNotNull(jsonTable.getTableRow(row0Id));
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    });
    // Update the (now hidden) row --> should not trigger an update event, because the row does not exist in the UI
    row.getCellForUpdate(0).setValue("Updated text");
    // We expect the first row to be removed from the table, and no update event!
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // contains row_filter_changed and rows_updated
    assertEquals(2, jsonTable.eventBuffer().size());
    // Filtering is implemented by Only one deletion event should be emitted (no update event!)
    // Conversion of rowFilterChanged event happens here -> // TYPE_ROW_FILTER_CHANGED + TYPE_ROWS_UPDATED = TYPE_ROWS_DELETED
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(1, m_uiSession.currentJsonResponse().getEventList().size());
    assertEquals("rowsDeleted", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
}
Also used : 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

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)11 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)11 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 Test (org.junit.Test)11 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)10 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)5 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)3 AbstractListBox (org.eclipse.scout.rt.client.ui.form.fields.listbox.AbstractListBox)1 IListBox (org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1