Class JmixUserMenu<USER>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<JmixMenuBar>
io.jmix.flowui.kit.component.usermenu.JmixUserMenu<USER>
Type Parameters:
USER - the type of the user associated with the menu
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<JmixUserMenu<USER>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<JmixUserMenu<USER>>, com.vaadin.flow.component.FocusNotifier<JmixUserMenu<USER>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasOverlayClassName, com.vaadin.flow.component.shared.HasThemeVariant<UserMenuVariant>, HasSubParts, HasTitle, HasActionMenuItems, HasComponentMenuItems, HasMenuItems, HasTextMenuItems, Serializable
Direct Known Subclasses:
UserMenu

public class JmixUserMenu<USER> extends com.vaadin.flow.component.Composite<JmixMenuBar> implements HasTextMenuItems, HasActionMenuItems, HasComponentMenuItems, com.vaadin.flow.component.HasEnabled, HasTitle, com.vaadin.flow.component.shared.HasOverlayClassName, HasSubParts, com.vaadin.flow.component.shared.HasThemeVariant<UserMenuVariant>, com.vaadin.flow.component.Focusable<JmixUserMenu<USER>>
A component that displays a user menu as a dropdown.
See Also:
  • Field Details

  • Constructor Details

    • JmixUserMenu

      public JmixUserMenu()
  • Method Details

    • initUserMenuItem

      protected void initUserMenuItem()
    • initContent

      protected JmixMenuBar initContent()
      Overrides:
      initContent in class com.vaadin.flow.component.Composite<JmixMenuBar>
    • getSubMenu

      protected JmixSubMenu getSubMenu()
    • getUser

      @Nullable public USER getUser()
      Returns the current user associated with the user menu.
      Returns:
      the current user, or null if no user is set
    • setUser

      public void setUser(@Nullable USER user)
      Sets the user for the user menu. If the given user is different from the currently set user, the change is applied, an internal user change handler is called, and a JmixUserMenu.UserChangedEvent is fired.
      Parameters:
      user - the user to be set; can be null to clear the current user
    • userChangedInternal

      protected void userChangedInternal()
    • setButtonRenderer

      public void setButtonRenderer(@Nullable JmixUserMenu.Renderer<USER> buttonRenderer)
      Sets the function to generate the button's content based on the current user.
      Parameters:
      buttonRenderer - a function that takes a user object and returns a Component to be used as the header; can be null, in which case no header content will be displayed
    • updateButton

      protected void updateButton()
    • setHeaderRenderer

      public void setHeaderRenderer(@Nullable JmixUserMenu.Renderer<USER> headerRenderer)
      Sets the function to generate the header's content based on the current user.
      Parameters:
      headerRenderer - a function that takes a user object and returns a Component to be used as the header; can be null, in which case no header content will be displayed
    • updateHeader

      protected void updateHeader()
    • createHeaderWrapper

      protected com.vaadin.flow.component.HasComponents createHeaderWrapper()
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID and text.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, int index)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID and text at the given index.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      index - position at which to insert the menu item
      Returns:
      newly created menu item
    • addTextItem

      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text and click listener.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      listener - callback to be invoked when the menu item is clicked
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, Consumer<UserMenuItem.HasClickListener.ClickEvent<TextUserMenuItem>> listener, int index)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text and click listener at the given index.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      listener - callback to be invoked when the menu item is clicked
      index - position at which to insert the menu item
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, com.vaadin.flow.component.Component icon)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text and icon.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      icon - icon component to be displayed in the menu item
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, com.vaadin.flow.component.Component icon, int index)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text and icon at the given index.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      icon - icon component to be displayed in the menu item
      index - position at which to insert the menu item
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, com.vaadin.flow.component.Component icon, Consumer<UserMenuItem.HasClickListener.ClickEvent<TextUserMenuItem>> listener)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text, icon and click listener.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      icon - icon component to be displayed in the menu item
      listener - callback to be invoked when the menu item is clicked
      Returns:
      newly created menu item
    • addTextItem

      public TextUserMenuItem addTextItem(String id, String text, com.vaadin.flow.component.Component icon, Consumer<UserMenuItem.HasClickListener.ClickEvent<TextUserMenuItem>> listener, int index)
      Description copied from interface: HasTextMenuItems
      Adds a new menu item with the specified ID, text, icon and click listener at the given index.
      Specified by:
      addTextItem in interface HasTextMenuItems
      Parameters:
      id - unique identifier for the menu item
      text - text to be displayed in the menu item
      icon - icon component to be displayed in the menu item
      listener - callback to be invoked when the menu item is clicked
      index - position at which to insert the menu item
      Returns:
      newly created menu item
    • addActionItem

      public ActionUserMenuItem addActionItem(String id, Action action)
      Description copied from interface: HasActionMenuItems
      Adds a new menu item with the specified identifier and associated action.
      Specified by:
      addActionItem in interface HasActionMenuItems
      Parameters:
      id - the unique identifier of the menu item
      action - the Action to associate with the menu item
      Returns:
      the created ActionUserMenuItem instance
    • addActionItem

      public ActionUserMenuItem addActionItem(String id, Action action, int index)
      Description copied from interface: HasActionMenuItems
      Adds a new menu item with the specified identifier, associated action, and specified index where the item should be inserted.
      Specified by:
      addActionItem in interface HasActionMenuItems
      Parameters:
      id - the unique identifier of the menu item
      action - the Action to associate with the menu item
      index - the position at which the menu item should be inserted
      Returns:
      the created ActionUserMenuItem instance
    • addComponentItem

      public ComponentUserMenuItem addComponentItem(String id, com.vaadin.flow.component.Component content)
      Description copied from interface: HasComponentMenuItems
      Adds a new menu item with a unique identifier and a custom UI Component as its content.
      Specified by:
      addComponentItem in interface HasComponentMenuItems
      Parameters:
      id - the unique identifier of the menu item
      content - the Component to be set as the content of the menu item
      Returns:
      the created ComponentUserMenuItem instance
    • addComponentItem

      public ComponentUserMenuItem addComponentItem(String id, com.vaadin.flow.component.Component content, int index)
      Description copied from interface: HasComponentMenuItems
      Adds a new menu item with a unique identifier, a custom UI Component as its content, and inserts it at a specific position in the menu.
      Specified by:
      addComponentItem in interface HasComponentMenuItems
      Parameters:
      id - the unique identifier of the menu item
      content - the Component to be set as the content of the menu item
      index - the position at which the menu item will be inserted
      Returns:
      the created ComponentUserMenuItem instance
    • addComponentItem

      public ComponentUserMenuItem addComponentItem(String id, com.vaadin.flow.component.Component content, Consumer<UserMenuItem.HasClickListener.ClickEvent<ComponentUserMenuItem>> listener)
      Description copied from interface: HasComponentMenuItems
      Adds a new menu item with a unique identifier, a custom UI Component as its content, and a click listener to handle click events for the menu item.
      Specified by:
      addComponentItem in interface HasComponentMenuItems
      Parameters:
      id - the unique identifier of the menu item
      content - the Component to be set as the content of the menu item
      listener - the Consumer that handles the click events triggered by the menu item
      Returns:
      the created ComponentUserMenuItem instance
    • addComponentItem

      public ComponentUserMenuItem addComponentItem(String id, com.vaadin.flow.component.Component content, Consumer<UserMenuItem.HasClickListener.ClickEvent<ComponentUserMenuItem>> listener, int index)
      Description copied from interface: HasComponentMenuItems
      Adds a new menu item with a unique identifier, a custom UI Component as its content, a click listener to handle click events for the menu item, and inserts it at a specific position in the menu.
      Specified by:
      addComponentItem in interface HasComponentMenuItems
      Parameters:
      id - the unique identifier of the menu item
      content - the Component to be set as the content of the menu item
      listener - the Consumer that handles the click events triggered by the menu item
      index - the position at which the menu item will be inserted
      Returns:
      the created ComponentUserMenuItem instance
    • addSeparator

      public void addSeparator()
      Description copied from interface: HasMenuItems
      Adds a separator to the menu. A separator is used to visually divide groups of menu items, enabling better organization and readability.
      Specified by:
      addSeparator in interface HasMenuItems
    • addSeparatorAtIndex

      public void addSeparatorAtIndex(int index)
      Description copied from interface: HasMenuItems
      Adds a separator to the menu at the specified index. A separator is used to visually divide groups of menu items, enhancing organization and readability. The given index determines the position where the separator is inserted.
      Specified by:
      addSeparatorAtIndex in interface HasMenuItems
      Parameters:
      index - the position in the menu where the separator will be added. The index must be within the valid range of current menu items.
    • findItem

      public Optional<UserMenuItem> findItem(String itemId)
      Description copied from interface: HasMenuItems
      Searches for a user menu item with the specified unique identifier.
      Specified by:
      findItem in interface HasMenuItems
      Parameters:
      itemId - the unique identifier of the menu item to find
      Returns:
      an Optional containing the UserMenuItem if found, or an empty Optional if the item does not exist
    • getItem

      public UserMenuItem getItem(String itemId)
      Description copied from interface: HasMenuItems
      Retrieves a user menu item with the specified unique identifier.
      Specified by:
      getItem in interface HasMenuItems
      Parameters:
      itemId - the unique identifier of the menu item to retrieve
      Returns:
      the UserMenuItem associated with the given identifier
    • getSubPart

      @Nullable public UserMenuItem getSubPart(String name)
      Description copied from interface: HasSubParts
      Returns a sub part object by its name.
      Specified by:
      getSubPart in interface HasSubParts
      Parameters:
      name - sub part name, e.g. component id
      Returns:
      a sub part object by its name, or null if not found
    • getItems

      public List<UserMenuItem> getItems()
      Description copied from interface: HasMenuItems
      Returns a list of all items currently present in the user menu component.
      Specified by:
      getItems in interface HasMenuItems
      Returns:
      a list of all items currently present in the user menu component
    • remove

      public void remove(String itemId)
      Description copied from interface: HasMenuItems
      Removes a menu item identified by the specified unique identifier from the menu.
      Specified by:
      remove in interface HasMenuItems
      Parameters:
      itemId - the unique identifier of the menu item to be removed
    • remove

      public void remove(UserMenuItem menuItem)
      Description copied from interface: HasMenuItems
      Removes the specified menu item from the user menu.
      Specified by:
      remove in interface HasMenuItems
      Parameters:
      menuItem - the UserMenuItem to be removed from the menu
    • removeAll

      public void removeAll()
      Description copied from interface: HasMenuItems
      Removes all menu items from the user menu.
      Specified by:
      removeAll in interface HasMenuItems
    • isOpenOnHover

      public boolean isOpenOnHover()
      Determines whether the user menu opens on hover.
      Returns:
      true if the menu opens on hover, false otherwise
    • setOpenOnHover

      public void setOpenOnHover(boolean openOnHover)
      Sets whether the user menu should open when hovered.
      Parameters:
      openOnHover - true to make the menu open on hover, false to disable this behavior
    • setOverlayClassName

      public void setOverlayClassName(@Nullable String overlayClassName)
      Specified by:
      setOverlayClassName in interface com.vaadin.flow.component.shared.HasOverlayClassName
    • addUserChangedListener

      public com.vaadin.flow.shared.Registration addUserChangedListener(com.vaadin.flow.component.ComponentEventListener<JmixUserMenu.UserChangedEvent<USER>> listener)
    • getItemsDelegate

      protected JmixUserMenuItemsDelegate getItemsDelegate()
    • createUserMenuItemsDelegate

      protected JmixUserMenuItemsDelegate createUserMenuItemsDelegate(JmixSubMenu subMenu)
    • createSubMenu

      protected UserMenuItem.HasSubMenu.SubMenu createSubMenu(JmixSubMenu subMenu)