use of com.haulmont.cuba.gui.config.MenuItem in project cuba by cuba-platform.
the class MenuBuilder method createSubMenu.
private void createSubMenu(JMenu jMenu, MenuItem item) {
List<MenuItem> itemChildren = new ArrayList<>(item.getChildren());
CollectionUtils.filter(itemChildren, object -> object.isPermitted(userSession));
List<MenuItemContainer> items = new ArrayList<>();
// prepare menu items
for (MenuItem child : itemChildren) {
if (child.getChildren().isEmpty()) {
if (child.isSeparator()) {
items.add(new MenuItemContainer());
} else {
JMenuItem jMenuItem = new JMenuItem(menuConfig.getItemCaption(child.getId()));
jMenuItem.setName(child.getId());
assignCommand(jMenuItem, child);
assignShortcut(jMenuItem, child);
items.add(new MenuItemContainer(jMenuItem));
}
} else {
JMenu jChildMenu = new JMenu(menuConfig.getItemCaption(child.getId()));
createSubMenu(jChildMenu, child);
if (!isMenuEmpty(jChildMenu)) {
items.add(new MenuItemContainer(jChildMenu));
}
}
}
// remove unnecessary separators
if (!items.isEmpty()) {
Iterator<MenuItemContainer> iterator = items.iterator();
JMenuItem menuItem = getNextMenuItem(iterator);
boolean useSeparator = false;
while (menuItem != null) {
if (useSeparator)
jMenu.addSeparator();
jMenu.add(menuItem);
useSeparator = false;
menuItem = null;
if (iterator.hasNext()) {
MenuItemContainer itemContainer = iterator.next();
if (!itemContainer.isSeparator())
menuItem = itemContainer.getMenuItem();
else {
menuItem = getNextMenuItem(iterator);
useSeparator = true;
}
}
}
}
}
use of com.haulmont.cuba.gui.config.MenuItem in project cuba by cuba-platform.
the class MenuBuilder method createSubMenu.
protected void createSubMenu(Window webWindow, AppMenu.MenuItem vItem, MenuItem item, UserSession session) {
if (item.isPermitted(session) && !item.getChildren().isEmpty()) {
for (MenuItem child : item.getChildren()) {
if (child.getChildren().isEmpty()) {
if (child.isPermitted(session)) {
if (child.isSeparator()) {
vItem.addChildItem(appMenu.createSeparator());
continue;
}
AppMenu.MenuItem menuItem = appMenu.createMenuItem(child.getId(), menuConfig.getItemCaption(child.getId()), null, createMenuBarCommand(child));
assignShortcut(webWindow, menuItem, child);
assignDescription(menuItem, child);
assignIcon(menuItem, child);
assignStyleName(menuItem, child);
vItem.addChildItem(menuItem);
}
} else {
if (child.isPermitted(session)) {
AppMenu.MenuItem menuItem = appMenu.createMenuItem(child.getId(), menuConfig.getItemCaption(child.getId()), null, null);
assignShortcut(webWindow, menuItem, child);
assignDescription(menuItem, child);
assignIcon(menuItem, child);
assignStyleName(menuItem, child);
createSubMenu(webWindow, menuItem, child, session);
if (!isMenuItemEmpty(menuItem)) {
vItem.addChildItem(menuItem);
}
}
}
}
}
}
use of com.haulmont.cuba.gui.config.MenuItem in project cuba by cuba-platform.
the class MenuBuilder method build.
protected void build(AppMenu appMenu, List<MenuItem> rootItems) {
this.appMenu = appMenu;
Window window = ComponentsHelper.getWindowImplementation(appMenu);
if (window == null) {
throw new IllegalStateException("AppMenu is not belong to Window");
}
for (MenuItem menuItem : rootItems) {
// AppMenu does not load top-level separators
if (menuItem.isPermitted(session) && !menuItem.isSeparator()) {
createMenuBarItem(window, menuItem);
}
}
removeExtraSeparators();
}
use of com.haulmont.cuba.gui.config.MenuItem in project cuba by cuba-platform.
the class SideMenuBuilder method build.
protected void build(SideMenu menu, List<MenuItem> rootItems) {
Window window = ComponentsHelper.getWindowImplementation(menu);
if (window == null) {
throw new IllegalStateException("SideMenu is not belong to Window");
}
for (MenuItem menuItem : rootItems) {
// AppMenu does not support separators
if (menuItem.isPermitted(session) && !menuItem.isSeparator()) {
createMenuBarItem(window, menu, menuItem);
}
}
removeExtraSeparators(menu);
}
use of com.haulmont.cuba.gui.config.MenuItem in project cuba by cuba-platform.
the class SideMenuBuilder method createSubMenu.
protected void createSubMenu(Window webWindow, SideMenu menu, SideMenu.MenuItem vItem, MenuItem parentItem, UserSession session) {
if (parentItem.isPermitted(session)) {
for (MenuItem child : parentItem.getChildren()) {
if (child.isSeparator()) {
continue;
}
if (child.isPermitted(session)) {
SideMenu.MenuItem menuItem = menu.createMenuItem(child.getId(), menuConfig.getItemCaption(child.getId()));
assignDescription(menuItem, child);
assignIcon(menuItem, child);
assignStyleName(menuItem, child);
if (child.getChildren().isEmpty()) {
menuItem.setCommand(createMenuBarCommand(child));
assignShortcut(webWindow, menuItem, child);
vItem.addChildItem(menuItem);
} else {
createSubMenu(webWindow, menu, menuItem, child, session);
assignExpanded(menuItem, child);
if (!isMenuItemEmpty(menuItem)) {
vItem.addChildItem(menuItem);
}
}
}
}
}
}