Search in sources :

Example 1 with JsonEvent

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

the class JsonDesktopTest method testFormClosedBeforeRemovedInSameRequest.

@Test
public void testFormClosedBeforeRemovedInSameRequest() throws JSONException {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(jsonForm);
    desktop.showForm(form);
    jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(jsonForm);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
    assertEquals(1, responseEvents.size());
    form.start();
    form.doClose();
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
    assertEquals(0, responseEvents.size());
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
    assertEquals(1, responseEvents.size());
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    assertEquals(0, responseEvents.size());
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 2 with JsonEvent

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

the class JsonDesktopTest method testFormClosedBeforeRemovedInDifferentRequests.

@Test
public void testFormClosedBeforeRemovedInDifferentRequests() throws Exception {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(jsonForm);
    desktop.showForm(form);
    jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(jsonForm);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
    assertEquals(1, responseEvents.size());
    form.start();
    JsonTestUtility.endRequest(m_uiSession);
    // -------------------------------
    // New request:
    form.doClose();
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
    assertEquals(0, responseEvents.size());
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
    assertEquals(1, responseEvents.size());
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    // 0 instead of 1, because formClosed includes "formHide" implicitly. The event itself cannot be sent, because
    // the form adapter is already disposed when the form is closed.
    assertEquals(0, responseEvents.size());
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 3 with JsonEvent

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

the class JsonDesktopTest method testFormAddedAndRemoved.

@Test
public void testFormAddedAndRemoved() throws Exception {
    DesktopWithOneOutline desktop = new DesktopWithOneOutline();
    desktop.initDesktop();
    JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
    FormWithOneField form = new FormWithOneField();
    form.setDisplayParent(desktop);
    form.setShowOnStart(false);
    JsonForm formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(formAdapter);
    desktop.showForm(form);
    formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(formAdapter);
    JsonResponse jsonResp = m_uiSession.currentJsonResponse();
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(jsonResp, "formShow");
    assertTrue(responseEvents.size() == 1);
    JsonEvent event = responseEvents.get(0);
    String formId = event.getData().getString("form");
    // Add event must contain reference (by ID) to form.
    assertEquals(jsonDesktop.getId(), event.getTarget());
    assertEquals(formAdapter.getId(), formId);
    // adapter-data for form must exist in 'adapterData' property of response
    JSONObject json = jsonResp.toJson();
    JSONObject adapterData = JsonTestUtility.getAdapterData(json, formId);
    assertEquals(formAdapter.getId(), adapterData.getString("id"));
    assertEquals("Form", adapterData.getString("objectType"));
    String rootGroupBoxId = adapterData.getString("rootGroupBox");
    adapterData = JsonTestUtility.getAdapterData(json, rootGroupBoxId);
    assertEquals("GroupBox", adapterData.getString("objectType"));
    // we could continue to test the reference structure in the JSON response,
    // but for the moment this should be enough...
    JsonTestUtility.endRequest(m_uiSession);
    desktop.hideForm(form);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
    assertTrue(responseEvents.size() == 1);
    event = responseEvents.get(0);
    formId = event.getData().getString("form");
    // Remove event must only contain the id, no other properties
    assertEquals(jsonDesktop.getId(), event.getTarget());
    assertEquals(formAdapter.getId(), formId);
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) DesktopWithOneOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline) JSONObject(org.json.JSONObject) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) JsonResponse(org.eclipse.scout.rt.ui.html.json.JsonResponse) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 4 with JsonEvent

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

the class JsonOutlineTest method createNodeSelectionEvent.

protected JsonEvent createNodeSelectionEvent(JsonOutline<IOutline> jsonOutline, IPage page) throws JSONException {
    JSONObject eventData = new JSONObject();
    JSONArray nodeIds = new JSONArray();
    nodeIds.put(JsonTreeTest.getNodeId(jsonOutline, page));
    eventData.put("nodeIds", nodeIds);
    JsonEvent event = new JsonEvent(jsonOutline.getId(), JsonTree.EVENT_NODES_SELECTED, eventData);
    return event;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

Example 5 with JsonEvent

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

the class JsonTableTest method testColumnStructureChangedEvent.

/**
 * If column structure changes, we need to resend every row including its new cells.
 */
@Test
public void testColumnStructureChangedEvent() throws JSONException {
    TableWith3Cols table = new TableWith3Cols();
    table.fill(2);
    table.initTable();
    table.resetColumns();
    table.getColumnSet().getColumn(0).setVisible(false);
    IJsonAdapter<? super TableWith3Cols> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----
    table.getColumnSet().getColumn(0).setVisible(true);
    JsonResponse response = m_uiSession.currentJsonResponse();
    response.fireProcessBufferedEvents();
    List<JsonEvent> events = response.getEventList();
    assertEquals(4, events.size());
    assertEquals(JsonTable.EVENT_COLUMN_STRUCTURE_CHANGED, events.get(0).getType());
    assertEquals(JsonEventType.PROPERTY.getEventType(), events.get(1).getType());
    assertEquals(JsonTable.EVENT_ALL_ROWS_DELETED, events.get(2).getType());
    assertEquals(JsonTable.EVENT_ROWS_INSERTED, events.get(3).getType());
}
Also used : JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) JsonResponse(org.eclipse.scout.rt.ui.html.json.JsonResponse) 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