Package org.opencms.ui.contextmenu
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,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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCmsContextMenu.ContextMenuClosedEventContextMenuClosedEvent is an event fired by the context menu when it's closed.static interfaceCmsContextMenu.ContextMenuClosedListenerContextMenuClosedListener 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.classCmsContextMenu.ContextMenuItemContextMenuItem represents one clickable item in the context menu.static classCmsContextMenu.ContextMenuItemClickEventContextMenuItemClickEvent is an event produced by the context menu item when it is clicked.static interfaceCmsContextMenu.ContextMenuItemClickListenerContextMenuItemClickListener is listener for context menu items wanting to notify listeners about item clickstatic interfaceCmsContextMenu.ContextMenuOpenedListenerContextMenuOpenedListener is used to modify the content of context menu based on what was clicked.static classCmsContextMenu.ContextMenuOpenedOnComponentEventContextMenuOpenedOnComponentEvent is an event fired by the context menu when it's opened from a component.static classCmsContextMenu.ContextMenuOpenedOnTableFooterEventContextMenuOpenedOnTableFooterEvent is an event that is fired by the context menu when it's opened by clicking on table footerstatic classCmsContextMenu.ContextMenuOpenedOnTableHeaderEventContextMenuOpenedOnTableHeaderEvent is an event fired by the context menu when it's opened by clicking on table header row.static classCmsContextMenu.ContextMenuOpenedOnTableRowEventContextMenuOpenedOnTableRowEvent is an event that is fired when context menu is opened by clicking on table row.static classCmsContextMenu.ContextMenuOpenedOnTreeItemEventContextMenuOpenedOnTreeItemEvent 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 CmsContextMenu()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContextMenuCloseListener(CmsContextMenu.ContextMenuClosedListener contextMenuClosedListener)Adds listener that will be invoked when context menu is closed.voidaddContextMenuComponentListener(CmsContextMenu.ContextMenuOpenedListener.ComponentListener contextMenuComponentListener)Adds listener that will be invoked when context menu is opened from the component to which it's assigned to.voidaddContextMenuTableListener(CmsContextMenu.ContextMenuOpenedListener.TableListener contextMenuTableListener)Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Table component.voidaddContextMenuTreeListener(CmsContextMenu.ContextMenuOpenedListener.TreeListener contextMenuTreeListener)Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Tree component.CmsContextMenu.ContextMenuItemaddItem(com.vaadin.server.Resource icon)Adds new item to context menu root with given icon without caption.CmsContextMenu.ContextMenuItemaddItem(java.lang.String caption)Adds new item to context menu root with given caption.CmsContextMenu.ContextMenuItemaddItem(java.lang.String caption, com.vaadin.server.Resource icon)Adds new item to context menu root with given caption and icon.voidaddItemClickListener(CmsContextMenu.ContextMenuItemClickListener clickListener)Adds click listener to context menu.voidextend(com.vaadin.server.AbstractClientConnector target)protected voidfireEvent(java.util.EventObject event)Added to increase method visibility.protected java.lang.StringgetNextId()Returns a new UUID.protected com.vaadin.server.ResourcegetResource(java.lang.String key)Added to increase visibility.protected CmsContextMenuStategetState()voidhide()Closes the context menu from server side.booleanisHideAutomatically()Returns if the menu is set to hide automatically.booleanisOpenAutomatically()Returns if the menu is set to open automatically.voidopen(int x, int y)Opens the context menu to given coordinates.voidopen(com.vaadin.ui.Component component)Opens the menu for the given component.voidopenForTable(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.voidopenForTable(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Table table)Opens the context menu of the given table.voidopenForTree(com.vaadin.v7.event.ItemClickEvent event, com.vaadin.v7.ui.Tree tree)Opens the context menu of the given tree.voidremoveAllItems()Removes all items from the context menu.voidremoveItem(CmsContextMenu.ContextMenuItem contextMenuItem)Removes given context menu item from the context menu.voidsetAsContextMenuOf(com.vaadin.server.AbstractClientConnector component)Assigns this as context menu of given component which will react to right mouse button click.voidsetAsTableContextMenu(com.vaadin.v7.ui.Table table)Assigns this as the context menu of given table.voidsetAsTreeContextMenu(com.vaadin.v7.ui.Tree tree)Assigns this as context menu of given tree.<T> voidsetEntries(java.util.Collection<I_CmsSimpleContextMenuEntry<T>> entries, T data)Sets the context menu entries.voidsetHideAutomatically(boolean hideAutomatically)Sets menu to hide automatically after mouse cliks on menu items or area off the menu.voidsetOpenAutomatically(boolean openAutomatically)Enables or disables open automatically feature.protected voidsetResource(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
-
-
-
-
Constructor Detail
-
CmsContextMenu
public CmsContextMenu()
Constructor.
-
-
Method Detail
-
addContextMenuCloseListener
public void addContextMenuCloseListener(CmsContextMenu.ContextMenuClosedListener contextMenuClosedListener)
Adds listener that will be invoked when context menu is closed.- Parameters:
contextMenuClosedListener- menu close listener
-
addContextMenuComponentListener
public 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.- Parameters:
contextMenuComponentListener- the component listener
-
addContextMenuTableListener
public void addContextMenuTableListener(CmsContextMenu.ContextMenuOpenedListener.TableListener contextMenuTableListener)
Adds listener that will be invoked when context menu is opened from com.vaadin.ui.Table component.- Parameters:
contextMenuTableListener- the table listener
-
addContextMenuTreeListener
public void addContextMenuTreeListener(CmsContextMenu.ContextMenuOpenedListener.TreeListener contextMenuTreeListener)
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
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 captionicon- the icon- Returns:
- reference to newly added item
-
addItemClickListener
public void addItemClickListener(CmsContextMenu.ContextMenuItemClickListener clickListener)
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:
extendin classcom.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:
trueif context menu is hiding automatically after clicks
-
isOpenAutomatically
public boolean isOpenAutomatically()
Returns if the menu is set to open automatically.- Returns:
trueif 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 positiony- 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 eventitemId- of clicked itempropertyId- of clicked itemtable- 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 eventtable- 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 eventtree- 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 entriesdata- 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:
fireEventin classcom.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:
getResourcein classcom.vaadin.server.AbstractClientConnector- See Also:
AbstractClientConnector.getResource(java.lang.String)
-
getState
protected CmsContextMenuState getState()
- Overrides:
getStatein classcom.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:
setResourcein classcom.vaadin.server.AbstractClientConnector- See Also:
AbstractClientConnector.setResource(java.lang.String, com.vaadin.server.Resource)
-
-