Search in sources :

Example 11 with JsonEvent

use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.

the class JsonTableTest method testColumnHeadersUpdatedEvent.

/**
 * Sends header update event if header cell has changed, but only for visible columns.
 */
@Test
public void testColumnHeadersUpdatedEvent() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    table.getColumnSet().getColumn(0).setDisplayable(false);
    IColumn<?> column0 = table.getColumns().get(0);
    IColumn<?> column1 = table.getColumns().get(1);
    IJsonAdapter<? super TableWith3Cols> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    ((HeaderCell) column0.getHeaderCell()).setText("newHeaderText");
    table.getColumnSet().updateColumn(column0);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_COLUMN_HEADERS_UPDATED);
    assertTrue(responseEvents.size() == 0);
    ((HeaderCell) column1.getHeaderCell()).setText("newHeaderText2");
    table.getColumnSet().updateColumn(column1);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_COLUMN_HEADERS_UPDATED);
    assertTrue(responseEvents.size() == 1);
}
Also used : HeaderCell(org.eclipse.scout.rt.client.ui.basic.table.HeaderCell) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) Test(org.junit.Test)

Example 12 with JsonEvent

use of org.eclipse.scout.rt.ui.html.json.JsonEvent 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 13 with JsonEvent

use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.

the class JsonTableTest method createJsonRowsSortedEvent.

public static JsonEvent createJsonRowsSortedEvent(String columnId, boolean asc) throws JSONException {
    // never used
    String tableId = "x";
    JSONObject data = new JSONObject();
    data.put("columnId", columnId);
    data.put("sortAscending", asc);
    return new JsonEvent(tableId, JsonTable.EVENT_SORT, data);
}
Also used : JSONObject(org.json.JSONObject) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

Example 14 with JsonEvent

use of org.eclipse.scout.rt.ui.html.json.JsonEvent 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)

Example 15 with JsonEvent

use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.

the class JsonTableTest method testIgnorableColumnOrderChangedEvent.

/**
 * Response must not contain the column order changed event if the event was triggered by the request and the order
 * hasn't changed
 */
@Test
public void testIgnorableColumnOrderChangedEvent() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    IColumn<?> column = table.getColumns().get(0);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column), 2);
    jsonTable.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "columnOrderChanged");
    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) Test(org.junit.Test)

Aggregations

JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)50 Test (org.junit.Test)38 JSONObject (org.json.JSONObject)20 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)16 ArrayList (java.util.ArrayList)12 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)12 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)11 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)11 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)11 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)8 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)7 JSONArray (org.json.JSONArray)7 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)6 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)5 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)5 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)4 FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)4 List (java.util.List)3 DesktopWithOneOutline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline)3 JsonForm (org.eclipse.scout.rt.ui.html.json.form.JsonForm)3