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