
org.xlcloud.console.menu.MenuCollectorBean Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xlcloud.console.menu;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
/**
* Collects all menu item elements and keeps them for current session.
* @author Tomek Adamczewski, AMG.net
*/
@SessionScoped
@Named
public class MenuCollectorBean implements Serializable {
private static final long serialVersionUID = -6816011842956006625L;
private final Map groups = new HashMap<>();
/**
* Adds an new menu item to the collection
* @param menuItem menu item
*/
public void addMenuItem(MenuItem menuItem) {
MenuGroupLabel groupLabel = menuItem.getGroupLabel();
MenuGroup group = groups.get(groupLabel);
if (group == null) {
group = new MenuGroup(groupLabel);
groups.put(groupLabel, group);
}
if (!group.getItems().contains(menuItem)) {
group.addItem(menuItem);
}
}
/**
* @return the menu groups
*/
public List getGroups() {
return new ArrayList<>(groups.values());
}
/**
* Returns active menu item, matched by the specified path.
* @param path request path
* @return active menu item
*/
public MenuItem getActiveMenuItem(String path) {
for (MenuGroup menuGroup : groups.values()) {
MenuItem activeMenuItem = menuGroup.getActiveMenuItem(path);
if (activeMenuItem != null) {
return activeMenuItem;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy