Search in sources :

Example 36 with JsonEvent

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

the class JsonTreeTest method testIgnorableExpansionEvent.

/**
 * If the selection event triggers the selection of another node, the selection event must not be ignored.
 */
// TODO [7.0] cgu: Test fails due to scout model bug: selectNode puts first selection event AFTER this new selection event -> gets filtered in processEventBuffers. With table it works though.
// @Test
// public void testIgnorableSelectionEvent2() throws JSONException {
// List<ITreeNode> nodes = new LinkedList<>();
// final TreeNode firstNode = new TreeNode();
// final TreeNode secondNode = new TreeNode();
// 
// nodes.add(firstNode);
// nodes.add(secondNode);
// ITree tree = new Tree(nodes) {
// 
// @Override
// protected void execNodesSelected(TreeEvent e) {
// if (e.getNode().equals(secondNode)) {
// selectNode(firstNode);
// }
// }
// };
// tree.initTree();
// 
// JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
// JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(secondNode));
// 
// assertFalse(firstNode.isSelectedNode());
// assertFalse(secondNode.isSelectedNode());
// 
// jsonTree.handleUiEvent(event);
// 
// assertTrue(firstNode.isSelectedNode());
// assertFalse(secondNode.isSelectedNode());
// 
// List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(
// m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_SELECTED);
// assertTrue(responseEvents.size() == 1);
// 
// List<ITreeNode> treeNodes = jsonTree.extractTreeNodes(responseEvents.get(0).getData());
// assertEquals(firstNode, treeNodes.get(0));
// }
/**
 * Response must not contain the expansion event if the expansion was triggered by the request
 */
@Test
public void testIgnorableExpansionEvent() throws JSONException {
    ITree tree = createTreeWithOneNode();
    ITreeNode node = tree.getRootNode().getChildNode(0);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    // Check expanded = true
    JsonEvent event = createJsonExpansionEvent(jsonTree.getOrCreateNodeId(node), true);
    jsonTree.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODE_EXPANDED);
    assertTrue(responseEvents.size() == 0);
    // Check expanded = false
    event = createJsonExpansionEvent(jsonTree.getOrCreateNodeId(node), false);
    jsonTree.handleUiEvent(event);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODE_EXPANDED);
    assertTrue(responseEvents.size() == 0);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 37 with JsonEvent

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

the class JsonTreeTest method testNodesDeletedEvent.

/**
 * Tests whether a deletion event with correct node id gets sent whenever a node gets deleted.
 */
@Test
public void testNodesDeletedEvent() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    String node1Id = jsonTree.getOrCreateNodeId(nodes.get(1));
    tree.removeNode(nodes.get(1));
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_DELETED);
    assertTrue(responseEvents.size() == 1);
    assertEventTypeAndNodeIds(responseEvents.get(0), "nodesDeleted", node1Id);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 38 with JsonEvent

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

the class JsonTableTest method testColumnOrderChangedEvent_assertCellOrder.

@Test
public void testColumnOrderChangedEvent_assertCellOrder() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    IColumn<?> column0 = table.getColumns().get(0);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JSONObject jsonRow = jsonTable.tableRowToJson(table.getRow(0));
    JSONArray jsonCells = (JSONArray) jsonRow.get("cells");
    JsonEvent event = createJsonColumnMovedEvent(jsonTable.getColumnId(column0), 2);
    jsonTable.handleUiEvent(event);
    JSONObject jsonRowAfterMoving = jsonTable.tableRowToJson(table.getRow(0));
    JSONArray jsonCellsAfterMoving = (JSONArray) jsonRowAfterMoving.get("cells");
    // Expect same cell order, even if the columns are moved
    for (int i = 0; i < jsonCellsAfterMoving.length(); i++) {
        assertEquals(jsonCells.get(i), jsonCellsAfterMoving.get(i));
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) 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)

Example 39 with JsonEvent

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

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

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