Search in sources :

Example 41 with JsonEvent

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

the class JsonTableTest method testIgnorableSelectionEvent.

/**
 * Response must not contain the selection event if the selection was triggered by the request
 */
@Test
public void testIgnorableSelectionEvent() throws JSONException {
    Table table = createTableFixture(5);
    ITableRow row = table.getRow(2);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonRowsSelectedEvent(jsonTable.getOrCreateRowId(row));
    jsonTable.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTable.EVENT_ROWS_SELECTED);
    assertTrue(responseEvents.size() == 0);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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 42 with JsonEvent

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

the class JsonTabBoxTest method handleUiTabSelected.

private void handleUiTabSelected(String selectedTabId) {
    JSONObject data = new JSONObject();
    data.put("selectedTab", selectedTabId);
    m_tabBox.handleUiPropertyChange("selectedTab", new JsonEvent("?", "?", data).toJson());
}
Also used : JSONObject(org.json.JSONObject) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent)

Example 43 with JsonEvent

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

the class JsonTableTest method testSelectionEvent.

/**
 * Tests whether the model row gets correctly selected
 */
@Test
public void testSelectionEvent() throws JSONException {
    Table table = createTableFixture(5);
    assertNull(table.getSelectedRow());
    ITableRow row = table.getRow(2);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    // ----------
    JsonEvent event = createJsonRowsSelectedEvent(jsonTable.getOrCreateRowId(row));
    jsonTable.handleUiEvent(event);
    assertTrue(row.isSelected());
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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 44 with JsonEvent

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

the class JsonFormTableControlTest method testLazyLoadingForm_onUiSelectionChanged.

@Test
public void testLazyLoadingForm_onUiSelectionChanged() throws Exception {
    FormWithOneField form = new FormWithOneField();
    FormTableControl control = new FormTableControl();
    control.setTable(new Table());
    control.setForm(form);
    control.decorateForm();
    JsonTableControl<ITableControl> jsonControl = UiSessionTestUtility.newJsonAdapter(m_uiSession, control, null);
    assertNull(jsonControl.getAdapter(form));
    JsonEvent event = createJsonSelectedEvent(jsonControl.getId(), true);
    jsonControl.handleUiEvent(event);
    // Form needs to be created and sent if selection changes to true
    IJsonAdapter<?> formAdapter = jsonControl.getAdapter(form);
    assertNotNull(formAdapter);
    String formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertEquals(formAdapter.getId(), formId);
    JsonTestUtility.endRequest(m_uiSession);
    // Don't send form again on subsequent selection changes
    event = createJsonSelectedEvent(jsonControl.getId(), false);
    jsonControl.handleUiEvent(event);
    formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertNull(formId);
    JsonTestUtility.endRequest(m_uiSession);
    event = createJsonSelectedEvent(jsonControl.getId(), true);
    jsonControl.handleUiEvent(event);
    formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertNull(formId);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITableControl(org.eclipse.scout.rt.client.ui.basic.table.controls.ITableControl) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) FormTableControl(org.eclipse.scout.rt.ui.html.json.table.fixtures.FormTableControl) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Example 45 with JsonEvent

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

the class JsonDesktop method addActionEventForEachDisplayParentAdapter.

protected List<JsonEvent> addActionEventForEachDisplayParentAdapter(String eventName, String propModelAdapterId, IJsonAdapter<?> modelAdapter, IDisplayParent displayParent, int position) {
    List<JsonEvent> events = new ArrayList<>();
    for (IJsonAdapter<IDisplayParent> displayParentAdapter : getUiSession().getJsonAdapters(displayParent)) {
        JSONObject jsonEvent = new JSONObject();
        jsonEvent.put(propModelAdapterId, modelAdapter.getId());
        jsonEvent.put(PROP_DISPLAY_PARENT, displayParentAdapter.getId());
        if (position >= 0) {
            jsonEvent.put(PROP_POSITION, position);
        }
        // Add modelAdapter as "referenced adapter" to event (to remove event when
        // modelAdapter is disposed but desktop is not)
        events.add(addActionEvent(eventName, modelAdapter, jsonEvent));
    }
    return events;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) IDisplayParent(org.eclipse.scout.rt.client.ui.IDisplayParent)

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