Class QMenuAdjuster

java.lang.Object
com.kingsrook.qqq.backend.core.model.metadata.menus.adjusters.QMenuAdjuster

public class QMenuAdjuster extends Object
Utility class for programmatically modifying menu structures.

This class provides static methods to adjust menus and menu items after they have been created. Common operations include:

  • Removing items (first match or all matches)
  • Adding items (before, after, first, or last position)
  • Replacing items

All operations use QMenuItemMatcher to locate target items within the menu structure. Operations recursively search through nested sub-menus and sub-lists.

See Also:
  • Constructor Details

    • QMenuAdjuster

      public QMenuAdjuster()
  • Method Details

    • removeFirst

      public static boolean removeFirst(QMenuItemContainerInterface menuItemContainer, QMenuItemMatcher matcher)
      Removes the first menu item that matches the given matcher.

      Searches recursively through the menu structure and removes only the first matching item found. Stops searching after the first removal.

      Parameters:
      menuItemContainer - the menu item container to search
      matcher - the matcher used to identify the item to remove
      Returns:
      true if an item was removed, false otherwise
    • removeAll

      public static int removeAll(QMenuItemContainerInterface menuItemContainer, QMenuItemMatcher matcher)
      Removes all menu items that match the given matcher.

      Searches recursively through the entire menu structure and removes all items that match the matcher's criteria.

      Parameters:
      menuItemContainer - the menu item container to search
      matcher - the matcher used to identify items to remove
      Returns:
      the number of items that were removed
    • addAfter

      public static boolean addAfter(QMenuItemContainerInterface menuItemContainer, QMenuItemInterface newItem, QMenuItemMatcher matcher)
      Adds a new menu item immediately after the first item that matches the matcher.

      Searches recursively through the menu structure. If a matching item is found, the new item is inserted immediately after it. If no match is found, no changes are made.

      Parameters:
      menuItemContainer - the menu item container to modify
      newItem - the menu item to add
      matcher - the matcher used to locate the insertion point
      Returns:
      true if the item was successfully added, false if no match was found
    • addBefore

      public static boolean addBefore(QMenuItemContainerInterface menuItemContainer, QMenuItemInterface newItem, QMenuItemMatcher matcher)
      Adds a new menu item immediately before the first item that matches the matcher.

      Searches recursively through the menu structure. If a matching item is found, the new item is inserted immediately before it. If no match is found, no changes are made.

      Parameters:
      menuItemContainer - the menu item container to modify
      newItem - the menu item to add
      matcher - the matcher used to locate the insertion point
      Returns:
      true if the item was successfully added, false if no match was found
    • addLast

      public static void addLast(QMenuItemContainerInterface menuItemContainer, QMenuItemInterface newItem)
      Adds a new menu item at the end of a menu item container.
      Parameters:
      menuItemContainer - the menu item container to modify
      newItem - the menu item to add
    • addFirst

      public static void addFirst(QMenuItemContainerInterface menuItemContainer, QMenuItemInterface newItem)
      Adds a new menu item at the start of a menu item container.
      Parameters:
      menuItemContainer - the menu item container to modify
      newItem - the menu item to add
    • addAtIndex

      public static void addAtIndex(QMenuItemContainerInterface menuItemContainer, int index, QMenuItemInterface newItem)
      Adds a new menu item at the specified index of a menu item container.

      If the index is out of bounds - this will throw IndexOutOfBoundsException

      Parameters:
      menuItemContainer - the menu item container to modify
      index - (0-based) of the insertion point (see list.add)
      newItem - the menu item to add
    • replaceItem

      public static boolean replaceItem(QMenuItemContainerInterface menuItemContainer, QMenuItemInterface replacementItem, QMenuItemMatcher matcher)
      Replace the first menu that matches the given matcher with a replacement item.

      Searches recursively through the menu structure. If a matching item is found, the new item replace it. If no match is found, no changes are made.

      Parameters:
      menuItemContainer - the menu item container to modify
      replacementItem - the menu item to add to the container
      matcher - the matcher used to locate the item to be replaced by the replacementItem
      Returns:
      true if the item was successfully added, false if no match was found