Search in sources :

Example 66 with ITable

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

the class JsonTableTest method testTableEventCoalesceInUi_TwoRowsAdded.

/**
 * Tests that multiple model events are coalseced in JSON layer
 */
@Test
public void testTableEventCoalesceInUi_TwoRowsAdded() 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 two rows sequentially --> this should trigger two TableEvents
    table.addRowsByMatrix(new Object[] { new Object[] { "NewCell_0", "NewCell_1", "NewCell_2" } });
    table.addRowsByMatrix(new Object[] { new Object[] { "AnotherNewCell_0", "AnotherNewCell_1", "AnotherNewCell_2" } });
    // 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. -->  Only one insert event (with two rows)
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    assertEquals(0, jsonTable.eventBuffer().size());
    JSONArray events = response.getJSONArray("events");
    assertEquals(1, events.length());
    assertEquals(2, events.getJSONObject(0).getJSONArray("rows").length());
}
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) Test(org.junit.Test)

Example 67 with ITable

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

the class JsonTableTest method testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete.

/**
 * Tests if a RequestFocusInCell-Event gets discarded when all rows of the table get deleted and the table has
 * setAutoDiscardOnDelete set to true
 */
@Test
public void testRequestFocusInCellCoalesceWithtAutoDiscardOnDelete() {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.setAutoDiscardOnDelete(true);
    table.resetColumns();
    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
    table.requestFocusInCell(table.getColumns().get(0), table.getRow(0));
    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());
}
Also used : 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)

Example 68 with ITable

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

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

the class JsonTableTest method testDontSendNonDisplayableMenus.

/**
 * Tests whether non displayable menus are sent.
 * <p>
 * This reduces response size and also leverages security because the menus are never visible to the user, not even
 * with the dev tools of the browser
 */
@Test
public void testDontSendNonDisplayableMenus() throws Exception {
    TableWithNonDisplayableMenu table = new TableWithNonDisplayableMenu();
    table.initTable();
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonMenu<IMenu> jsonDisplayableMenu = jsonTable.getAdapter(table.getMenuByClass(TableWithNonDisplayableMenu.DisplayableMenu.class));
    JsonMenu<IMenu> jsonNonDisplayableMenu = jsonTable.getAdapter(table.getMenuByClass(TableWithNonDisplayableMenu.NonDisplayableMenu.class));
    // Adapter for NonDisplayableMenu must not exist
    assertNull(jsonNonDisplayableMenu);
    // Json response must not contain NonDisplayableMenu
    JSONObject json = jsonTable.toJson();
    JSONArray jsonMenus = json.getJSONArray("menus");
    assertEquals(1, jsonMenus.length());
    assertEquals(jsonDisplayableMenu.getId(), jsonMenus.get(0));
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) TableWithNonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu.NonDisplayableMenu) DisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu.DisplayableMenu) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TableWithNonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu.NonDisplayableMenu) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) TableWithNonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithNonDisplayableMenu) Test(org.junit.Test)

Example 70 with ITable

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

the class JsonTableTest method testOptTableRow.

@Test
public void testOptTableRow() throws Exception {
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, new TableWith3Cols(), null);
    assertNull(jsonTable.optTableRow("foo"));
}
Also used : ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) 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