Search in sources :

Example 46 with JsonEvent

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

the class JsonForm method handleModelRequestEvent.

protected void handleModelRequestEvent(FormEvent event, boolean protect) {
    IJsonAdapter<?> childAdapter = findChildAdapter(event);
    if (childAdapter != null) {
        JSONObject json = new JSONObject();
        putProperty(json, PROP_FORM_FIELD, childAdapter.getId());
        JsonEvent jsonEvent = addActionEvent(getRequestEventName(event.getType()), json);
        if (protect) {
            jsonEvent.protect();
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

Example 47 with JsonEvent

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

the class JsonDesktopTest method testHandleModelDownloadResource.

@Test
public void testHandleModelDownloadResource() throws Exception {
    IDesktop desktop = new DesktopWithNonDisplayableOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    jsonDesktop.handleModelOpenUri(new BinaryResource("foo.txt", null), OpenUriAction.DOWNLOAD);
    jsonDesktop.handleModelOpenUri(new BinaryResource("TP6 ARL ; Zulassung (UVV) - Bearbeitung elektr. Fax-Eingang [-8874 , ABC-Prüfbericht] (1).pdf", null), OpenUriAction.DOWNLOAD);
    List<JsonEvent> events = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "openUri");
    JSONObject[] data = new JSONObject[2];
    data[0] = events.get(0).getData();
    data[1] = events.get(1).getData();
    // counter = 0 first for test run
    assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/0/foo.txt", data[0].getString("uri"));
    assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/1/TP6%2520ARL%2520%253B%2520Zulassung%2520%2528UVV%2529%2520-%2520Bearbeitung%2520elektr.%2520Fax-Eingang%2520%255B-8874%2520%252C%2520ABC-Pr%25C3%25BCfbericht%255D%2520%25281%2529.pdf", // counter = 1 second for test run
    data[1].getString("uri"));
    assertEquals("download", data[0].getString("action"));
    assertEquals("download", data[1].getString("action"));
    // cleanup
    Jobs.getJobManager().cancel(Jobs.newFutureFilterBuilder().andMatchExecutionHint(DownloadHandlerStorage.RESOURCE_CLEANUP_JOB_MARKER).toFilter(), true);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) DesktopWithNonDisplayableOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 48 with JsonEvent

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

Example 49 with JsonEvent

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

the class JsonOutlineViewButtonTest method testLazyLoadingOutline_onUiSelectionChanged.

@Test
public void testLazyLoadingOutline_onUiSelectionChanged() throws Exception {
    OutlineWithOneNode outline = new OutlineWithOneNode();
    IDesktop desktop = Mockito.mock(IDesktop.class);
    Mockito.when(desktop.getAvailableOutlines()).thenReturn(Collections.<IOutline>singletonList(outline));
    IOutlineViewButton button = new OutlineViewButton(desktop, outline.getClass());
    JsonOutlineViewButton<IOutlineViewButton> jsonViewButton = UiSessionTestUtility.newJsonAdapter(m_uiSession, button, null);
    assertNull(jsonViewButton.getAdapter(outline));
    JsonEvent event = createJsonActionEvent(jsonViewButton.getId());
    assertEquals("action", event.getType());
    jsonViewButton.handleUiEvent(event);
    // Outline needs to be created and sent if selection changes to true
    IJsonAdapter<?> outlineAdapter = jsonViewButton.getAdapter(outline);
    assertNotNull(outlineAdapter);
    String outlineId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonViewButton.getId(), "outline");
    assertEquals(outlineAdapter.getId(), outlineId);
}
Also used : OutlineWithOneNode(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode) IOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton) OutlineViewButton(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineViewButton) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) IOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 50 with JsonEvent

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

the class JsonBrowserFieldTest method testPostMessage.

@Test
public void testPostMessage() throws JSONException {
    String origin = "https://eclipse.org/scout/";
    String data = "42";
    Map<String, String> map = new HashMap<>();
    map.put("origin", origin);
    map.put("data", data);
    m_browserField.handleUiEvent(new JsonEvent("xyz", "postMessage", new JSONObject(map)));
    Assert.assertNotNull(m_lastPostMessage);
    Assert.assertEquals(origin, m_lastPostMessage[0]);
    Assert.assertEquals(data, m_lastPostMessage[1]);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) Test(org.junit.Test) BaseFormFieldTest(org.eclipse.scout.rt.ui.html.json.form.fields.BaseFormFieldTest)

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