Search in sources :

Example 1 with AbstractMenu

use of org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu in project scout.rt by eclipse.

the class P_BadVisitorCompositeField method testAddField.

@Test
public void testAddField() {
    P_TestCompositeField compositeField = new P_TestCompositeField();
    compositeField.setEnabled(false, false, false);
    IStringField add = new AbstractStringField() {
    };
    AbstractMenu menu = new AbstractMenu() {
    };
    add.getContextMenu().addChildAction(menu);
    compositeField.addField(add);
    assertFalse(add.isEnabledIncludingParents());
    assertTrue(add.isEnabled());
    assertFalse(menu.isEnabled());
}
Also used : AbstractMenu(org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu) IStringField(org.eclipse.scout.rt.client.ui.form.fields.stringfield.IStringField) AbstractStringField(org.eclipse.scout.rt.client.ui.form.fields.stringfield.AbstractStringField) Test(org.junit.Test)

Example 2 with AbstractMenu

use of org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu in project scout.rt by eclipse.

the class JsonMenuTest method testDontSendNonDisplayableMenusSpecialCaseWithEvent.

/**
 * Even more special case: Menus that are set to visibleGranted=false may already be referred in an event for another
 * (still available) adapter.
 */
@Test
public void testDontSendNonDisplayableMenusSpecialCaseWithEvent() throws Exception {
    // skip startup response
    JsonTestUtility.endRequest(m_uiSession);
    IForm form = new FormWithOneField();
    IMenu menu = new AbstractMenu() {

        @Override
        protected void execInitAction() {
            setVisibleGranted(false);
        }
    };
    IJsonAdapter<?> jsonForm = m_uiSession.createJsonAdapter(form, null);
    IJsonAdapter<?> jsonRootGroupBox = jsonForm.getAdapter(form.getRootGroupBox());
    // Test:
    // 3 adapters in response: Form, MainBox, StringField
    // 0 events in response
    assertEquals(3, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(0, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // ------------------
    // End request and simulate context menu change event on form
    JsonTestUtility.endRequest(m_uiSession);
    form.getRootGroupBox().getContextMenu().addChildAction(menu);
    // Test:
    // 1 adapters in response: Menu
    // 1 events in response: PROP_MENU
    assertEquals(1, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(1, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // ------------------
    // After attachment of adapter!
    ActionUtility.initActions(CollectionUtility.arrayList(menu));
    // Test:
    // - 0 adapters in response (-1 menu)
    // - 1 events in response: PROP_MENU <-- this would be wrong! But when the JSON string is generated, the adapter is removed from the list
    assertEquals(0, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(1, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // Check that the event's properties are empty after toJson()
    JSONObject json = m_uiSession.currentJsonResponse().toJson();
    assertFalse(json.has("adapterData"));
    JSONArray events = json.getJSONArray("events");
    assertEquals(1, events.length());
    assertEquals(jsonRootGroupBox.getId(), events.getJSONObject(0).get("target"));
    assertEquals("property", events.getJSONObject(0).get("type"));
    assertEquals(0, events.getJSONObject(0).getJSONObject("properties").getJSONArray("menus").length());
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) AbstractMenu(org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IForm(org.eclipse.scout.rt.client.ui.form.IForm) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Aggregations

AbstractMenu (org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu)2 Test (org.junit.Test)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1 AbstractStringField (org.eclipse.scout.rt.client.ui.form.fields.stringfield.AbstractStringField)1 IStringField (org.eclipse.scout.rt.client.ui.form.fields.stringfield.IStringField)1 FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1