Search in sources :

Example 61 with ITable

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);
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) JSONObject(org.json.JSONObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 62 with ITable

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"));
}
Also used : JSONObject(org.json.JSONObject) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) TableWithDateColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithDateColumn) Test(org.junit.Test)

Example 63 with ITable

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);
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) JSONObject(org.json.JSONObject) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 64 with ITable

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"));
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) Test(org.junit.Test)

Example 65 with ITable

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));
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) Test(org.junit.Test)

Aggregations

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)89 Test (org.junit.Test)64 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)45 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)28 JSONObject (org.json.JSONObject)23 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)16 JSONArray (org.json.JSONArray)12 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)10 ArrayList (java.util.ArrayList)9 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)8 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)6 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)6 ITableField (org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)4 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)4 IProposalField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField)4 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)4