use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonCellToJsonTest method testLongColumn_leftAlignment.
/**
* Don't generate a cell object if text is the only property.
*/
@Test
public void testLongColumn_leftAlignment() throws JSONException {
TableWithLongColumn table = new TableWithLongColumn();
table.getColumn().setHorizontalAlignment(-1);
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setValue(row, 15L);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
assertTrue(jsonObj instanceof String);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonCellToJsonTest method testDateColumn.
@Test
public void testDateColumn() throws JSONException {
TableWithDateColumn table = new TableWithDateColumn();
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setFormat("dd.MM.yyyy");
table.getColumn().setValue(row, DateUtility.parse("01.01.2015", "dd.MM.yyyy"));
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
Assert.assertEquals("01.01.2015", jsonObj.get("text"));
// Pattern used by JsonDate
Assert.assertEquals("2015-01-01", jsonObj.get("value"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonCellToJsonTest method testNullValueAndEmptyText_leftAlignment.
/**
* Send only empty text if both are empty
*/
@Test
public void testNullValueAndEmptyText_leftAlignment() throws JSONException {
TableWithLongColumn table = new TableWithLongColumn();
table.getColumn().setHorizontalAlignment(-1);
table.initTable();
ITableRow row = table.addRow(table.createRow());
table.getColumn().setValue(row, null);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
assertEquals("", jsonObj);
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testDeleteAfterMove.
@Test
public void testDeleteAfterMove() throws Exception {
TableWith3Cols table = new TableWith3Cols();
table.initTable();
table.fill(3, false);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTable);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
String row0Id = jsonTable.getTableRowId(table.getRow(0));
String row1Id = jsonTable.getTableRowId(table.getRow(1));
String row2Id = jsonTable.getTableRowId(table.getRow(2));
table.moveRow(0, 2);
table.deleteRow(0);
response = m_uiSession.currentJsonResponse().toJson();
JsonTestUtility.endRequest(m_uiSession);
JSONArray events = response.optJSONArray("events");
assertEquals(2, events.length());
JSONObject event0 = events.getJSONObject(0);
JSONObject event1 = events.getJSONObject(1);
assertEquals("rowOrderChanged", event0.getString("type"));
JSONArray rowIds = event0.optJSONArray("rowIds");
assertTrue(rowIds.length() == 3);
assertEquals(row2Id, rowIds.get(0));
assertEquals(row0Id, rowIds.get(1));
// <-- this is not correct but since it will be deleted it is fine
assertEquals(row1Id, rowIds.get(2));
assertEquals("rowsDeleted", event1.getString("type"));
}
use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.
the class JsonTableTest method testColumnOrderChangedEvent_assertCellOrder.
@Test
public void testColumnOrderChangedEvent_assertCellOrder() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
IColumn<?> column0 = table.getColumns().get(0);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----------
JSONObject jsonRow = jsonTable.tableRowToJson(table.getRow(0));
JSONArray jsonCells = (JSONArray) jsonRow.get("cells");
JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column0), 2);
jsonTable.handleUiEvent(event);
JSONObject jsonRowAfterMoving = jsonTable.tableRowToJson(table.getRow(0));
JSONArray jsonCellsAfterMoving = (JSONArray) jsonRowAfterMoving.get("cells");
// Expect same cell order, even if the columns are moved
for (int i = 0; i < jsonCellsAfterMoving.length(); i++) {
assertEquals(jsonCells.get(i), jsonCellsAfterMoving.get(i));
}
}
Aggregations