Search in sources :

Example 1 with IActionVisitor

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

the class FormFieldContextMenu method handleOwnerEnabledChanged.

protected void handleOwnerEnabledChanged() {
    T container = getContainer();
    if (container == null) {
        return;
    }
    final boolean enabled = container.isEnabledIncludingParents();
    acceptVisitor(new IActionVisitor() {

        @Override
        public int visit(IAction action) {
            if (action instanceof IMenu) {
                IMenu menu = (IMenu) action;
                if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                    menu.setEnabledInheritAccessibility(enabled);
                }
            }
            return CONTINUE;
        }
    });
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction)

Example 2 with IActionVisitor

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

the class AbstractContextMenu method calculateLocalVisibility.

protected void calculateLocalVisibility() {
    final IActionFilter activeFilter = ActionUtility.createMenuFilterMenuTypes(getCurrentMenuTypes(), true);
    if (activeFilter != null) {
        final BooleanHolder visibleHolder = new BooleanHolder(false);
        acceptVisitor(new IActionVisitor() {

            @Override
            public int visit(IAction action) {
                if (action instanceof IMenu) {
                    IMenu menu = (IMenu) action;
                    if (menu.hasChildActions() || menu.isSeparator() || menu instanceof IContextMenu) {
                        return CONTINUE;
                    } else if (activeFilter.accept(menu)) {
                        visibleHolder.setValue(true);
                        return CANCEL;
                    }
                }
                return CONTINUE;
            }
        });
        setVisible(visibleHolder.getValue());
    }
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder)

Example 3 with IActionVisitor

use of org.eclipse.scout.rt.client.ui.action.IActionVisitor 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 4 with IActionVisitor

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

the class TableContextMenu method calculateEnableState.

/**
 * @param ownerValue
 */
protected void calculateEnableState(List<? extends ITableRow> ownerValue) {
    boolean enabled = getContainer().isEnabled();
    if (enabled) {
        for (ITableRow row : ownerValue) {
            if (!row.isEnabled()) {
                enabled = false;
                break;
            }
        }
    }
    final boolean inheritedEnability = enabled;
    acceptVisitor(new IActionVisitor() {

        @Override
        public int visit(IAction action) {
            if (action instanceof IMenu) {
                IMenu menu = (IMenu) action;
                if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                    menu.setEnabledInheritAccessibility(inheritedEnability);
                }
            }
            return CONTINUE;
        }
    });
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 5 with IActionVisitor

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

the class TableContextMenu method handleOwnerEnabledChanged.

protected void handleOwnerEnabledChanged() {
    ITable container = getContainer();
    if (container != null) {
        final boolean enabled = container.isEnabled();
        acceptVisitor(new IActionVisitor() {

            @Override
            public int visit(IAction action) {
                if (action instanceof IMenu) {
                    IMenu menu = (IMenu) action;
                    if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                        menu.setEnabled(enabled);
                    }
                }
                return CONTINUE;
            }
        });
    }
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable)

Aggregations

IAction (org.eclipse.scout.rt.client.ui.action.IAction)8 IActionVisitor (org.eclipse.scout.rt.client.ui.action.IActionVisitor)8 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)6 ArrayList (java.util.ArrayList)1 IActionFilter (org.eclipse.scout.rt.client.ui.action.IActionFilter)1 IContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.IContextMenu)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)1 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)1 BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)1