private void createMenuParentMapRec( MenuItem menu, MenuItem parentMenu, MenuItem stopMenu, Map<String, MenuItem> breadcrumbMap) { breadcrumbMap.put(menu.getId(), parentMenu); if (menu.getId().equals(stopMenu.getId())) return; for (MenuItem menuItem : menu.getItems()) { if (menuItem.getType() == MenuItemType.MENU) { createMenuParentMapRec(menuItem, menu, stopMenu, breadcrumbMap); } } }
@Override public boolean containsItem(String itemId) { List<MenuItem> items = menu.getItems(); if (items != null) { for (MenuItem submenuItem : items) { if (submenuItem.getId().equals(itemId)) return true; } } return false; }
@Override public List<MolgenisUiMenu> getBreadcrumb() { if (menu.equals(rootMenu)) return Collections.<MolgenisUiMenu>singletonList(this); Map<String, MenuItem> menuParentMap = new HashMap<String, MenuItem>(); createMenuParentMapRec(rootMenu, null, menu, menuParentMap); List<MolgenisUiMenu> breadcrumb = new ArrayList<MolgenisUiMenu>(); MenuItem currentMenu = menu; while (currentMenu != null) { breadcrumb.add(new MenuItemToMolgenisUiMenuAdapter(currentMenu, rootMenu)); currentMenu = menuParentMap.get(currentMenu.getId()); } return Lists.reverse(breadcrumb); }