use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonCellToJsonTest method testNullValueAndEmptyText.
/**
* Send only empty text if both are empty
*/
@Test
public void testNullValueAndEmptyText() throws JSONException {
TableWithLongColumn table = new TableWithLongColumn();
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setValue(row, null);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
assertEquals("", jsonObj.get("text"));
assertNull(jsonObj.opt("value"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonCellToJsonTest method testNullValue.
/**
* Send {@link JSONObject#NULL} if value is null if value is required.
*/
@Test
public void testNullValue() throws JSONException {
TableWithLongColumn table = new TableWithLongColumn();
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setValue(row, null);
row.getCellForUpdate(table.getColumn()).setText("-empty-");
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
assertEquals("-empty-", jsonObj.get("text"));
assertEquals(JSONObject.NULL, jsonObj.get("value"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class JsonCellToJsonTest method testStringColumn.
/**
* Don't generate a cell object if text is the only property.
*/
@Test
public void testStringColumn() throws JSONException {
TableWithStringColumn table = new TableWithStringColumn();
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setValue(row, "A string");
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
assertTrue(jsonObj instanceof String);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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"));
}
Aggregations