Search in sources :

Example 21 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonCellToJsonTest method testNullValueAndEmptyText.

/**
 * Send only empty text if both are empty
 */
@Test
public void testNullValueAndEmptyText() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, null);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
    assertEquals("", jsonObj.get("text"));
    assertNull(jsonObj.opt("value"));
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) JSONObject(org.json.JSONObject) 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 22 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonCellToJsonTest method testNullValue.

/**
 * Send {@link JSONObject#NULL} if value is null if value is required.
 */
@Test
public void testNullValue() throws JSONException {
    TableWithLongColumn table = new TableWithLongColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, null);
    row.getCellForUpdate(table.getColumn()).setText("-empty-");
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    JSONObject jsonObj = (JSONObject) jsonTable.cellToJson(row, table.getColumn());
    assertEquals("-empty-", jsonObj.get("text"));
    assertEquals(JSONObject.NULL, jsonObj.get("value"));
}
Also used : TableWithLongColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn) JSONObject(org.json.JSONObject) 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 23 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonCellToJsonTest method testStringColumn.

/**
 * Don't generate a cell object if text is the only property.
 */
@Test
public void testStringColumn() throws JSONException {
    TableWithStringColumn table = new TableWithStringColumn();
    table.initTable();
    ITableRow row = table.addRow(table.createRow());
    table.getColumn().setValue(row, "A string");
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    Object jsonObj = jsonTable.cellToJson(row, table.getColumn());
    assertTrue(jsonObj instanceof String);
}
Also used : TableWithStringColumn(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithStringColumn) 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 24 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonTableTest method testTableEventCoalesceInUi_RowInsertedAndDeleted.

/**
 * Tests that multiple model events are coalseced in JSON layer
 */
@Test
public void testTableEventCoalesceInUi_RowInsertedAndDeleted() 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 one row, then delete it --> this should trigger two TableEvents
    List<ITableRow> newRows = table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
    table.discardRows(newRows);
    // 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. --> Both events should cancel each other
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.optJSONArray("events");
    assertNull(events);
}
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) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Example 25 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow in project scout.rt by eclipse.

the class JsonTableTest method testRemoveRowFilterAfterUpdates.

@Test
public void testRemoveRowFilterAfterUpdates() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    // Filter the first row
    ITableRowFilter filter = new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    };
    table.addRowFilter(filter);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    // Simulate that the full table is sent to the UI
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // Hidden row must not be sent to ui -> no row id
    ITableRow row = table.getRow(0);
    assertNull(jsonTable.getTableRowId(row));
    // Update the hidden row
    row.getCellForUpdate(0).setValue("Updated text");
    // Remove filter -> Insert event is generated, inserted row is removed from update event in JsonTable.preprocessBufferedEvents
    table.removeRowFilter(filter);
    assertEquals(3, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // Filtering is implemented by Only one deletion event should be emitted (no update event!)
    List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(2, eventList.size());
    assertEquals("rowsInserted", eventList.get(0).getType());
    assertEquals("rowOrderChanged", eventList.get(1).getType());
    JsonEvent jsonEvent = eventList.get(0);
    assertEquals(1, jsonEvent.getData().getJSONArray("rows").length());
    assertEquals(jsonTable.getTableRowId(row), jsonEvent.getData().getJSONArray("rows").getJSONObject(0).get("id"));
}
Also used : ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) 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) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) Test(org.junit.Test)

Aggregations

ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)127 Test (org.junit.Test)77 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)47 ArrayList (java.util.ArrayList)23 JSONObject (org.json.JSONObject)22 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)16 JSONArray (org.json.JSONArray)13 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)12 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)7 IProposalField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField)7 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)6 IMixedSmartField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IMixedSmartField)5 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 Cell (org.eclipse.scout.rt.client.ui.basic.cell.Cell)4 ICell (org.eclipse.scout.rt.client.ui.basic.cell.ICell)4 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4