Class ContextMenu
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionprotected final Link
protected final ListBox
protected final Div
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionCreates a context menu, and assigns it to the specified component -
Method Summary
Modifier and TypeMethodDescriptionprotected ContextMenu
_addComponent
(Component<?> component) addComponent
(Component component) Adds the specified component as a subcomponent, and redraws the component immediatelyfinal ContextMenu
addItemList
(List<?> items) Adds multiple menu itemsfinal void
addMenuItem
(Icon icon, String text, Object data, ClickEventHandler clickHandler) Adds a menu item to the context menufinal ContextMenu
addTextListItem
(String text) Adds the specified static text, as an unclickable menu item to the context menu.final ContextMenu
clear()
Clears the menufinal void
close()
Closes the menu if it was open.final Link
getMenuItem
(String data) Gets the menu item, that is specified by its datafinal String
Gets the context menu title textfinal boolean
Determines if the context menu has a close button enabledremoveComponent
(Component component) Removes the specified subcomponent.final ContextMenu
setCloseable
(boolean closeable) Determines if the close icon will appear in the top right corner.final ContextMenu
setTitleText
(String title) Sets the title text of the menuboolean
writeHTML
(StringWriter writer) Creates the component's HTML equivalentMethods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, afterDraw, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getName, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, init, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, isVisible, onHide, onHotKeyEventHandler, onShow, openTag, redraw, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEnabled, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setMargin, setName, setOverflow, setPadding, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setVisible, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.Scrollable
addScrollHandler
-
Field Details
-
titleContainer
-
closeBtn
-
Constructor Details
-
ContextMenu
public ContextMenu()Creates a context menu, and assigns it to the specified component- Throws:
NullPointerException
- If the component is specified asnull
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
-
Method Details
-
setCloseable
Determines if the close icon will appear in the top right corner. Defaults totrue
- Parameters:
closeable
- If specified astrue
the close button will be enabled. Iffalse
, it won't appear.- Returns:
- The context menu component
-
setTitleText
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, otherwisefalse
-
getTitleText
Gets the context menu title text- Returns:
- The title text or
null
if no text was specified
-
addMenuItem
Adds a menu item to the context menu- Parameters:
icon
- The menu item icon. For a list of icons, see theIcon
enum. If specified asnull
no icon will be added.text
- The menu item text. If specified asnull
, 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 itemclickHandler
- 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
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
Adds the specified component as a subcomponent, and redraws the component immediately- Overrides:
addComponent
in classComponent<ContextMenu>
- Parameters:
component
- The component to be added- Returns:
- The component
-
_addComponent
- Parameters:
component
- The component to be added- Returns:
- The context menu component
-
removeComponent
Removes the specified subcomponent.- Overrides:
removeComponent
in classComponent<ContextMenu>
- Parameters:
component
- The component instance- Returns:
- The component
-
addTextListItem
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
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
Clears the menu- Returns:
- The context menu component
-
writeHTML
Description copied from class:Component
Creates the component's HTML equivalentThis 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 withfalse
. Otherwise, it must return withtrue
.- Specified by:
writeHTML
in classComponent<ContextMenu>
- Returns:
- If the componentwas drawn,
true
, otherwisefalse
-
close
public final void close()Closes the menu if it was open. If it wasn't, the method won't do anything.
-