Search in sources :

Example 21 with TableWith3Cols

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols 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)

Example 22 with TableWith3Cols

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.

the class JsonTableTest method testTableEventCoalesceInUi_TwoRowsAdded.

/**
 * Tests that multiple model events are coalseced in JSON layer
 */
@Test
public void testTableEventCoalesceInUi_TwoRowsAdded() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    // Response should contain no events
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // Add two rows sequentially --> this should trigger two TableEvents
    table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
    table.addRowsByMatrix(new Object[] { new Object[] { "AnotherNewCell_0", "AnotherNewCell_1", "AnotherNewCell_2" } });
    // Events should not yet be in the response
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // But they should be in the event buffer
    assertEquals(2, jsonTable.eventBuffer().size());
    // When converting to JSON, the event buffer should be cleared and the events should
    // be coalesced and written to the response. -->  Only one insert event (with two rows)
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.getJSONArray("events");
    assertEquals(1, events.length());
    assertEquals(2, events.getJSONObject(0).getJSONArray("rows").length());
}
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 23 with TableWith3Cols

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.

the class JsonTableTest method testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete.

/**
 * Tests if a RequestFocusInCell-Event gets discarded when all rows of the table get deleted and the table has
 * setAutoDiscardOnDelete set to true
 */
@Test
public void testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete() {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.setAutoDiscardOnDelete(true);
    table.resetColumns();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    // Response should contain no events
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // Request Focus without a row
    table.requestFocusInCell(table.getColumns().get(0), table.getRow(0));
    table.deleteAllRows();
    // Events should not yet be in the response
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // And there should only one delete event
    assertEquals(1, jsonTable.eventBuffer().size());
    assertEquals(TableEvent.TYPE_ALL_ROWS_DELETED, jsonTable.eventBuffer().getBufferInternal().get(0).getType());
}
Also used : 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 24 with TableWith3Cols

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.

the class JsonTableTest method testTableEventCoalesceInUi_UpdateEventOnFilteredRow.

@Test
public void testTableEventCoalesceInUi_UpdateEventOnFilteredRow() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.initTable();
    table.fill(1, false);
    table.resetColumns();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTable);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    // -------------
    table.fill(2, false);
    // would normally trigger an event, but we filter the row in the next step
    table.getRow(2).setChecked(true);
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide everything expect the first (already existing row)
            return r.getRowIndex() == 0;
        }
    });
    response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.optJSONArray("events");
    // No events should be emitted
    assertNull(events);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 25 with TableWith3Cols

use of org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols in project scout.rt by eclipse.

the class JsonTableTest method testOptTableRow.

@Test
public void testOptTableRow() throws Exception {
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, new TableWith3Cols(), null);
    assertNull(jsonTable.optTableRow("foo"));
}
Also used : ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) Test(org.junit.Test)

Aggregations

TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)30 Test (org.junit.Test)30 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)28 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)16 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONObject (org.json.JSONObject)11 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)10 JSONArray (org.json.JSONArray)9 JsonResponse (org.eclipse.scout.rt.ui.html.json.JsonResponse)2 ArrayList (java.util.ArrayList)1 HeaderCell (org.eclipse.scout.rt.client.ui.basic.table.HeaderCell)1 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1