Search in sources :

Example 31 with ITableRow

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

the class JsonTableTest method testTableEventCoalesceInUi_DeleteEventOnFilteredRow.

@Test
public void testTableEventCoalesceInUi_DeleteEventOnFilteredRow() 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);
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // filter all rows
            return false;
        }
    });
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    JSONArray events = response.optJSONArray("events");
    assertEquals(1, events.length());
    assertEquals("allRowsDeleted", events.getJSONObject(0).getString("type"));
    // -------------
    // should not trigger any events
    table.deleteRow(0);
    response = m_uiSession.currentJsonResponse().toJson();
    JsonTestUtility.endRequest(m_uiSession);
    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 32 with ITableRow

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

the class JsonTableTest method testIgnorableSelectionEvent2.

/**
 * If the selection event triggers the selection of another row, the selection event must not be ignored.
 */
@Test
public void testIgnorableSelectionEvent2() throws JSONException {
    Table table = new Table() {

        @Override
        protected void execRowsSelected(List<? extends ITableRow> rows) {
            selectRow(4);
        }
    };
    table.fill(5);
    table.initTable();
    ITableRow row2 = table.getRow(2);
    ITableRow row4 = table.getRow(4);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonRowsSelectedEvent(jsonTable.getOrCreateRowId(row2));
    assertFalse(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)

Example 33 with ITableRow

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

the class JsonTableTest method testRowFilter.

@Test
public void testRowFilter() 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));
    String row0Id = jsonTable.getOrCreateRowId(row0);
    String row1Id = jsonTable.getOrCreateRowId(row1);
    assertNotNull(row0Id);
    assertNotNull(jsonTable.getTableRow(row0Id));
    assertNotNull(row1Id);
    assertNotNull(jsonTable.getTableRow(row1Id));
    table.addRowFilter(new ITableRowFilter() {

        @Override
        public boolean accept(ITableRow r) {
            // hide first row
            return r.getRowIndex() > 0;
        }
    });
    // After flushing the event buffers and applying the model changes
    // to the JsonTable, the row should not exist anymore on the JsonTable
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    assertNull(jsonTable.tableRowIdsMap().get(row0));
    assertNotNull(jsonTable.tableRowIdsMap().get(row1));
    assertNotNull(jsonTable.tableRowIdsMap().get(row2));
    // should still exist -> should NOT throw an exception
    jsonTable.getTableRow(row1Id);
    try {
        // throws exception
        jsonTable.getTableRow(row0Id);
        fail("Expected an exception, but no exception was thrown");
    } catch (UiException e) {
    // ok
    }
}
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) UiException(org.eclipse.scout.rt.ui.html.UiException) Test(org.junit.Test)

Example 34 with ITableRow

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

the class JsonTableTest method testRequestFocusInCellCoalesceInMultipleResponses.

@Test
public void testRequestFocusInCellCoalesceInMultipleResponses() throws Exception {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    table.setAutoDiscardOnDelete(true);
    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
    final ITableRow row = table.getRow(0);
    table.requestFocusInCell(table.getColumns().get(0), row);
    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());
    // So there should be no events at all in the response
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertNull(response.optJSONArray("events"));
    // end current request
    JsonTestUtility.endRequest(m_uiSession);
    // try to requestFocusInCell on deleted row
    table.requestFocusInCell(table.getColumns().get(0), row);
    // Events should not be in the response
    assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
    // And also not in the event buffer
    assertEquals(0, jsonTable.eventBuffer().size());
    // So there should be no events at all in the response
    JSONObject response2 = m_uiSession.currentJsonResponse().toJson();
    assertNull(response2.optJSONArray("events"));
}
Also used : JSONObject(org.json.JSONObject) 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 35 with ITableRow

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

the class JsonTableTest method testUserRowFilter_toJson.

/**
 * If toJson is called and a user filter is active, every row must be returned and not only the filtered ones
 */
@Test
public void testUserRowFilter_toJson() 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);
    List<ITableRow> filteredRows = new ArrayList<ITableRow>();
    filteredRows.add(row0);
    filteredRows.add(row2);
    table.getUIFacade().setFilteredRowsFromUI(filteredRows);
    jsonTable.toJson();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertEquals(3, table.getRowCount());
    assertEquals(2, table.getFilteredRowCount());
    assertEquals(3, jsonTable.tableRowIdsMap().size());
}
Also used : ArrayList(java.util.ArrayList) 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