use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testUserRowFilter_toJson.
/**
* If toJson is called and a user filter is active, every row must be returned and not only the filtered ones
*/
@Test
public void testUserRowFilter_toJson() 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 row2 = table.getRow(2);
List<ITableRow> filteredRows = new ArrayList<ITableRow>();
filteredRows.add(row0);
filteredRows.add(row2);
table.getUIFacade().setFilteredRowsFromUI(filteredRows);
jsonTable.toJson();
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
assertEquals(3, jsonTable.tableRowIdsMap().size());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testClearSelectionEvent.
/**
* Tests whether the model rows get correctly unselected
*/
@Test
public void testClearSelectionEvent() throws JSONException {
Table table = createTableFixture(5);
ITableRow row1 = table.getRow(1);
table.selectRow(row1);
assertTrue(row1.isSelected());
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JsonEvent event = createJsonRowsSelectedEvent(null);
jsonTable.handleUiEvent(event);
assertTrue(table.getSelectedRows().size() == 0);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonListBoxTest method testReloadAndRowFilterChange.
/**
* Usecase:
* <p>
* Listbox has a filter.<br>
* 1. Reload the listbox -> generates rowsUpdated and rowOrderChanged events<br>
* 2. Add a new filter -> generates rowFilterChanged which are converted into rowsDeleted or rowsInserted Asserts that
* rowOrderChanged event contains the correct rows.
*/
@Test
public void testReloadAndRowFilterChange() throws Exception {
ListBox listBox = new ListBox();
ITable table = listBox.getTable();
listBox.initField();
JsonListBox<Long, IListBox<Long>> jsonListBox = m_uiSession.createJsonAdapter(listBox, null);
JsonTable<ITable> jsonTable = jsonListBox.getAdapter(table);
// Filter the first row
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow row) {
Long key = (Long) row.getKeyValues().get(0);
if (key.equals(0L)) {
return false;
}
return true;
}
});
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
// "Send" listbox to UI
jsonListBox.toJson();
JsonTestUtility.processBufferedEvents(m_uiSession);
JsonTestUtility.endRequest(m_uiSession);
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// Load listbox BEFORE adding a new filter -> generates rowOrderChanged before the filter events
listBox.loadListBoxData();
// Filter second row as well
String row1Id = jsonTable.getTableRowId(table.findRowByKey(Arrays.asList(1L)));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow row) {
Long key = (Long) row.getKeyValues().get(0);
if (key.equals(1L)) {
return false;
}
return true;
}
});
assertEquals(1, table.getFilteredRowCount());
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
JsonEvent jsonEvent = eventList.get(0);
assertEquals("rowsDeleted", jsonEvent.getType());
assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
assertEquals(row1Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
// eventList.get(1) is the rows_updated event, not of interest here
jsonEvent = eventList.get(2);
assertEquals("rowOrderChanged", jsonEvent.getType());
JSONArray jsonRowIds = jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS);
assertEquals(1, jsonRowIds.length());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableFieldTest method testPreventTableDisposal2.
@Test
public void testPreventTableDisposal2() {
// 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);
// Switch table -> table must not be disposed because table page still needs it
ITable table2 = new Table();
tableField.setTable(table2, true);
assertNotNull(jsonTableField.getAdapter(table2));
assertTrue(jsonTableField.getAdapter(table2).isInitialized());
assertNotNull(jsonOutline.getAdapter(tablePageTable));
assertTrue(jsonOutline.getAdapter(tablePageTable).isInitialized());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableFieldTest method testTableDisposal.
@Test
public void testTableDisposal() {
ITable table = new Table();
ITableField<ITable> tableField = new TableField<ITable>(table);
JsonTableField<ITableField<?>> jsonTableField = UiSessionTestUtility.newJsonAdapter(m_uiSession, tableField, null);
assertNotNull(jsonTableField.getAdapter(table));
jsonTableField.dispose();
assertNull(jsonTableField.getAdapter(table));
}
Aggregations