use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonTableTest method testUserRowFilter_AndAnotherRowFilter.
/**
* If the rows are filtered using {@link UserTableRowFilter}, the rows must not be deleted from json table and no
* delete event must be sent, EXCEPT if the row is filtered by a model based row filter. In that case rows must be
* deleted in the ui.
*/
@Test
public void testUserRowFilter_AndAnotherRowFilter() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(3);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
String row0Id = jsonTable.getOrCreateRowId(row0);
String row2Id = jsonTable.getOrCreateRowId(row2);
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
});
JsonEvent event = createJsonRowsFilteredEvent(row0Id, row2Id);
jsonTable.handleUiEvent(event);
// In the model, 3 rows exist, but only 1 is visible (accepted by filters), in the ui 2 rows exist and 1 is visible
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(1, table.getFilteredRowCount());
assertEquals(2, jsonTable.tableRowIdsMap().size());
// expect that first row gets deleted because a "real" row filter does not accept the first row
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_DELETED);
assertTrue(responseEvents.size() == 1);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_RowInsertedAndUpdated.
/**
* Tests that multiple model events are coalseced in JSON layer
*/
@Test
public void testTableEventCoalesceInUi_RowInsertedAndUpdated() 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 update it --> this should trigger two TableEvents
List<ITableRow> newRows = table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
newRows.get(0).getCellForUpdate(0).setValue("UPDATED");
// 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. --> Update should be merged with inserted
JSONObject response = m_uiSession.currentJsonResponse().toJson();
assertEquals(0, jsonTable.eventBuffer().size());
JSONArray events = response.getJSONArray("events");
assertEquals(1, events.length());
assertEquals(1, events.getJSONObject(0).getJSONArray("rows").length());
assertEquals("UPDATED", events.getJSONObject(0).getJSONArray("rows").getJSONObject(0).getJSONArray("cells").getString(0));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonTableTest method testAllRowsDeleted_whenFilterActive.
/**
* JsonTable generates an allRowsDeleted event if a row is deleted and filteredRowCount is 0. This happens only if a
* filter is active, otherwise table generates a all rows deleted event by itself
*/
@Test
public void testAllRowsDeleted_whenFilterActive() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
jsonTable.toJson();
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide second row
return r.getRowIndex() == 0;
}
});
table.deleteRow(row0);
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(1, table.getRowCount());
assertEquals(0, table.getFilteredRowCount());
assertEquals(0, jsonTable.tableRowIdsMap().size());
// expect that deleteAll event is sent
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ALL_ROWS_DELETED);
assertTrue(responseEvents.size() == 1);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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());
}
Aggregations