WorkbenchMegaMenuPresenter extends WorkbenchBaseMenuPresenter { public void enableMenuItem(final String menuItemId, final boolean enabled) { final CanBeDisabled menuItem = canBeDisabledMenuItemByIdentifier.get(menuItemId); if (menuItem != null) { if (enabled) { menuItem.enable(); } else { menuItem.disable(); } } } WorkbenchMegaMenuPresenter(final AuthorizationManager authzManager,
                                      final PerspectiveManager perspectiveManager,
                                      final ActivityManager activityManager,
                                      final User identity,
                                      final View view,
                                      final ManagedInstance<MegaMenuBrand> megaMenuBrands,
                                      final PlaceManager placeManager,
                                      final AuthorizationManager authorizationManager,
                                      final SessionInfo sessionInfo,
                                      final ManagedInstance<ChildMenuItemPresenter> childMenuItemPresenters,
                                      final ManagedInstance<GroupMenuItemPresenter> groupMenuItemPresenters,
                                      final ManagedInstance<ChildContextMenuItemPresenter> childContextMenuItemPresenters,
                                      final ManagedInstance<GroupContextMenuItemPresenter> groupContextMenuItemPresenters,
                                      final Workbench workbench,
                                      final ExperimentalActivitiesAuthorizationManager experimentalActivitiesAuthorizationManager); IsElement getView(); void clear(); void addMenuItem(final String id,
                            final String label,
                            final String parentId,
                            final Command command,
                            final MenuPosition position); void addCustomMenuItem(final IsElement menu,
                                  final MenuPosition position); void addCustomMenuItem(IsWidget menu,
                                  MenuPosition position); void addGroupMenuItem(final String id,
                                 final String label,
                                 final MenuPosition position); void selectMenuItem(final String id); void addContextMenuItem(final String menuItemId,
                                   final String id,
                                   final String label,
                                   final String parentId,
                                   final Command command,
                                   final MenuPosition position); void addContextGroupMenuItem(final String menuItemId,
                                        final String id,
                                        final String label,
                                        final MenuPosition position); void clearContextMenu(); void enableMenuItem(final String menuItemId,
                               final boolean enabled); void enableContextMenuItem(final String menuItemId,
                                      final boolean enabled); void onPerspectiveChange(final PerspectiveChange perspectiveChange); void setupSetVisibleMenuItem(MenuItemPerspective menuItemPerspective);  }
@Test public void testSetupEnableDisableMenuItemCommand() { final String label = "command"; final Command command = mock(Command.class); final Menus menus = MenuFactory.newSimpleItem(label).respondsWith(command).endMenu().build(); when(authzManager.authorize(menus.getItems().get(0), identity)).thenReturn(true); presenter.addMenus(menus); verify(presenter).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(true); verify(presenter, times(2)).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(false); verify(presenter).enableMenuItem(anyString(), eq(false)); }
@Test public void testSetupEnableDisableMenuItemPlace() { final String label = "placeLabel"; final PlaceRequest place = mock(PlaceRequest.class); final Menus menus = MenuFactory.newSimpleItem(label).place(place).endMenu().build(); when(authzManager.authorize(menus.getItems().get(0), identity)).thenReturn(true); presenter.addMenus(menus); verify(presenter).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(true); verify(presenter, times(2)).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(false); verify(presenter).enableMenuItem(anyString(), eq(false)); }
@Test public void testSetupEnableDisableMenuItemPerspective() { final String label = "perspectiveLabel"; final String perspectiveId = "perspectiveId"; final Menus menus = MenuFactory.newSimpleItem(label).perspective(perspectiveId).endMenu().build(); when(authzManager.authorize(menus.getItems().get(0), identity)).thenReturn(true); presenter.addMenus(menus); verify(presenter).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(true); verify(presenter, times(2)).enableMenuItem(anyString(), eq(true)); menus.getItems().get(0).setEnabled(false); verify(presenter).enableMenuItem(anyString(), eq(false)); }
@Test public void enableMenuItemTest() { final CanBeDisabled menuItem = mock(CanBeDisabled.class); presenter.canBeDisabledMenuItemByIdentifier.put("id", menuItem); presenter.enableMenuItem("id", true); verify(menuItem).enable(); }
@Test public void disableMenuItemTest() { final CanBeDisabled menuItem = mock(CanBeDisabled.class); presenter.canBeDisabledMenuItemByIdentifier.put("id", menuItem); presenter.enableMenuItem("id", false); verify(menuItem).disable(); }