Search in sources :

Example 1 with IActionFilter

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

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

the class TableMenuTest method testRowDisabledSingleSelection.

/**
 * Tests menu disabled if row disabled, single selection
 */
@Test
public void testRowDisabledSingleSelection() {
    Table t = new Table();
    t.addRowsByMatrix(TEST_ROWS);
    ITableContextMenu contextMenu = t.getContextMenu();
    t.getRow(0).setEnabled(false);
    t.selectRows(CollectionUtility.arrayList(t.getRow(0)), false);
    IActionFilter filter = ActionUtility.createMenuFilterMenuTypes(contextMenu.getCurrentMenuTypes(), true);
    List<IMenu> visibleMenus = ActionUtility.normalizedActions(contextMenu.getChildActions(), filter);
    assertEquals(false, visibleMenus.get(0).isEnabled());
}
Also used : ITableContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ITableContextMenu) AbstractTable(org.eclipse.scout.rt.client.ui.basic.table.AbstractTable) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) Test(org.junit.Test)

Example 3 with IActionFilter

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

the class TableMenuTest method testSingleSelection.

/**
 * Tests the visibility for a single selection menu
 */
@Test
public void testSingleSelection() {
    Table t = new Table();
    t.addRowsByMatrix(TEST_ROWS);
    ITableContextMenu contextMenu = t.getContextMenu();
    // single hugo boss
    t.selectRows(CollectionUtility.arrayList(t.getRow(0)), false);
    IActionFilter filter = ActionUtility.createMenuFilterMenuTypes(contextMenu.getCurrentMenuTypes(), true);
    List<IMenu> visibleMenus = ActionUtility.normalizedActions(contextMenu.getChildActions(), filter);
    assertEquals(2, visibleMenus.size());
    assertEquals("SingleSelectionMenu", visibleMenus.get(0).getClass().getSimpleName());
    assertEquals("HugoBossMenu", visibleMenus.get(1).getClass().getSimpleName());
    // single only meier
    t.selectRows(CollectionUtility.arrayList(t.getRow(1)), false);
    filter = ActionUtility.createMenuFilterMenuTypes(contextMenu.getCurrentMenuTypes(), true);
    visibleMenus = ActionUtility.normalizedActions(contextMenu.getChildActions(), filter);
    assertEquals(1, visibleMenus.size());
    assertEquals("SingleSelectionMenu", visibleMenus.get(0).getClass().getSimpleName());
}
Also used : ITableContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ITableContextMenu) AbstractTable(org.eclipse.scout.rt.client.ui.basic.table.AbstractTable) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) Test(org.junit.Test)

Example 4 with IActionFilter

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

the class TableMenuTest method setMultiSelection.

/**
 * Tests the visibility for a multi selection menu
 */
@Test
public void setMultiSelection() {
    Table t = new Table();
    t.addRowsByMatrix(TEST_ROWS);
    ITableContextMenu contextMenu = t.getContextMenu();
    // multi selection
    t.selectRows(CollectionUtility.arrayList(t.getRow(0), t.getRow(1)), false);
    IActionFilter filter = ActionUtility.createMenuFilterMenuTypes(contextMenu.getCurrentMenuTypes(), true);
    List<IMenu> visibleMenus = ActionUtility.normalizedActions(contextMenu.getChildActions(), filter);
    assertEquals(1, visibleMenus.size());
    assertEquals("MultiSelectionMenu", visibleMenus.get(0).getClass().getSimpleName());
}
Also used : ITableContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ITableContextMenu) AbstractTable(org.eclipse.scout.rt.client.ui.basic.table.AbstractTable) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) Test(org.junit.Test)

Example 5 with IActionFilter

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

the class AbstractPageWithNodes method updateContextMenusForSelection.

protected void updateContextMenusForSelection() {
    // remove old
    if (m_pageMenusOfSelection != null) {
        getTable().getContextMenu().removeChildActions(m_pageMenusOfSelection);
        m_pageMenusOfSelection = null;
    }
    List<IMenu> pageMenus = new ArrayList<IMenu>();
    List<ITableRow> selectedRows = getTable().getSelectedRows();
    if (CollectionUtility.size(selectedRows) == 1) {
        ITreeNode node = getTreeNodeFor(CollectionUtility.firstElement(selectedRows));
        if (node instanceof IPageWithNodes) {
            IPageWithNodes pageWithNodes = (IPageWithNodes) node;
            IActionFilter filter = ActionUtility.createMenuFilterMenuTypes(CollectionUtility.hashSet(TreeMenuType.SingleSelection), false);
            List<IMenu> menus = ActionUtility.getActions(pageWithNodes.getMenus(), filter);
            for (IMenu m : menus) {
                pageMenus.add(new OutlineMenuWrapper(m, TREE_MENU_TYPE_MAPPER, filter));
            }
        }
    }
    getTable().getContextMenu().addChildActions(pageMenus);
    m_pageMenusOfSelection = pageMenus;
}
Also used : OutlineMenuWrapper(org.eclipse.scout.rt.client.ui.desktop.outline.OutlineMenuWrapper) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ArrayList(java.util.ArrayList) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Aggregations

IActionFilter (org.eclipse.scout.rt.client.ui.action.IActionFilter)9 ITableContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.ITableContextMenu)7 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)7 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)7 Test (org.junit.Test)7 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)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 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)1 OutlineMenuWrapper (org.eclipse.scout.rt.client.ui.desktop.outline.OutlineMenuWrapper)1 BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)1