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