Search in sources :

Example 11 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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)

Example 12 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 13 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 14 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 15 with ITable

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

the class JsonTableTest method testColumnOrderChangedEvent.

@Test
public void testColumnOrderChangedEvent() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    IColumn<?> column0 = table.getColumns().get(0);
    IColumn<?> column1 = table.getColumns().get(1);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    assertEquals(table.getColumnSet().getVisibleColumn(0), column0);
    assertEquals(table.getColumnSet().getVisibleColumn(1), column1);
    JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column0), 2);
    jsonTable.handleUiEvent(event);
    assertEquals(table.getColumnSet().getVisibleColumn(2), column0);
    event = createJsonColumnMovedEvent(jsonTable.getColumnId(column1), 0);
    jsonTable.handleUiEvent(event);
    assertEquals(table.getColumnSet().getVisibleColumn(0), column1);
}
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) 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