Search in sources :

Example 1 with ActionFinder

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

the class AbstractDesktop method initConfig.

protected void initConfig() {
    m_eventHistory = createEventHistory();
    // add convenience observer for event history
    addDesktopListener(new DesktopListener() {

        @Override
        public void desktopChanged(DesktopEvent e) {
            IEventHistory<DesktopEvent> h = getEventHistory();
            if (h != null) {
                h.notifyEvent(e);
            }
        }
    });
    ClientSessionProvider.currentSession().getMemoryPolicy().registerDesktop(this);
    BEANS.get(IDeviceTransformationService.class).install(this);
    initDesktopExtensions();
    setTitle(getConfiguredTitle());
    setCssClass(getConfiguredCssClass());
    setSelectViewTabsKeyStrokesEnabled(getConfiguredSelectViewTabsKeyStrokesEnabled());
    setSelectViewTabsKeyStrokeModifier(getConfiguredSelectViewTabsKeyStrokeModifier());
    setLogoId(getConfiguredLogoId());
    setDisplayStyle(getConfiguredDisplayStyle());
    initDisplayStyle(getDisplayStyle());
    setCacheSplitterPosition(getConfiguredCacheSplitterPosition());
    List<IDesktopExtension> extensions = getDesktopExtensions();
    m_contributionHolder = new ContributionComposite(this);
    // outlines
    OrderedCollection<IOutline> outlines = new OrderedCollection<IOutline>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeOutlines(outlines);
        } catch (Exception t) {
            LOG.error("contributing outlines by {}", ext, t);
        }
    }
    List<IOutline> contributedOutlines = m_contributionHolder.getContributionsByClass(IOutline.class);
    outlines.addAllOrdered(contributedOutlines);
    // move outlines
    ExtensionUtility.moveModelObjects(outlines);
    setAvailableOutlines(outlines.getOrderedList());
    // actions (keyStroke, menu, viewButton, toolButton)
    List<IAction> actionList = new ArrayList<IAction>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeActions(actionList);
        } catch (Exception t) {
            LOG.error("contributing actions by {}", ext, t);
        }
    }
    List<IAction> contributedActions = m_contributionHolder.getContributionsByClass(IAction.class);
    actionList.addAll(contributedActions);
    // build complete menu and viewButton lists
    // only top level menus
    OrderedComparator orderedComparator = new OrderedComparator();
    List<IMenu> menuList = new ActionFinder().findActions(actionList, IMenu.class, false);
    ExtensionUtility.moveModelObjects(menuList);
    Collections.sort(menuList, orderedComparator);
    m_menus = menuList;
    List<IViewButton> viewButtonList = new ActionFinder().findActions(actionList, IViewButton.class, false);
    ExtensionUtility.moveModelObjects(viewButtonList);
    Collections.sort(viewButtonList, orderedComparator);
    m_viewButtons = viewButtonList;
    // add dynamic keyStrokes
    List<IKeyStroke> ksList = new ActionFinder().findActions(actionList, IKeyStroke.class, true);
    for (IKeyStroke ks : ksList) {
        try {
            ks.initAction();
        } catch (RuntimeException | PlatformError e) {
            LOG.error("could not initialize key stroke '{}'.", ks, e);
        }
    }
    addKeyStrokes(ksList.toArray(new IKeyStroke[ksList.size()]));
    // init outlines
    for (IOutline o : m_availableOutlines) {
        try {
            o.initTree();
        } catch (Exception e) {
            LOG.error("Could not init outline {}", o, e);
        }
    }
    addPropertyChangeListener(new P_LocalPropertyChangeListener());
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) IEventHistory(org.eclipse.scout.rt.client.ui.IEventHistory) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) DeepLinkException(org.eclipse.scout.rt.client.deeplink.DeepLinkException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IViewButton(org.eclipse.scout.rt.client.ui.action.view.IViewButton) IDeviceTransformationService(org.eclipse.scout.rt.client.transformation.IDeviceTransformationService) ActionFinder(org.eclipse.scout.rt.client.ui.action.ActionFinder)

Example 2 with ActionFinder

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

the class JsonMenuTest method testDontSendNonDisplayableMenus.

/**
 * Tests whether non displayable menus are sent.
 * <p>
 * This reduces response size and also leverages security because the menus are never visible to the user, not even
 * with the dev tools of the browser
 */
@Test
public void testDontSendNonDisplayableMenus() throws Exception {
    IMenu menu = new MenuWithNonDisplayableChild();
    ActionUtility.initActions(CollectionUtility.arrayList(menu));
    JsonMenu<IMenu> jsonMenu = UiSessionTestUtility.newJsonAdapter(m_uiSession, menu, null);
    JsonMenu<IMenu> jsonDisplayableMenu = jsonMenu.getAdapter(new ActionFinder().findAction(menu.getChildActions(), MenuWithNonDisplayableChild.DisplayableMenu.class));
    JsonMenu<IMenu> jsonNonDisplayableMenu = jsonMenu.getAdapter(new ActionFinder().findAction(menu.getChildActions(), MenuWithNonDisplayableChild.NonDisplayableMenu.class));
    // Adapter for NonDisplayableMenu must not exist
    assertNull(jsonNonDisplayableMenu);
    // Json response must not contain NonDisplayableMenu
    JSONObject json = jsonMenu.toJson();
    JSONArray jsonMenus = json.getJSONArray("childActions");
    assertEquals(1, jsonMenus.length());
    assertEquals(jsonDisplayableMenu.getId(), jsonMenus.get(0));
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.NonDisplayableMenu) DisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.DisplayableMenu) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) MenuWithNonDisplayableChild(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.NonDisplayableMenu) ActionFinder(org.eclipse.scout.rt.client.ui.action.ActionFinder) Test(org.junit.Test)

Example 3 with ActionFinder

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

the class JsonMenuTest method testDontSendNonDisplayableMenusSpecialCase.

/**
 * Special case: Menu is attached, then it is set to visibleGranted=false, then sent to the UI, then a property change
 * event occurs on that menu. We expect, that the adapter is automatically disposed again when setVisibleGranted=false
 * is called, because the response is still writable.
 */
@Test
public void testDontSendNonDisplayableMenusSpecialCase() throws Exception {
    IMenu menu = new MenuWithNonDisplayableChild();
    DisplayableMenu displayableMenu = new ActionFinder().findAction(menu.getChildActions(), MenuWithNonDisplayableChild.DisplayableMenu.class);
    NonDisplayableMenu nonDisplayableMenu = new ActionFinder().findAction(menu.getChildActions(), MenuWithNonDisplayableChild.NonDisplayableMenu.class);
    JsonMenu<IMenu> jsonMenu = UiSessionTestUtility.newJsonAdapter(m_uiSession, menu, null);
    JsonMenu<IMenu> jsonDisplayableMenu = jsonMenu.getAdapter(displayableMenu);
    JsonMenu<IMenu> jsonNonDisplayableMenu = jsonMenu.getAdapter(nonDisplayableMenu);
    // Both adapters exist
    assertNotNull(jsonDisplayableMenu);
    assertNotNull(jsonNonDisplayableMenu);
    // After attachment of adapter!
    ActionUtility.initActions(CollectionUtility.arrayList(menu));
    jsonDisplayableMenu = jsonMenu.getAdapter(displayableMenu);
    jsonNonDisplayableMenu = jsonMenu.getAdapter(nonDisplayableMenu);
    // Now only one adapter exists anymore
    assertNotNull(jsonDisplayableMenu);
    assertNull(jsonNonDisplayableMenu);
    // Check that no traces of the invisible menu are in JSON
    JSONObject json = m_uiSession.currentJsonResponse().toJson();
    assertEquals(1, json.getJSONObject("adapterData").length());
    assertNotNull(json.getJSONObject("adapterData").getJSONObject(jsonDisplayableMenu.getId()));
    // --------
    // Property change on invisible menu -> must not trigger anything in the JSON layer
    JsonTestUtility.endRequest(m_uiSession);
    nonDisplayableMenu.setTooltipText("Test-Tooltip");
    json = m_uiSession.currentJsonResponse().toJson();
    assertFalse(json.has("adapterData"));
    assertFalse(json.has("events"));
    // Property change on visible menu -> triggers event
    JsonTestUtility.endRequest(m_uiSession);
    displayableMenu.setTooltipText("Test-Tooltip");
    json = m_uiSession.currentJsonResponse().toJson();
    assertFalse(json.has("adapterData"));
    assertEquals(1, json.getJSONArray("events").length());
    // --------------------------------
    // Test case where the menu is already sent to the UI, then setVisibleGranted=false (this is too late, but it will only trigger a warning in the log)
    JsonTestUtility.endRequest(m_uiSession);
    displayableMenu.setVisibleGranted(false);
    IJsonAdapter<?> jsonDisplayableMenu2 = jsonMenu.getAdapter(displayableMenu);
    assertSame(jsonDisplayableMenu, jsonDisplayableMenu2);
    json = m_uiSession.currentJsonResponse().toJson();
    assertFalse(json.has("adapterData"));
    assertEquals(1, json.getJSONArray("events").length());
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.NonDisplayableMenu) DisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.DisplayableMenu) JSONObject(org.json.JSONObject) MenuWithNonDisplayableChild(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild) NonDisplayableMenu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.NonDisplayableMenu) ActionFinder(org.eclipse.scout.rt.client.ui.action.ActionFinder) Test(org.junit.Test)

Aggregations

ActionFinder (org.eclipse.scout.rt.client.ui.action.ActionFinder)3 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)3 MenuWithNonDisplayableChild (org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild)2 DisplayableMenu (org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.DisplayableMenu)2 NonDisplayableMenu (org.eclipse.scout.rt.ui.html.json.menu.fixtures.MenuWithNonDisplayableChild.NonDisplayableMenu)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 DeepLinkException (org.eclipse.scout.rt.client.deeplink.DeepLinkException)1 IDeviceTransformationService (org.eclipse.scout.rt.client.transformation.IDeviceTransformationService)1 IEventHistory (org.eclipse.scout.rt.client.ui.IEventHistory)1 IAction (org.eclipse.scout.rt.client.ui.action.IAction)1 IKeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)1 IViewButton (org.eclipse.scout.rt.client.ui.action.view.IViewButton)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 OrderedComparator (org.eclipse.scout.rt.platform.OrderedComparator)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)1 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)1