Search in sources :

Example 6 with Outline

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline in project scout.rt by eclipse.

the class JsonOutlineTest method testChildAdaptersCreated.

/**
 * Tests whether the adapters for the detail forms get created
 */
@Test
public void testChildAdaptersCreated() {
    TablePage tablePage = new TablePage(1, new TablePage.NodePageWithFormFactory());
    NodePageWithForm nodePage = new NodePageWithForm();
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(nodePage);
    pages.add(tablePage);
    IOutline outline = new Outline(pages);
    // Activate nodes (forms get created lazily on activation)
    outline.selectNode(nodePage);
    outline.selectNode(tablePage);
    IPage rowPage = (IPage) tablePage.getTreeNodeFor(tablePage.getTable().getRow(0));
    outline.selectNode(rowPage);
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, null);
    Assert.assertNotNull(jsonOutline.getAdapter(nodePage.getDetailForm()));
    Assert.assertNotNull(jsonOutline.getAdapter(rowPage.getDetailForm()));
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) TablePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) NodePageWithForm(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePageWithForm) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Example 7 with Outline

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline in project scout.rt by eclipse.

the class JsonOutlineTest method testPageDisposal.

@Test
public void testPageDisposal() {
    TablePage tablePage = new TablePage(1, new TablePage.NodePageWithFormFactory());
    NodePage nodePage = new NodePage();
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(nodePage);
    IOutline outline = new Outline(pages);
    outline.addChildNode(nodePage, tablePage);
    outline.selectNode(tablePage);
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, null);
    List<ITreeNode> allNodes = JsonTreeTest.getAllTreeNodes(outline);
    List<String> allNodeIds = new LinkedList<String>();
    for (ITreeNode node : allNodes) {
        String nodeId = JsonTreeTest.getOrCreateNodeId(jsonOutline, node);
        allNodeIds.add(nodeId);
        assertNotNull(nodeId);
        assertNotNull(JsonTreeTest.getNode(jsonOutline, nodeId));
    }
    outline.removeNode(nodePage);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // Verify nodes get unregistered
    for (ITreeNode node : allNodes) {
        assertNull(JsonTreeTest.optNodeId(jsonOutline, node));
    }
    for (String nodeId : allNodeIds) {
        assertNull(JsonTreeTest.getNode(jsonOutline, nodeId));
    }
    // Verify table adapter gets unregistered
    assertNull(m_uiSession.getJsonAdapter(tablePage.getTable(), m_uiSession.getRootJsonAdapter()));
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) LinkedList(java.util.LinkedList) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TablePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage) NodePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePage) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Example 8 with Outline

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline in project scout.rt by eclipse.

the class JsonOutlineTest method testPageDisposalOnRemoveAll.

@Test
public void testPageDisposalOnRemoveAll() throws JSONException {
    NodePage nodePage = new NodePage();
    // trigger table creation
    nodePage.getTable(true);
    NodePage childPage = new NodePage();
    // trigger table creation
    childPage.getTable(true);
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(nodePage);
    IOutline outline = new Outline(pages);
    outline.addChildNode(nodePage, childPage);
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, null);
    // Assert that pages have an id
    String nodeId = JsonTreeTest.getOrCreateNodeId(jsonOutline, nodePage);
    assertNotNull(nodeId);
    assertNotNull(JsonTreeTest.getNode(jsonOutline, nodeId));
    String childId = JsonTreeTest.getOrCreateNodeId(jsonOutline, childPage);
    assertNotNull(childId);
    assertNotNull(JsonTreeTest.getNode(jsonOutline, childId));
    // Assert that adapters for table have been created
    assertNotNull(m_uiSession.getJsonAdapter(nodePage.getTable(), m_uiSession.getRootJsonAdapter()));
    assertNotNull(m_uiSession.getJsonAdapter(childPage.getTable(), m_uiSession.getRootJsonAdapter()));
    // Remove all child nodes of the root page
    outline.removeAllChildNodes(outline.getRootNode());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // Assert that pages have been disposed
    assertNull(JsonTreeTest.getNode(jsonOutline, nodeId));
    assertNull(JsonTreeTest.getNode(jsonOutline, childId));
    // Assert that tables have been disposed
    assertNull(m_uiSession.getJsonAdapter(nodePage.getTable(), m_uiSession.getRootJsonAdapter()));
    assertNull(m_uiSession.getJsonAdapter(childPage.getTable(), m_uiSession.getRootJsonAdapter()));
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) NodePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePage) ArrayList(java.util.ArrayList) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Example 9 with Outline

use of org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline in project scout.rt by eclipse.

the class JsonOutlineTest method testNoEventsFiredOnChildPageCreation.

/**
 * Tests that no events are fired during page initialization
 */
@Test
public void testNoEventsFiredOnChildPageCreation() throws JSONException {
    final Holder<Integer> initPageCounter = new Holder<>(Integer.class);
    initPageCounter.setValue(0);
    // Build an outline with two nodes, where the second node has a child node
    IPage page1 = new AbstractPageWithNodes() {
    };
    IPage page2 = new AbstractPageWithNodes() {

        @Override
        protected void execCreateChildPages(List<IPage<?>> pageList) {
            pageList.add(new AbstractPageWithNodes() {

                @Override
                protected void execInitPage() {
                    // Change some properties (this would normally fire events, but we are inside execInitPage())
                    setLeaf(!isLeaf());
                    getCellForUpdate().setText("Test");
                    initPageCounter.setValue(initPageCounter.getValue() + 1);
                }
            });
            super.execCreateChildPages(pageList);
        }
    };
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(page2);
    IOutline outline = new Outline(pages);
    outline.selectNode(page1);
    // Outline to JsonOutline
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, m_uiSession.getRootJsonAdapter());
    // simulate "send to client"
    jsonOutline.toJson();
    Assert.assertEquals(0, initPageCounter.getValue().intValue());
    // Simulate "select page2" event
    JsonEvent event = createNodeSelectionEvent(jsonOutline, page2);
    jsonOutline.handleUiEvent(event);
    assertEquals(1, initPageCounter.getValue().intValue());
    // Get all events for the outline (ignore table events)
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), null, jsonOutline.getId());
    // Check that we got only two events: page-changed (because the table was created), node insertion
    assertEquals(2, responseEvents.size());
    assertEquals("pageChanged", responseEvents.get(0).getType());
    assertEquals(JsonTree.EVENT_NODES_INSERTED, responseEvents.get(1).getType());
}
Also used : AbstractPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.AbstractPageWithNodes) Holder(org.eclipse.scout.rt.platform.holders.Holder) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) Test(org.junit.Test)

Aggregations

IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)9 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)9 Outline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 JsonTreeTest (org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest)7 TablePage (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage)4 NodePage (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePage)3 LinkedList (java.util.LinkedList)2 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 JsonOutline (org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline)2 NodePageWithForm (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.NodePageWithForm)2 JSONObject (org.json.JSONObject)2 List (java.util.List)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)1 AbstractPageWithNodes (org.eclipse.scout.rt.client.ui.desktop.outline.pages.AbstractPageWithNodes)1 Holder (org.eclipse.scout.rt.platform.holders.Holder)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)1