use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTreeTest method testIgnorableSelectionEvent.
/**
* Response must not contain the selection event if the selection was triggered by the request
*/
@Test
public void testIgnorableSelectionEvent() throws JSONException {
ITree tree = createTreeWithOneNode();
ITreeNode node = tree.getRootNode().getChildNode(0);
JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(node));
jsonTree.handleUiEvent(event);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_SELECTED);
assertTrue(responseEvents.size() == 0);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTreeTest method testWrongEventOrder.
/**
* Tests that events are ignored when nodes are not yet inserted.
*/
@Test
public void testWrongEventOrder() 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);
TreeNode newNode = new TreeNode();
jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODE_EXPANDED, newNode));
jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODES_INSERTED, nodes.get(0), Collections.singletonList(newNode)));
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(1, events.size());
assertEquals("nodesInserted", events.get(0).getType());
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTreeTest method testNodeFilter_events.
@Test
public void testNodeFilter_events() throws JSONException {
TreeNode nodeToFilter = new TreeNode();
nodeToFilter.setEnabled(false);
List<ITreeNode> nodes = new ArrayList<ITreeNode>();
nodes.add(nodeToFilter);
nodes.add(new TreeNode());
nodes.add(new TreeNode());
nodes.add(new TreeNode());
ITree tree = createTree(nodes);
JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
jsonTree.toJson();
String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
assertNotNull(node0Id);
assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
tree.addNodeFilter(new ITreeNodeFilter() {
@Override
public boolean accept(ITreeNode node, int level) {
return node.isEnabled();
}
});
JsonTestUtility.processBufferedEvents(m_uiSession);
assertNull(jsonTree.optNodeId(nodes.get(0)));
assertNull(jsonTree.optTreeNodeForNodeId(node0Id));
List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(1, events.size());
assertEventTypeAndNodeIds(events.get(0), "nodesDeleted", node0Id);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonTreeTest method testInsertAndDeleteInSameRequest.
@Test
public void testInsertAndDeleteInSameRequest() throws Exception {
// Note: A test for the same problem (but without a real tree) can be found here:
// org.eclipse.scout.rt.client.ui.basic.tree.TreeEventBufferTest.testInsertAndRemoveInSameRequest()
ITree tree = new Tree();
tree.setRootNode(new TreeNode("Root"));
final List<TreeEvent> treeEventCollector = new ArrayList<>();
tree.addTreeListener(new TreeAdapter() {
@Override
public void treeChanged(TreeEvent e) {
treeEventCollector.add(e);
}
});
IJsonAdapter<? super ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
m_uiSession.currentJsonResponse().addAdapter(jsonTree);
JSONObject response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #1: " + response);
JsonTestUtility.endRequest(m_uiSession);
// ----------------
// (root)
// +-[A]
// +-[B]
ITreeNode nodeA = new TreeNode("A");
ITreeNode nodeB = new TreeNode("B");
// Insert A and B in one "tree changing" batch
// -> TreeEventBuffer should remove the second event (because B is a sub-node of A)
tree.setTreeChanging(true);
tree.addChildNode(tree.getRootNode(), nodeA);
tree.addChildNode(nodeA, nodeB);
tree.setTreeChanging(false);
assertEquals(1, treeEventCollector.size());
treeEventCollector.clear();
// Remove B, then A (in two separate calls)
// -> TreeEventBuffer should remove the second event (because B is a sub-node of A), altough
// only an insertion event for A exists (and A.getChildNodes() returns nothing)
tree.removeAllChildNodes(nodeA);
tree.removeAllChildNodes(tree.getRootNode());
assertEquals(2, treeEventCollector.size());
treeEventCollector.clear();
assertEquals(0, nodeA.getChildNodeCount());
assertEquals(0, tree.getRootNode().getChildNodeCount());
// Process the buffer
// -> TreeEventBuffer should remove all events
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(0, events.size());
response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #2: " + response);
JsonTestUtility.endRequest(m_uiSession);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonListBoxTest method testReloadAndRowFilterChange.
/**
* Usecase:
* <p>
* Listbox has a filter.<br>
* 1. Reload the listbox -> generates rowsUpdated and rowOrderChanged events<br>
* 2. Add a new filter -> generates rowFilterChanged which are converted into rowsDeleted or rowsInserted Asserts that
* rowOrderChanged event contains the correct rows.
*/
@Test
public void testReloadAndRowFilterChange() throws Exception {
ListBox listBox = new ListBox();
ITable table = listBox.getTable();
listBox.initField();
JsonListBox<Long, IListBox<Long>> jsonListBox = m_uiSession.createJsonAdapter(listBox, null);
JsonTable<ITable> jsonTable = jsonListBox.getAdapter(table);
// Filter the first row
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow row) {
Long key = (Long) row.getKeyValues().get(0);
if (key.equals(0L)) {
return false;
}
return true;
}
});
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
// "Send" listbox to UI
jsonListBox.toJson();
JsonTestUtility.processBufferedEvents(m_uiSession);
JsonTestUtility.endRequest(m_uiSession);
assertEquals(0, m_uiSession.currentJsonResponse().getEventList().size());
// Load listbox BEFORE adding a new filter -> generates rowOrderChanged before the filter events
listBox.loadListBoxData();
// Filter second row as well
String row1Id = jsonTable.getTableRowId(table.findRowByKey(Arrays.asList(1L)));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow row) {
Long key = (Long) row.getKeyValues().get(0);
if (key.equals(1L)) {
return false;
}
return true;
}
});
assertEquals(1, table.getFilteredRowCount());
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> eventList = m_uiSession.currentJsonResponse().getEventList();
JsonEvent jsonEvent = eventList.get(0);
assertEquals("rowsDeleted", jsonEvent.getType());
assertEquals(1, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).length());
assertEquals(row1Id, jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS).get(0));
// eventList.get(1) is the rows_updated event, not of interest here
jsonEvent = eventList.get(2);
assertEquals("rowOrderChanged", jsonEvent.getType());
JSONArray jsonRowIds = jsonEvent.getData().getJSONArray(JsonTable.PROP_ROW_IDS);
assertEquals(1, jsonRowIds.length());
}
Aggregations