use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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.ITableRow 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.ITableRow in project scout.rt by eclipse.
the class JsonTableTest method testRowFilter_nop.
/**
* Usecase:
* <p>
* 1. Add filter to table<br>
* 2. Remove same filter so that no rows are removed<br>
* Assert that no events are generated, especially no rowsDeleted event
*/
@Test
public void testRowFilter_nop() 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 row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
assertNotNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
ITableRowFilter filter = new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
};
table.addRowFilter(filter);
assertEquals(2, table.getFilteredRowCount());
// Remove the just added filter -> Must not create any request
table.removeRowFilter(filter);
assertEquals(3, table.getFilteredRowCount());
JsonTestUtility.processBufferedEvents(m_uiSession);
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class AbstractTableField method execMarkSaved.
@Override
protected void execMarkSaved() {
super.execMarkSaved();
if (m_table != null && !m_tableExternallyManaged) {
try {
m_table.setTableChanging(true);
//
for (int i = 0; i < m_table.getRowCount(); i++) {
ITableRow row = m_table.getRow(i);
if (!row.isStatusNonchanged()) {
row.setStatusNonchanged();
}
}
m_table.discardAllDeletedRows();
} finally {
m_table.setTableChanging(false);
}
}
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.
the class AbstractTableField method importFormFieldData.
@Override
public void importFormFieldData(AbstractFormFieldData source, boolean valueChangeTriggersEnabled) {
Assertions.assertNotNull(source);
if (source.isValueSet() && m_table != null) {
try {
if (!valueChangeTriggersEnabled) {
setValueChangeTriggerEnabled(false);
}
if (source instanceof AbstractTableFieldBeanData) {
AbstractTableFieldBeanData tableBeanData = (AbstractTableFieldBeanData) source;
m_table.importFromTableBeanData(tableBeanData);
}
if (m_table.isCheckable() && m_table.getCheckableColumn() != null) {
for (ITableRow row : m_table.getRows()) {
row.setChecked(BooleanUtility.nvl(m_table.getCheckableColumn().getValue(row)));
}
}
} finally {
if (!valueChangeTriggersEnabled) {
setValueChangeTriggerEnabled(true);
}
}
}
}
Aggregations