Search in sources :

Example 1 with IContextMenu

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

the class MenuUtility method getMenuByClass.

/**
 * @return the sub-menu of the given context menu owner that implements the given type. If no implementation is found,
 *         <code>null</code> is returned. Note: This method uses instance-of checks, hence the menu replacement
 *         mapping is not required.
 * @throws IllegalStateException
 *           when more than one menu implements the given type
 * @throws IllegalArgumentException
 *           when no context menu owner is provided.
 */
public static <T extends IMenu> T getMenuByClass(IContextMenuOwner contextMenuOwner, final Class<T> menuType) {
    if (contextMenuOwner == null) {
        throw new IllegalArgumentException("Argument 'contextMenuOwner' must not be null");
    }
    IContextMenu contextMenu = contextMenuOwner.getContextMenu();
    if (contextMenu == null || menuType == null) {
        return null;
    }
    final List<T> collectedMenus = new ArrayList<T>();
    contextMenu.acceptVisitor(new IActionVisitor() {

        @Override
        public int visit(IAction action) {
            if (menuType.isInstance(action)) {
                T menu = menuType.cast(action);
                collectedMenus.add(menu);
            }
            return CONTINUE;
        }
    });
    if (collectedMenus.isEmpty()) {
        return null;
    }
    if (collectedMenus.size() == 1) {
        return collectedMenus.get(0);
    }
    throw new IllegalStateException("Ambiguous menu type " + menuType.getName() + "! More than one implementation was found: " + CollectionUtility.format(collectedMenus));
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IAction(org.eclipse.scout.rt.client.ui.action.IAction) IContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.IContextMenu) ArrayList(java.util.ArrayList)

Example 2 with IContextMenu

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

the class AbstractButton method initConfig.

@Override
protected void initConfig() {
    super.initConfig();
    setSystemType(getConfiguredSystemType());
    setDisplayStyleInternal(getConfiguredDisplayStyle());
    setProcessButton(getConfiguredProcessButton());
    setDefaultButton(getConfiguredDefaultButton());
    setIconId(getConfiguredIconId());
    setKeyStroke(getConfiguredKeyStroke());
    setKeyStrokeScopeClass(getConfiguredKeyStrokeScopeClass());
    setPreventDoubleClick(getConfiguredPreventDoubleClick());
    // menus
    List<Class<? extends IMenu>> declaredMenus = getDeclaredMenus();
    List<IMenu> contributedMenus = m_contributionHolder.getContributionsByClass(IMenu.class);
    OrderedCollection<IMenu> menus = new OrderedCollection<IMenu>();
    for (Class<? extends IMenu> menuClazz : declaredMenus) {
        IMenu menu;
        menu = ConfigurationUtility.newInnerInstance(this, menuClazz);
        menus.addOrdered(menu);
    }
    menus.addAllOrdered(contributedMenus);
    injectMenusInternal(menus);
    new MoveActionNodesHandler<IMenu>(menus).moveModelObjects();
    IContextMenu contextMenu = new FormFieldContextMenu<IButton>(this, menus.getOrderedList());
    contextMenu.setContainerInternal(this);
    setContextMenu(contextMenu);
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) FormFieldContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.internal.FormFieldContextMenu) IContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.IContextMenu) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection)

Aggregations

IContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.IContextMenu)2 ArrayList (java.util.ArrayList)1 IAction (org.eclipse.scout.rt.client.ui.action.IAction)1 IActionVisitor (org.eclipse.scout.rt.client.ui.action.IActionVisitor)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 FormFieldContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.internal.FormFieldContextMenu)1 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)1