Class ContextMenu

All Implemented Interfaces:
Animatable<ContextMenu>, Scrollable<ContextMenu>

public class ContextMenu extends Component<ContextMenu> implements Animatable<ContextMenu>, Scrollable<ContextMenu>

The context menu component (Right click menu)

The context menu component can be assigned to any component. If it's assigned, the user can access this menu if they press the right mouse button, and they can choose from the menu items.

The context menu has a header, that can have custom text assigned to it, and it also has a closing button in the top right corner (X button). The menu can also be closed if the user clicks anywhere else inside the application.

Supported events:

AnimationStart AnimationEnd, Scrollable

Since:
4.0
Author:
JBStrap
  • Field Details

    • titleContainer

      protected final Div titleContainer
    • closeBtn

      protected final Link closeBtn
  • Constructor Details

    • ContextMenu

      public ContextMenu()
      Creates a context menu, and assigns it to the specified component
      Throws:
      NullPointerException - If the component is specified as null
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
  • Method Details

    • setCloseable

      public final ContextMenu setCloseable(boolean closeable)
      Determines if the close icon will appear in the top right corner. Defaults to true
      Parameters:
      closeable - If specified as true the close button will be enabled. If false, it won't appear.
      Returns:
      The context menu component
    • setTitleText

      public final ContextMenu setTitleText(String title)
      Sets the title text of the menu
      Parameters:
      title - The menu title text
      Returns:
      The context menu component
    • isCloseable

      public final boolean isCloseable()
      Determines if the context menu has a close button enabled
      Returns:
      true if the button is enabled, otherwise false
    • getTitleText

      public final String getTitleText()
      Gets the context menu title text
      Returns:
      The title text or null if no text was specified
    • addMenuItem

      public final void addMenuItem(Icon icon, String text, Object data, ClickEventHandler clickHandler)
      Adds a menu item to the context menu
      Parameters:
      icon - The menu item icon. For a list of icons, see the Icon enum. If specified as null no icon will be added.
      text - The menu item text. If specified as null, the menu item won't have any text.
      data - Custom date to be added to the menu item. The data object specified here won't be used by the framework, but it's value will be accessible to the menu item
      clickHandler - The menu item click handler (ClickEventHandler)implementation. This is where the business logic can be implemented, that will run when the user clicks on the menu item
    • getMenuItem

      public final Link getMenuItem(String data)
      Gets the menu item, that is specified by its data
      Parameters:
      data - The custom data, that was specified when the menu item was created.
      Returns:
      The first menu item that has the specified data. If not found, returns with null
    • addComponent

      public ContextMenu addComponent(Component component)
      Adds the specified component as a subcomponent, and redraws the component immediately
      Overrides:
      addComponent in class Component<ContextMenu>
      Parameters:
      component - The component to be added
      Returns:
      The component
    • _addComponent

      protected ContextMenu _addComponent(Component<?> component)
      Parameters:
      component - The component to be added
      Returns:
      The context menu component
    • removeComponent

      public ContextMenu removeComponent(Component component)
      Removes the specified subcomponent.
      Overrides:
      removeComponent in class Component<ContextMenu>
      Parameters:
      component - The component instance
      Returns:
      The component
    • addTextListItem

      public final ContextMenu addTextListItem(String text)
      Adds the specified static text, as an unclickable menu item to the context menu.
      Parameters:
      text - The static text to be added
      Returns:
      The context menu component
    • addItemList

      public final ContextMenu addItemList(List<?> items)
      Adds multiple menu items
      Parameters:
      items - A list of menu items to be added to the context menu. The list must be made of components, that have click handler implementations. Otherwise, they will appear as static text.
      Returns:
      The context menu component
    • clear

      public final ContextMenu clear()
      Clears the menu
      Returns:
      The context menu component
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (StringWriter class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<ContextMenu>
      Returns:
      If the componentwas drawn, true, otherwise false
    • close

      public final void close()
      Closes the menu if it was open. If it wasn't, the method won't do anything.