use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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.ITable 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.ITable 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.ITable 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());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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);
}
Aggregations