use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTableTest method testColumnHeadersUpdatedEvent.
/**
* Sends header update event if header cell has changed, but only for visible columns.
*/
@Test
public void testColumnHeadersUpdatedEvent() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
table.getColumnSet().getColumn(0).setDisplayable(false);
IColumn<?> column0 = table.getColumns().get(0);
IColumn<?> column1 = table.getColumns().get(1);
IJsonAdapter<? super TableWith3Cols> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
((HeaderCell) column0.getHeaderCell()).setText("newHeaderText");
table.getColumnSet().updateColumn(column0);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_COLUMN_HEADERS_UPDATED);
assertTrue(responseEvents.size() == 0);
((HeaderCell) column1.getHeaderCell()).setText("newHeaderText2");
table.getColumnSet().updateColumn(column1);
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_COLUMN_HEADERS_UPDATED);
assertTrue(responseEvents.size() == 1);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTableTest method testUserRowFilter_preventAllRowsDeleted.
/**
* JsonTable generates an allRowsDeleted event if a row is deleted and filteredRowCount is 0. This must not happen if
* the row has been filtered by the user.
*/
@Test
public void testUserRowFilter_preventAllRowsDeleted() 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();
String row0Id = jsonTable.getOrCreateRowId(row0);
JsonEvent event = createJsonRowsFilteredEvent(row0Id);
jsonTable.handleUiEvent(event);
table.deleteRow(row0);
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(1, table.getRowCount());
assertEquals(0, table.getFilteredRowCount());
assertEquals(1, jsonTable.tableRowIdsMap().size());
// expect that NO deleteAll event is sent
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ALL_ROWS_DELETED);
assertTrue(responseEvents.size() == 0);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTableTest method createJsonRowsSortedEvent.
public static JsonEvent createJsonRowsSortedEvent(String columnId, boolean asc) throws JSONException {
// never used
String tableId = "x";
JSONObject data = new JSONObject();
data.put("columnId", columnId);
data.put("sortAscending", asc);
return new JsonEvent(tableId, JsonTable.EVENT_SORT, data);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTableTest method testIgnorableSelectionEvent3.
/**
* Same as {@link #testIgnorableSelectionEvent2()} but with an empty selection
*/
@Test
public void testIgnorableSelectionEvent3() throws JSONException {
Table table = new Table() {
@Override
protected void execRowsSelected(List<? extends ITableRow> rows) {
if (rows.size() == 0) {
selectRow(4);
}
}
};
table.fill(5);
table.initTable();
ITableRow row2 = table.getRow(2);
ITableRow row4 = table.getRow(4);
table.selectRow(row2);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JsonEvent event = createJsonRowsSelectedEvent(null);
assertTrue(row2.isSelected());
assertFalse(row4.isSelected());
jsonTable.handleUiEvent(event);
assertFalse(row2.isSelected());
assertTrue(row4.isSelected());
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_SELECTED);
assertTrue(responseEvents.size() == 1);
List<ITableRow> tableRows = jsonTable.extractTableRows(responseEvents.get(0).getData());
assertEquals(row4, tableRows.get(0));
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTableTest method testIgnorableColumnOrderChangedEvent.
/**
* Response must not contain the column order changed event if the event was triggered by the request and the order
* hasn't changed
*/
@Test
public void testIgnorableColumnOrderChangedEvent() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
IColumn<?> column = table.getColumns().get(0);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column), 2);
jsonTable.handleUiEvent(event);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "columnOrderChanged");
assertTrue(responseEvents.size() == 0);
}
Aggregations