Search in sources :

Example 16 with JsonEvent

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

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

the class JsonTableTest method createJsonRowsSelectedEvent.

public static JsonEvent createJsonRowsSelectedEvent(String rowId) throws JSONException {
    // never used
    String tableId = "x";
    JSONObject data = new JSONObject();
    JSONArray rowIds = new JSONArray();
    if (rowId != null) {
        rowIds.put(rowId);
    }
    data.put(JsonTable.PROP_ROW_IDS, rowIds);
    return new JsonEvent(tableId, JsonTable.EVENT_ROWS_SELECTED, data);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

Example 18 with JsonEvent

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

the class JsonTableTest method testIgnorableRowOrderChangedEvent.

/**
 * Response must not contain the row_order_changed event if the sort was triggered by the request
 */
@Test
public void testIgnorableRowOrderChangedEvent() throws JSONException {
    Table table = createTableFixture(5);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    IColumn column = table.getColumnSet().getFirstVisibleColumn();
    // ----------
    JsonEvent event = createJsonRowsSortedEvent(jsonTable.getColumnId(column), !column.isSortAscending());
    jsonTable.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "rowOrderChanged");
    assertTrue(responseEvents.size() == 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) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) Test(org.junit.Test)

Example 19 with JsonEvent

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

the class JsonTableTest method testClearSelectionEvent.

/**
 * Tests whether the model rows get correctly unselected
 */
@Test
public void testClearSelectionEvent() throws JSONException {
    Table table = createTableFixture(5);
    ITableRow row1 = table.getRow(1);
    table.selectRow(row1);
    assertTrue(row1.isSelected());
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonRowsSelectedEvent(null);
    jsonTable.handleUiEvent(event);
    assertTrue(table.getSelectedRows().size() == 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) 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 20 with JsonEvent

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

the class JsonTreeTest method createJsonSelectedEvent.

public static JsonEvent createJsonSelectedEvent(String nodeId) throws JSONException {
    // never used
    String desktopId = "x";
    JSONObject data = new JSONObject();
    JSONArray nodeIds = new JSONArray();
    nodeIds.put(nodeId);
    data.put(JsonTree.PROP_NODE_IDS, nodeIds);
    return new JsonEvent(desktopId, JsonTree.EVENT_NODES_SELECTED, data);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

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