private void onEditorLockInfo(@Observes UpdatedLockStatusEvent lockInfo) {
   boolean enabled = (!lockInfo.isLocked() || lockInfo.isLockedByCurrentUser());
   for (MenuItem menuItem : menuItemsSyncedWithLockState) {
     menuItem.setEnabled(enabled);
   }
 }
Exemplo n.º 2
0
 private void disableMenuItems(final Menus menus) {
   for (MenuItem mi : menus.getItemsMap().values()) {
     mi.setEnabled(false);
   }
 }
Exemplo n.º 3
0
  public Widget makeItem(final MenuItem item, boolean isRoot) {
    if (!authzManager.authorize(item, identity)) {
      return null;
    }

    if (item instanceof MenuItemCommand) {
      final MenuItemCommand cmdItem = (MenuItemCommand) item;
      if (isRoot) {
        final Button button = new Button(cmdItem.getCaption());
        button.setSize(ButtonSize.SMALL);
        button.setEnabled(item.isEnabled());
        button.addClickHandler(
            new ClickHandler() {
              @Override
              public void onClick(final ClickEvent event) {
                cmdItem.getCommand().execute();
              }
            });
        item.addEnabledStateChangeListener(
            new EnabledStateChangeListener() {
              @Override
              public void enabledStateChanged(final boolean enabled) {
                button.setEnabled(enabled);
              }
            });
        return button;
      } else {
        final NavbarLink navbarLink = new NavbarLink();
        navbarLink.setText(cmdItem.getCaption());
        if (!item.isEnabled()) {
          navbarLink.addStyleName("disabled");
        }
        navbarLink.addClickHandler(
            new ClickHandler() {
              @Override
              public void onClick(final ClickEvent event) {
                cmdItem.getCommand().execute();
              }
            });
        item.addEnabledStateChangeListener(
            new EnabledStateChangeListener() {
              @Override
              public void enabledStateChanged(final boolean enabled) {
                if (enabled) {
                  navbarLink.removeStyleName("disabled");
                } else {
                  navbarLink.addStyleName("disabled");
                }
              }
            });
        return navbarLink;
      }

    } else if (item instanceof MenuGroup) {
      final MenuGroup groups = (MenuGroup) item;
      if (isRoot) {
        final List<Widget> widgetList = new ArrayList<Widget>();
        for (final MenuItem _item : groups.getItems()) {
          final Widget widget = makeItem(_item, false);
          if (widget != null) {
            widgetList.add(widget);
          }
        }

        if (widgetList.isEmpty()) {
          return null;
        }

        return makeDropDownMenuButton(groups.getCaption(), widgetList);

      } else {
        final List<Widget> widgetList = new ArrayList<Widget>();
        for (final MenuItem _item : groups.getItems()) {
          final Widget result = makeItem(_item, false);
          if (result != null) {
            widgetList.add(result);
          }
        }

        if (widgetList.isEmpty()) {
          return null;
        }

        return makeDropDownMenuButton(groups.getCaption(), widgetList);
      }

    } else if (item instanceof MenuCustom) {
      final Object result = ((MenuCustom) item).build();
      if (result instanceof Widget) {
        return (Widget) result;
      }
    }

    return null;
  }