Search in sources :

Example 1 with TopLevelMenusBuilder

use of org.uberfire.workbench.model.menu.MenuFactory.TopLevelMenusBuilder in project kie-wb-common by kiegroup.

the class DefaultWorkbenchFeaturesMenusHelper method buildMenusFromNavTree.

public TopLevelMenusBuilder<MenuBuilder> buildMenusFromNavTree(NavTree navTree) {
    if (navTree == null) {
        return null;
    }
    MenuBuilder<TopLevelMenusBuilder<MenuBuilder>> builder = null;
    for (NavItem navItem : navTree.getRootItems()) {
        // Skip dividers
        if (navItem instanceof NavDivider) {
            continue;
        }
        // AF-953: Ignore empty groups
        if (navItem instanceof NavGroup && ((NavGroup) navItem).getChildren().isEmpty()) {
            continue;
        }
        // Build a top level menu entry
        if (builder == null) {
            builder = MenuFactory.newTopLevelMenu(navItem.getName());
        } else {
            builder = builder.endMenu().newTopLevelMenu(navItem.getName());
        }
        // Append its children
        if (navItem instanceof NavGroup) {
            List<MenuItem> childItems = buildMenuItemsFromNavGroup((NavGroup) navItem);
            builder.withItems(childItems);
        }
        // Append the place request
        NavWorkbenchCtx navCtx = NavWorkbenchCtx.get(navItem);
        if (navCtx.getResourceId() != null && ActivityResourceType.PERSPECTIVE.equals(navCtx.getResourceType())) {
            PlaceRequest placeRequest = resolvePlaceRequest(navCtx.getResourceId());
            builder = builder.place(placeRequest);
        }
    }
    return builder != null ? builder.endMenu() : null;
}
Also used : DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) PlaceRequest(org.uberfire.mvp.PlaceRequest) TopLevelMenusBuilder(org.uberfire.workbench.model.menu.MenuFactory.TopLevelMenusBuilder) MenuItem(org.uberfire.workbench.model.menu.MenuItem) NavWorkbenchCtx(org.dashbuilder.navigation.workbench.NavWorkbenchCtx) NavItem(org.dashbuilder.navigation.NavItem) NavDivider(org.dashbuilder.navigation.NavDivider) NavGroup(org.dashbuilder.navigation.NavGroup)

Aggregations

NavDivider (org.dashbuilder.navigation.NavDivider)1 NavGroup (org.dashbuilder.navigation.NavGroup)1 NavItem (org.dashbuilder.navigation.NavItem)1 NavWorkbenchCtx (org.dashbuilder.navigation.workbench.NavWorkbenchCtx)1 PlaceRequest (org.uberfire.mvp.PlaceRequest)1 DefaultPlaceRequest (org.uberfire.mvp.impl.DefaultPlaceRequest)1 TopLevelMenusBuilder (org.uberfire.workbench.model.menu.MenuFactory.TopLevelMenusBuilder)1 MenuItem (org.uberfire.workbench.model.menu.MenuItem)1