use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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.ITable 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());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testIgnorableSelectionEvent.
/**
* Response must not contain the selection event if the selection was triggered by the request
*/
@Test
public void testIgnorableSelectionEvent() throws JSONException {
Table table = createTableFixture(5);
ITableRow row = table.getRow(2);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JsonEvent event = createJsonRowsSelectedEvent(jsonTable.getOrCreateRowId(row));
jsonTable.handleUiEvent(event);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_SELECTED);
assertTrue(responseEvents.size() == 0);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableFieldTest method testTableDisposalOnPropertyChange.
@Test
public void testTableDisposalOnPropertyChange() {
ITable table = new Table();
ITable table2 = new Table();
ITableField<ITable> tableField = new TableField<ITable>(table);
JsonTableField<ITableField<?>> jsonTableField = UiSessionTestUtility.newJsonAdapter(m_uiSession, tableField, null);
// Switch table -> old one needs to be disposed
assertNotNull(jsonTableField.getAdapter(table));
tableField.setTable(table2, false);
assertNull(jsonTableField.getAdapter(table));
assertNotNull(jsonTableField.getAdapter(table2));
assertTrue(jsonTableField.getAdapter(table2).isInitialized());
jsonTableField.dispose();
assertNull(jsonTableField.getAdapter(table2));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableFieldTest method testPreventTableDisposal.
@Test
public void testPreventTableDisposal() {
// Create tablePage
IPageWithTable<?> tablePage = createTablePageAndSelectNode();
ITable tablePageTable = tablePage.getTable();
JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, tablePage.getOutline(), null);
Assert.assertNotNull(jsonOutline.getAdapter(tablePageTable));
// Create table field which uses the table from the table page
ITableField<ITable> tableField = new TableField<ITable>();
JsonTableField<ITableField<?>> jsonTableField = UiSessionTestUtility.newJsonAdapter(m_uiSession, tableField, null);
tableField.setTable(tablePageTable, true);
// Dispose table field -> table must not be disposed because table page still needs it
jsonTableField.dispose();
assertNotNull(jsonOutline.getAdapter(tablePageTable));
assertTrue(jsonOutline.getAdapter(tablePageTable).isInitialized());
}
Aggregations