Class CmsContextMenu

java.lang.Object
com.vaadin.server.AbstractClientConnector
com.vaadin.server.AbstractExtension
org.opencms.ui.contextmenu.CmsContextMenu
All Implemented Interfaces:
com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Extension, com.vaadin.shared.Connector, Serializable

public class CmsContextMenu extends com.vaadin.server.AbstractExtension
ContextMenu is an extension which can be attached to any Vaadin component to display a popup context menu. Most useful the menu is when attached for example to Tree or Table which support item and property based context menu detection.

Adapted from ContextMenu by Peter Lehto / Vaadin Ltd.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    ContextMenuClosedEvent is an event fired by the context menu when it's closed.
    static interface 
    ContextMenuClosedListener is used to listen for the event that the context menu is closed, either when a item is clicked or when the popup is canceled.
    class 
    ContextMenuItem represents one clickable item in the context menu.
    static class 
    ContextMenuItemClickEvent is an event produced by the context menu item when it is clicked.
    static interface 
    ContextMenuItemClickListener is listener for context menu items wanting to notify listeners about item click
    static interface 
    ContextMenuOpenedListener is used to modify the content of context menu based on what was clicked.
    static class 
    ContextMenuOpenedOnComponentEvent is an event fired by the context menu when it's opened from a component.
    static class 
    ContextMenuOpenedOnTableFooterEvent is an event that is fired by the context menu when it's opened by clicking on table footer
    static class 
    ContextMenuOpenedOnTableHeaderEvent is an event fired by the context menu when it's opened by clicking on table header row.
    static class 
    ContextMenuOpenedOnTableRowEvent is an event that is fired when context menu is opened by clicking on table row.
    static class 
    ContextMenuOpenedOnTreeItemEvent is an event fired by the context menu when it's opened by clicking on tree item.

    Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector

    com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds listener that will be invoked when context menu is closed.
    void
    Adds listener that will be invoked when context menu is opened from the component to which it's assigned to.
    void
    Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Table component.
    void
    Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Tree component.
    addItem(com.vaadin.server.Resource icon)
    Adds new item to context menu root with given icon without caption.
    addItem(String caption)
    Adds new item to context menu root with given caption.
    addItem(String caption, com.vaadin.server.Resource icon)
    Adds new item to context menu root with given caption and icon.
    void
    Adds click listener to context menu.
    void
    extend(com.vaadin.server.AbstractClientConnector target)
     
    protected void
    Added to increase method visibility.
    protected String
    Returns a new UUID.
    protected com.vaadin.server.Resource
    Added to increase visibility.
     
    void
    Closes the context menu from server side.
    boolean
    Returns if the menu is set to hide automatically.
    boolean
    Returns if the menu is set to open automatically.
    void
    open(int x, int y)
    Opens the context menu to given coordinates.
    void
    open(com.vaadin.ui.Component component)
    Opens the menu for the given component.
    void
    openForTable(com.vaadin.event.MouseEvents.ClickEvent event, Object itemId, Object propertyId, com.vaadin.v7.ui.Table table)
    Opens the context menu of the given table.
    void
    openForTable(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Table table)
    Opens the context menu of the given table.
    void
    openForTree(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Tree tree)
    Opens the context menu of the given tree.
    void
    Removes all items from the context menu.
    void
    Removes given context menu item from the context menu.
    void
    setAsContextMenuOf(com.vaadin.server.AbstractClientConnector component)
    Assigns this as context menu of given component which will react to right mouse button click.
    void
    setAsTableContextMenu(com.vaadin.v7.ui.Table table)
    Assigns this as the context menu of given table.
    void
    setAsTreeContextMenu(com.vaadin.v7.ui.Tree tree)
    Assigns this as context menu of given tree.
    <T> void
    Sets the context menu entries.
    void
    setHideAutomatically(boolean hideAutomatically)
    Sets menu to hide automatically after mouse cliks on menu items or area off the menu.
    void
    setOpenAutomatically(boolean openAutomatically)
    Enables or disables open automatically feature.
    protected void
    setResource(String key, com.vaadin.server.Resource resource)
    Added to increase visibility.

    Methods inherited from class com.vaadin.server.AbstractExtension

    getParent, getSupportedParentType, remove, setParent

    Methods inherited from class com.vaadin.server.AbstractClientConnector

    addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getRpcManager, getRpcProxy, getSession, getState, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, updateDiffstate

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.server.ClientConnector

    addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler

    Methods inherited from interface com.vaadin.shared.Connector

    getConnectorId
  • Constructor Details

  • Method Details

    • addContextMenuCloseListener

      Adds listener that will be invoked when context menu is closed.

      Parameters:
      contextMenuClosedListener - menu close listener
    • addContextMenuComponentListener

      Adds listener that will be invoked when context menu is opened from the component to which it's assigned to.

      Parameters:
      contextMenuComponentListener - the component listener
    • addContextMenuTableListener

      Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Table component.

      Parameters:
      contextMenuTableListener - the table listener
    • addContextMenuTreeListener

      Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Tree component.

      Parameters:
      contextMenuTreeListener - the menu tree listener
    • addItem

      public CmsContextMenu.ContextMenuItem addItem(com.vaadin.server.Resource icon)
      Adds new item to context menu root with given icon without caption.

      Parameters:
      icon - the icon
      Returns:
      reference to newly added item
    • addItem

      Adds new item to context menu root with given caption.

      Parameters:
      caption - the caption
      Returns:
      reference to newly added item
    • addItem

      public CmsContextMenu.ContextMenuItem addItem(String caption, com.vaadin.server.Resource icon)
      Adds new item to context menu root with given caption and icon.

      Parameters:
      caption - the caption
      icon - the icon
      Returns:
      reference to newly added item
    • addItemClickListener

      Adds click listener to context menu. This listener will be invoked when any of the menu items in this menu are clicked.

      Parameters:
      clickListener - the click listener
    • extend

      public void extend(com.vaadin.server.AbstractClientConnector target)
      Overrides:
      extend in class com.vaadin.server.AbstractExtension
      See Also:
      • AbstractExtension.extend(com.vaadin.server.AbstractClientConnector)
    • hide

      public void hide()
      Closes the context menu from server side.

    • isHideAutomatically

      public boolean isHideAutomatically()
      Returns if the menu is set to hide automatically.

      Returns:
      true if context menu is hiding automatically after clicks
    • isOpenAutomatically

      public boolean isOpenAutomatically()
      Returns if the menu is set to open automatically.

      Returns:
      true if open automatically is on. If open automatically is on, it means that context menu will always be opened when it's host component is right clicked. If automatic opening is turned off, context menu will only open when server side open(x, y) is called. Automatic opening avoid having to make server roundtrip whereas "manual" opening allows to have logic in menu before opening it.
    • open

      public void open(com.vaadin.ui.Component component)
      Opens the menu for the given component.

      Parameters:
      component - the component
    • open

      public void open(int x, int y)
      Opens the context menu to given coordinates. ContextMenu must extend component before calling this method. This method is only intended for opening the context menu from server side when using {@link #ContextMenuOpenedListener.ComponentListener}.

      Parameters:
      x - the client x position
      y - the client y position
    • openForTable

      public void openForTable(com.vaadin.event.MouseEvents.ClickEvent event, Object itemId, Object propertyId, com.vaadin.v7.ui.Table table)
      Opens the context menu of the given table.

      Parameters:
      event - the click event
      itemId - of clicked item
      propertyId - of clicked item
      table - the table
    • openForTable

      public void openForTable(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Table table)
      Opens the context menu of the given table.

      Parameters:
      event - the click event
      table - the table
    • openForTree

      public void openForTree(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Tree tree)
      Opens the context menu of the given tree.

      Parameters:
      event - the click event
      tree - the tree
    • removeAllItems

      public void removeAllItems()
      Removes all items from the context menu.

    • removeItem

      public void removeItem(CmsContextMenu.ContextMenuItem contextMenuItem)
      Removes given context menu item from the context menu. The given item can be a root item or leaf item or anything in between. If given given is not found from the context menu structure, this method has no effect.

      Parameters:
      contextMenuItem - the menu item
    • setAsContextMenuOf

      public void setAsContextMenuOf(com.vaadin.server.AbstractClientConnector component)
      Assigns this as context menu of given component which will react to right mouse button click.

      Parameters:
      component - the component
    • setAsTableContextMenu

      public void setAsTableContextMenu(com.vaadin.v7.ui.Table table)
      Assigns this as the context menu of given table.

      Parameters:
      table - the table
    • setAsTreeContextMenu

      public void setAsTreeContextMenu(com.vaadin.v7.ui.Tree tree)
      Assigns this as context menu of given tree.

      Parameters:
      tree - the tree
    • setEntries

      public <T> void setEntries(Collection<I_CmsSimpleContextMenuEntry<T>> entries, T data)
      Sets the context menu entries. Removes all previously present entries.

      Parameters:
      entries - the entries
      data - the context data
    • setHideAutomatically

      public void setHideAutomatically(boolean hideAutomatically)
      Sets menu to hide automatically after mouse cliks on menu items or area off the menu. If automatic hiding is disabled menu will stay open as long as hide is called from the server side.

      Parameters:
      hideAutomatically - whether to hide automatically
    • setOpenAutomatically

      public void setOpenAutomatically(boolean openAutomatically)
      Enables or disables open automatically feature. If open automatically is on, it means that context menu will always be opened when it's host component is right clicked. This will happen on client side without server round trip. If automatic opening is turned off, context menu will only open when server side open(x, y) is called. If automatic opening is disabled you will need a listener implementation for context menu that is called upon client side click event. Another option is to extend context menu and handle the right clicking internally with case specific listener implementation and inside it call open(x, y) method.
      Parameters:
      openAutomatically - whether to open automatically
    • fireEvent

      protected void fireEvent(EventObject event)
      Added to increase method visibility.

      Overrides:
      fireEvent in class com.vaadin.server.AbstractClientConnector
      See Also:
      • AbstractClientConnector.fireEvent(java.util.EventObject)
    • getNextId

      protected String getNextId()
      Returns a new UUID.

      Returns:
      a new UUID
    • getResource

      protected com.vaadin.server.Resource getResource(String key)
      Added to increase visibility.

      Overrides:
      getResource in class com.vaadin.server.AbstractClientConnector
      See Also:
      • AbstractClientConnector.getResource(java.lang.String)
    • getState

      Overrides:
      getState in class com.vaadin.server.AbstractClientConnector
      See Also:
      • AbstractClientConnector.getState()
    • setResource

      protected void setResource(String key, com.vaadin.server.Resource resource)
      Added to increase visibility.

      Overrides:
      setResource in class com.vaadin.server.AbstractClientConnector
      See Also:
      • AbstractClientConnector.setResource(java.lang.String, com.vaadin.server.Resource)