Search in sources :

Example 6 with ITableRowFilter

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

the class JsonListBoxTest method testReloadAndRowFilterChange.

/**
 * Usecase:
 * <p>
 * Listbox has a filter.<br>
 * 1. Reload the listbox -> generates rowsUpdated and rowOrderChanged events<br>
 * 2. Add a new filter -> generates rowFilterChanged which are converted into rowsDeleted or rowsInserted Asserts that
 * rowOrderChanged event contains the correct rows.
 */
@Test
public void testReloadAndRowFilterChange() throws Exception {
    ListBox listBox = new ListBox();
    ITable table = listBox.getTable();
    listBox.initField();
    JsonListBox<Long, IListBox<Long>> jsonListBox = m_uiSession.createJsonAdapter(listBox, null);
    JsonTable<ITable> jsonTable = jsonListBox.getAdapter(table);
    // Filter the first row
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow row) {
            Long key = (Long) row.getKeyValues().get(0);
            if (key.equals(0L)) {
                return false;
            }
            return true;
        }
    });
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    // "Send" listbox to UI
    jsonListBox.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // Load listbox BEFORE adding a new filter -> generates rowOrderChanged before the filter events
    listBox.loadListBoxData();
    // Filter second row as well
    String row1Id = jsonTable.getTableRowId(table.findRowByKey(Arrays.asList(1L)));
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow row) {
            Long key = (Long) row.getKeyValues().get(0);
            if (key.equals(1L)) {
                return false;
            }
            return true;
        }
    });
    assertEquals(1, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
    JsonEvent jsonEvent = eventList.get(0);
    assertEquals("rowsDeleted", jsonEvent.getType());
    assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
    assertEquals(row1Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
    // eventList.get(1) is the rows_updated event, not of interest here
    jsonEvent = eventList.get(2);
    assertEquals("rowOrderChanged", jsonEvent.getType());
    JSONArray jsonRowIds = jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS);
    assertEquals(1, jsonRowIds.length());
}
Also used : IListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox) AbstractListBox(org.eclipse.scout.rt.client.ui.form.fields.listbox.AbstractListBox) Test(org.junit.Test)

Example 7 with ITableRowFilter

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

the class JsonTableTest method testRowFilter_nop.

/**
 * Usecase:
 * <p>
 * 1. Add filter to table<br>
 * 2. Remove same filter so that no rows are removed<br>
 * Assert that no events are generated, especially no rowsDeleted event
 */
@Test
public void testRowFilter_nop() 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 row1 = table.getRow(1);
    ITableRow row2 = table.getRow(2);
    jsonTable.toJson();
    assertNotNull(jsonTable.tableRowIdsMap().get(row0));
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row2));
    ITableRowFilter filter = new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    };
    table.addRowFilter(filter);
    assertEquals(2, table.getFilteredRowCount());
    // Remove the just added filter -> Must not create any request
    table.removeRowFilter(filter);
    assertEquals(3, table.getFilteredRowCount());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row2));
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
}
Also used : 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 8 with ITableRowFilter

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

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

the class JsonTableTest method testUserRowFilter_AndAnotherRowFilter.

/**
 * If the rows are filtered using {@link UserTableRowFilter}, the rows must not be deleted from json table and no
 * delete event must be sent, EXCEPT if the row is filtered by a model based row filter. In that case rows must be
 * deleted in the ui.
 */
@Test
public void testUserRowFilter_AndAnotherRowFilter() 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);
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    });
    JsonEvent event = createJsonRowsFilteredEvent(row0Id, row2Id);
    jsonTable.handleUiEvent(event);
    // In the model, 3 rows exist, but only 1 is visible (accepted by filters), in the ui 2 rows exist and 1 is visible
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(3, table.getRowCount());
    assertEquals(1, table.getFilteredRowCount());
    assertEquals(2, jsonTable.tableRowIdsMap().size());
    // expect that first row gets deleted because a "real" row filter does not accept the first row
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_DELETED);
    assertTrue(responseEvents.size() == 1);
}
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 10 with ITableRowFilter

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

the class JsonTableTest method testAllRowsDeleted_whenFilterActive.

/**
 * JsonTable generates an allRowsDeleted event if a row is deleted and filteredRowCount is 0. This happens only if a
 * filter is active, otherwise table generates a all rows deleted event by itself
 */
@Test
public void testAllRowsDeleted_whenFilterActive() 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();
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide second row
            return r.getRowIndex() == 0;
        }
    });
    table.deleteRow(row0);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(1, table.getRowCount());
    assertEquals(0, table.getFilteredRowCount());
    assertEquals(0, jsonTable.tableRowIdsMap().size());
    // expect that deleteAll event is sent
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ALL_ROWS_DELETED);
    assertTrue(responseEvents.size() == 1);
}
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

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)11 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)11 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 Test (org.junit.Test)11 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)10 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)5 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)3 AbstractListBox (org.eclipse.scout.rt.client.ui.form.fields.listbox.AbstractListBox)1 IListBox (org.eclipse.scout.rt.client.ui.form.fields.listbox.IListBox)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1