use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_TwoRowsAdded.
/**
* Tests that multiple model events are coalseced in JSON layer
*/
@Test
public void testTableEventCoalesceInUi_TwoRowsAdded() 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 two rows sequentially --> this should trigger two TableEvents
table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
table.addRowsByMatrix(new Object[] { new Object[] { "AnotherNewCell_0", "AnotherNewCell_1", "AnotherNewCell_2" } });
// 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. --> Only one insert event (with two rows)
JSONObject response = m_uiSession.currentJsonResponse().toJson();
assertEquals(0, jsonTable.eventBuffer().size());
JSONArray events = response.getJSONArray("events");
assertEquals(1, events.length());
assertEquals(2, events.getJSONObject(0).getJSONArray("rows").length());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete.
/**
* Tests if a RequestFocusInCell-Event gets discarded when all rows of the table get deleted and the table has
* setAutoDiscardOnDelete set to true
*/
@Test
public void testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete() {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.setAutoDiscardOnDelete(true);
table.resetColumns();
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
// Response should contain no events
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// Request Focus without a row
table.requestFocusInCell(table.getColumns().get(0), table.getRow(0));
table.deleteAllRows();
// Events should not yet be in the response
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// And there should only one delete event
assertEquals(1, jsonTable.eventBuffer().size());
assertEquals(TableEvent.TYPE_ALL_ROWS_DELETED, jsonTable.eventBuffer().getBufferInternal().get(0).getType());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testTableEventCoalesceInUi_UpdateEventOnFilteredRow.
@Test
public void testTableEventCoalesceInUi_UpdateEventOnFilteredRow() 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);
// would normally trigger an event, but we filter the row in the next step
table.getRow(2).setChecked(true);
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide everything expect the first (already existing row)
return r.getRowIndex() == 0;
}
});
response = m_uiSession.currentJsonResponse().toJson();
assertEquals(0, jsonTable.eventBuffer().size());
JSONArray events = response.optJSONArray("events");
// No events should be emitted
assertNull(events);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testDontSendNonDisplayableMenus.
/**
* Tests whether non displayable menus are sent.
* <p>
* This reduces response size and also leverages security because the menus are never visible to the user, not even
* with the dev tools of the browser
*/
@Test
public void testDontSendNonDisplayableMenus() throws Exception {
TableWithNonDisplayableMenu table = new TableWithNonDisplayableMenu();
table.initTable();
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JsonMenu<IMenu> jsonDisplayableMenu = jsonTable.getAdapter(table.getMenuByClass(TableWithNonDisplayableMenu.DisplayableMenu.class));
JsonMenu<IMenu> jsonNonDisplayableMenu = jsonTable.getAdapter(table.getMenuByClass(TableWithNonDisplayableMenu.NonDisplayableMenu.class));
// Adapter for NonDisplayableMenu must not exist
assertNull(jsonNonDisplayableMenu);
// Json response must not contain NonDisplayableMenu
JSONObject json = jsonTable.toJson();
JSONArray jsonMenus = json.getJSONArray("menus");
assertEquals(1, jsonMenus.length());
assertEquals(jsonDisplayableMenu.getId(), jsonMenus.get(0));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testOptTableRow.
@Test
public void testOptTableRow() throws Exception {
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, new TableWith3Cols(), null);
assertNull(jsonTable.optTableRow("foo"));
}
Aggregations