Class CmsContextMenu

  • All Implemented Interfaces:
    com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Extension, com.vaadin.shared.Connector, java.io.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:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsContextMenu()
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addContextMenuCloseListener​(CmsContextMenu.ContextMenuClosedListener contextMenuClosedListener)
      Adds listener that will be invoked when context menu is closed.
      void addContextMenuComponentListener​(CmsContextMenu.ContextMenuOpenedListener.ComponentListener contextMenuComponentListener)
      Adds listener that will be invoked when context menu is opened from the component to which it's assigned to.
      void addContextMenuTableListener​(CmsContextMenu.ContextMenuOpenedListener.TableListener contextMenuTableListener)
      Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Table component.
      void addContextMenuTreeListener​(CmsContextMenu.ContextMenuOpenedListener.TreeListener contextMenuTreeListener)
      Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Tree component.
      CmsContextMenu.ContextMenuItem addItem​(com.vaadin.server.Resource icon)
      Adds new item to context menu root with given icon without caption.
      CmsContextMenu.ContextMenuItem addItem​(java.lang.String caption)
      Adds new item to context menu root with given caption.
      CmsContextMenu.ContextMenuItem addItem​(java.lang.String caption, com.vaadin.server.Resource icon)
      Adds new item to context menu root with given caption and icon.
      void addItemClickListener​(CmsContextMenu.ContextMenuItemClickListener clickListener)
      Adds click listener to context menu.
      void extend​(com.vaadin.server.AbstractClientConnector target)  
      protected void fireEvent​(java.util.EventObject event)
      Added to increase method visibility.
      protected java.lang.String getNextId()
      Returns a new UUID.
      protected com.vaadin.server.Resource getResource​(java.lang.String key)
      Added to increase visibility.
      protected CmsContextMenuState getState()  
      void hide()
      Closes the context menu from server side.
      boolean isHideAutomatically()
      Returns if the menu is set to hide automatically.
      boolean isOpenAutomatically()
      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, java.lang.Object itemId, java.lang.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 removeAllItems()
      Removes all items from the context menu.
      void removeItem​(CmsContextMenu.ContextMenuItem contextMenuItem)
      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 setEntries​(java.util.Collection<I_CmsSimpleContextMenuEntry<T>> entries, T data)
      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​(java.lang.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
    • Method Detail

      • 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

        public CmsContextMenu.ContextMenuItem addItem​(java.lang.String caption)
        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​(java.lang.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
      • 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,
                                 java.lang.Object itemId,
                                 java.lang.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​(java.util.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​(java.util.EventObject event)
        Added to increase method visibility.

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

        protected java.lang.String getNextId()
        Returns a new UUID.

        Returns:
        a new UUID
      • getResource

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

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

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

        protected void setResource​(java.lang.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)