use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter 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"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter 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"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter in project scout.rt by eclipse.
the class JsonTableTest method testUserRowFilter_UpdateEvent.
@Test
public void testUserRowFilter_UpdateEvent() 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 reject the first row
ITableRow row0 = table.getRow(0);
ITableRow row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
String row0Id = jsonTable.getOrCreateRowId(row0);
String row1Id = jsonTable.getOrCreateRowId(row1);
String row2Id = jsonTable.getOrCreateRowId(row2);
assertNotNull(row0Id);
assertNotNull(jsonTable.getTableRow(row0Id));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
});
// and reject the third row by the user row filter
JsonEvent event = createJsonRowsFilteredEvent(row0Id, row1Id);
jsonTable.handleUiEvent(event);
// Update the (now hidden) row 0 --> should not trigger an update event, because the row does not exist in the UI
row0.getCellForUpdate(0).setValue("Updated text");
row2.getCellForUpdate(0).setValue("Updated text");
// We expect the first row to be removed from the table, but not the third row
assertEquals(3, table.getRowCount());
assertEquals(1, table.getFilteredRowCount());
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// TODO [7.0] bsh: CGU delete ? assertEquals(6, jsonTable.eventBuffer().size()); // TYPE_ROW_FILTER_CHANGED + TYPE_ROWS_UPDATED = TYPE_ROWS_DELETED + TYPE_ROWS_INSERTED + TYPE_ROWS_UPDATED (row0) + TYPE_ROWS_UPDATED (row2)
// Rejection of row 0 generates a deleted event, rejection of row 2 an update event
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
assertEquals(2, eventList.size());
JsonEvent jsonEvent = eventList.get(0);
assertEquals("rowsDeleted", jsonEvent.getType());
assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
assertEquals(row0Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
jsonEvent = eventList.get(1);
assertEquals("rowsUpdated", jsonEvent.getType());
assertEquals(1, jsonEvent.getData().getJSONArray("rows").length());
assertEquals(row2Id, ((JSONObject) jsonEvent.getData().getJSONArray("rows").get(0)).getString("id"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_DeleteEventOnFilteredRow.
@Test
public void testTableEventCoalesceInUi_DeleteEventOnFilteredRow() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.initTable();
table.fill(1, false);
table.resetColumns();
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTable);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
// -------------
table.fill(2, false);
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// filter all rows
return false;
}
});
response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
JSONArray events = response.optJSONArray("events");
assertEquals(1, events.length());
assertEquals("allRowsDeleted", events.getJSONObject(0).getString("type"));
// -------------
// should not trigger any events
table.deleteRow(0);
response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
events = response.optJSONArray("events");
// No events should be emitted
assertNull(events);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter in project scout.rt by eclipse.
the class JsonTableTest method testRowFilter.
@Test
public void testRowFilter() 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 row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
assertNotNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
String row0Id = jsonTable.getOrCreateRowId(row0);
String row1Id = jsonTable.getOrCreateRowId(row1);
assertNotNull(row0Id);
assertNotNull(jsonTable.getTableRow(row0Id));
assertNotNull(row1Id);
assertNotNull(jsonTable.getTableRow(row1Id));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
});
// After flushing the event buffers and applying the model changes
// to the JsonTable, the row should not exist anymore on the JsonTable
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
assertNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
// should still exist -> should NOT throw an exception
jsonTable.getTableRow(row1Id);
try {
// throws exception
jsonTable.getTableRow(row0Id);
fail("Expected an exception, but no exception was thrown");
} catch (UiException e) {
// ok
}
}
Aggregations