Search in sources :

Example 26 with ITableRow

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

the class JsonTableTest method testDeleteAfterInsertAndFilterNop.

/**
 * Use case: Insert, addFilter, removeFilter, delete row of an already inserted row.
 * <p>
 * This exotic case will generate a row order changed event with not enough rows because at the time the row order
 * change event is generated (in JsonTable.preprocessBufferedEvents), getTable().getRows() returns the already
 * modified list where the row is already deleted. This is the difference to the test above, where the deletion really
 * happens after the row order change.
 */
@Test
public void testDeleteAfterInsertAndFilterNop() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.initTable();
    table.fill(2, 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);
    final ITableRow row0 = table.getRow(0);
    String row0Id = jsonTable.getTableRowId(table.getRow(0));
    String row1Id = jsonTable.getTableRowId(table.getRow(1));
    ITableRow newRow0 = table.addRow();
    ITableRow newRow1 = table.addRow();
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            return r == row0;
        }
    });
    // Remove filter again -> NOP
    table.removeRowFilter(table.getRowFilters().get(0));
    // delete the first row -> this will "destroy" the row order changed event
    table.deleteRow(0);
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    JSONArray events = response.optJSONArray("events");
    assertEquals(3, events.length());
    JSONObject event0 = events.getJSONObject(0);
    JSONObject event1 = events.getJSONObject(1);
    JSONObject event2 = events.getJSONObject(2);
    assertEquals("rowsInserted", event0.getString("type"));
    assertEquals("rowOrderChanged", event1.getString("type"));
    JSONArray rowIds = event1.optJSONArray("rowIds");
    assertTrue(rowIds.length() == 4);
    assertEquals(row1Id, rowIds.get(0));
    assertEquals(jsonTable.getTableRowId(newRow0), rowIds.get(1));
    assertEquals(jsonTable.getTableRowId(newRow1), rowIds.get(2));
    // <-- this is not correct but since it will be deleted it is fine
    assertEquals(row0Id, rowIds.get(3));
    assertEquals("rowsDeleted", event2.getString("type"));
}
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 27 with ITableRow

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

the class JsonTableTest method testUserRowFilter.

/**
 * If the rows are filtered using {@link UserTableRowFilter}, the rows must not be deleted from json table and no
 * delete event must be sent -> gui knows which rows are filtered and keeps the invisible rows in memory
 */
@Test
public void testUserRowFilter() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    ITableRow row0 = table.getRow(0);
    ITableRow row2 = table.getRow(2);
    jsonTable.toJson();
    String row0Id = jsonTable.getOrCreateRowId(row0);
    String row2Id = jsonTable.getOrCreateRowId(row2);
    JsonEvent event = createJsonRowsFilteredEvent(row0Id, row2Id);
    jsonTable.handleUiEvent(event);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    assertEquals(3, jsonTable.tableRowIdsMap().size());
    // expect that NO delete event is sent
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_DELETED);
    assertTrue(responseEvents.size() == 0);
}
Also used : 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)

Example 28 with ITableRow

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

the class JsonTableTest method testUserRowFilter_UpdateEvent.

@Test
public void testUserRowFilter_UpdateEvent() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(3);
    table.initTable();
    JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
    // Simulate that the full table is sent to the UI
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // Now reject the first row
    ITableRow row0 = table.getRow(0);
    ITableRow row1 = table.getRow(1);
    ITableRow row2 = table.getRow(2);
    String row0Id = jsonTable.getOrCreateRowId(row0);
    String row1Id = jsonTable.getOrCreateRowId(row1);
    String row2Id = jsonTable.getOrCreateRowId(row2);
    assertNotNull(row0Id);
    assertNotNull(jsonTable.getTableRow(row0Id));
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    });
    // and reject the third row by the user row filter
    JsonEvent event = createJsonRowsFilteredEvent(row0Id, row1Id);
    jsonTable.handleUiEvent(event);
    // Update the (now hidden) row 0 --> should not trigger an update event, because the row does not exist in the UI
    row0.getCellForUpdate(0).setValue("Updated text");
    row2.getCellForUpdate(0).setValue("Updated text");
    // We expect the first row to be removed from the table, but not the third row
    assertEquals(3, table.getRowCount());
    assertEquals(1, table.getFilteredRowCount());
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // TODO [7.0] bsh: CGU delete ? assertEquals(6, jsonTable.eventBuffer().size()); // TYPE_ROW_FILTER_CHANGED + TYPE_ROWS_UPDATED = TYPE_ROWS_DELETED + TYPE_ROWS_INSERTED + TYPE_ROWS_UPDATED (row0) + TYPE_ROWS_UPDATED (row2)
    // Rejection of row 0 generates a deleted event, rejection of row 2 an update event
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(2, eventList.size());
    JsonEvent jsonEvent = eventList.get(0);
    assertEquals("rowsDeleted", jsonEvent.getType());
    assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
    assertEquals(row0Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
    jsonEvent = eventList.get(1);
    assertEquals("rowsUpdated", jsonEvent.getType());
    assertEquals(1, jsonEvent.getData().getJSONArray("rows").length());
    assertEquals(row2Id, ((JSONObject) jsonEvent.getData().getJSONArray("rows").get(0)).getString("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)

Example 29 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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);
}
Also used : 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)

Example 30 with ITableRow

use of org.eclipse.scout.rt.client.ui.basic.table.ITableRow 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));
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) List(java.util.List) ArrayList(java.util.ArrayList) 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