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());
}
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));
}
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());
}
Aggregations