Record Class MenuNode

java.lang.Object
java.lang.Record
com.vaadin.swingbridge.surrogates.MenuNode

public record MenuNode(String text, com.vaadin.flow.component.Component icon, boolean enabled, boolean separator, boolean checkable, boolean checked, KeyStroke accelerator, Runnable onClick, List<MenuNode> children) extends Record
Surrogate-internal descriptor consumed by SJMenuBar.rebuildFromTree(List) (SD_sjmenubar). The emulator-side :emulators.swing.JMenuBar walks its JDK menu tree on every mutation, builds a List<MenuNode>, and pushes it through the surrogate's tree-rebuild API. Pure-surrogate users never see this type — they compose with Vaadin MenuBar.addItem directly per [R_vaadin_first](../../CLAUDE.md).

Lives in com.vaadin.swingbridge.surrogates (not :emulators) per [SD_shelper_statics](decisions.md): the descriptor is the surrogate's input, so it lives on the surrogate side of the :emulators → :surrogates boundary.

Field semantics

  • text — the rendered label. Empty string for icon-only items. null matches JDK's icon-only ctor convention.
  • icon — pre-converted Vaadin Component (typically a com.vaadin.flow.component.html.Image from Icons.imageIconToVaadinImage(ImageIcon)). The emulator runs the conversion before populating the descriptor; the surrogate just passes the resulting Component to Vaadin's MenuBar.addItem(Component, listener) overload.
  • enabled — drives Vaadin MenuItem.setEnabled.
  • separator — when true, the rebuild walk emits subMenu.addSeparator() (or drops + WARNs at the top level per SD_sjmenubar's accepted gap). All other fields ignored.
  • checkable — drives Vaadin MenuItem.setCheckable.
  • checked — drives Vaadin MenuItem.setChecked when checkable is true.
  • accelerator — JDK KeyStroke. The surrogate's rebuild path translates via KeyConvert.toVaadinKeyBinding(KeyStroke) and installs a UI-scoped Shortcuts.addShortcutListener. Unmappable keystrokes log + skip browser install but the emulator-side field round-trip survives.
  • onClick — fires the JDK ActionEvent on the emulator side. The surrogate wraps invocation in SHelper.callSwing(Runnable) (R_callswing_envelope funnel for blocking-dialog work). null means "non-clickable" — used for top-level JMenu containers whose click opens a submenu (Vaadin handles that natively, no handler needed).
  • children — nested submenu items. Empty for leaf JMenuItems; populated for JMenus.

Immutable record — every rebuild builds fresh nodes.

  • Constructor Summary

    Constructors
    Constructor
    Description
    MenuNode(String text, com.vaadin.flow.component.Component icon, boolean enabled, boolean separator, boolean checkable, boolean checked, KeyStroke accelerator, Runnable onClick, List<MenuNode> children)
    Creates an instance of a MenuNode record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the accelerator record component.
    boolean
    Returns the value of the checkable record component.
    boolean
    Returns the value of the checked record component.
    Returns the value of the children record component.
    boolean
    Returns the value of the enabled record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    com.vaadin.flow.component.Component
    Returns the value of the icon record component.
    static MenuNode
    ofItem(String text, boolean enabled, Runnable onClick)
    Convenience: a leaf JMenuItem-shape node with text + enabled + onClick.
    static MenuNode
    ofMenu(String text, boolean enabled, List<MenuNode> children)
    Convenience: a JMenu-shape node with text + enabled + children.
    static MenuNode
    Convenience: a separator node — only the separator flag is meaningful.
    Returns the value of the onClick record component.
    boolean
    Returns the value of the separator record component.
    Returns the value of the text record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MenuNode

      public MenuNode(String text, com.vaadin.flow.component.Component icon, boolean enabled, boolean separator, boolean checkable, boolean checked, KeyStroke accelerator, Runnable onClick, List<MenuNode> children)
      Creates an instance of a MenuNode record class.
      Parameters:
      text - the value for the text record component
      icon - the value for the icon record component
      enabled - the value for the enabled record component
      separator - the value for the separator record component
      checkable - the value for the checkable record component
      checked - the value for the checked record component
      accelerator - the value for the accelerator record component
      onClick - the value for the onClick record component
      children - the value for the children record component
  • Method Details

    • ofSeparator

      public static MenuNode ofSeparator()
      Convenience: a separator node — only the separator flag is meaningful.
    • ofItem

      public static MenuNode ofItem(String text, boolean enabled, Runnable onClick)
      Convenience: a leaf JMenuItem-shape node with text + enabled + onClick. Other fields default (null icon / accelerator, no checkable, empty children).
    • ofMenu

      public static MenuNode ofMenu(String text, boolean enabled, List<MenuNode> children)
      Convenience: a JMenu-shape node with text + enabled + children. onClick is null (Vaadin auto-handles submenu open on parent click).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • text

      public String text()
      Returns the value of the text record component.
      Returns:
      the value of the text record component
    • icon

      public com.vaadin.flow.component.Component icon()
      Returns the value of the icon record component.
      Returns:
      the value of the icon record component
    • enabled

      public boolean enabled()
      Returns the value of the enabled record component.
      Returns:
      the value of the enabled record component
    • separator

      public boolean separator()
      Returns the value of the separator record component.
      Returns:
      the value of the separator record component
    • checkable

      public boolean checkable()
      Returns the value of the checkable record component.
      Returns:
      the value of the checkable record component
    • checked

      public boolean checked()
      Returns the value of the checked record component.
      Returns:
      the value of the checked record component
    • accelerator

      public KeyStroke accelerator()
      Returns the value of the accelerator record component.
      Returns:
      the value of the accelerator record component
    • onClick

      public Runnable onClick()
      Returns the value of the onClick record component.
      Returns:
      the value of the onClick record component
    • children

      public List<MenuNode> children()
      Returns the value of the children record component.
      Returns:
      the value of the children record component