Class Shortcuts
Unlike the shortcut methods offered by Focusable and
ClickNotifier, these methods allow for configuring the
lifecycleOwner directly, making it possible to add the shortcut onto any
component. The lifecycleOwner denotes the component to which the
shortcut is bound to. If the lifecycle owner is not attached, visible, or
enabled, the shortcut won't work, and vice-versa.
- Since:
- 1.3
- Author:
- Vaadin Ltd.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ShortcutRegistrationaddShortcutListener(Component lifecycleOwner, ShortcutEventListener listener, Key key, KeyModifier... keyModifiers) Invoke aShortcutEventListenerwhen the shortcut is invoked.static ShortcutRegistrationaddShortcutListener(Component lifecycleOwner, Command command, Key key, KeyModifier... keyModifiers) Invoke aCommandwhen the shortcut is invoked.static RegistrationsetShortcutListenOnElement(String elementLocatorJs, Component listenOnComponent) Setup an element, that is only accessible on the browser (not server side), to listen for shortcut events on and delegate to the given component.
-
Method Details
-
addShortcutListener
public static ShortcutRegistration addShortcutListener(Component lifecycleOwner, Command command, Key key, KeyModifier... keyModifiers) Invoke aCommandwhen the shortcut is invoked.Registering a shortcut using this method will tie it to
lifecycleOwnerand the shortcut is available in the global scope.By default, the shortcut's listener is bound to
UI. The listening component can be changed by callingShortcutRegistration.listenOn(Component...).- Parameters:
lifecycleOwner- the component that controls, when the shortcut is active. If the component is either invisible or detached, the shortcut won't work. Cannot benullcommand- code to execute when the shortcut is invoked. Cannot benullkey- primaryKeyused to trigger the shortcut. Cannot benullkeyModifiers-KeyModifierswhich also need to be pressed for the shortcut to trigger- Returns:
ShortcutRegistrationfor configuring and removing the shortcut
-
addShortcutListener
public static ShortcutRegistration addShortcutListener(Component lifecycleOwner, ShortcutEventListener listener, Key key, KeyModifier... keyModifiers) Invoke aShortcutEventListenerwhen the shortcut is invoked.Registering a shortcut using this method will tie it to
lifecycleOwnerand the shortcut is available in the global scope.By default, the shortcut's listener is bound to
UI. The listening component can be changed by callingShortcutRegistration.listenOn(Component...).- Parameters:
lifecycleOwner- the component that controls, when the shortcut is active. If the component is either invisible or detached, the shortcut won't work. Cannot benulllistener- listener to execute when the shortcut is invoked. Receives aShortcutEvent. Cannot benullkey- primaryKeyused to trigger the shortcut. Cannot benullkeyModifiers-KeyModifierswhich also need to be pressed for the shortcut to trigger- Returns:
ShortcutRegistrationfor configuring and removing the shortcut
-
setShortcutListenOnElement
public static Registration setShortcutListenOnElement(String elementLocatorJs, Component listenOnComponent) Setup an element, that is only accessible on the browser (not server side), to listen for shortcut events on and delegate to the given component. The element will be located in the browser by executing the given JS statement. This needs to be set for each listen-on component instance.This should be only used by component developers, when their component is used as the
listenOncomponent for shortcuts, and their component does some magic on the browser which means that the shortcut events are not coming through from the actual element. Thus when an application developer calls e.g.
myButton.addClickShortcut(Key.ENTER).listenOn(dialog);
the framework will automatically make sure the events are passed from the browser only element to the listenOn component (dialog in this case).- Parameters:
elementLocatorJs- js execution string that references the desired element in DOM ornullto any remove existing locatorlistenOnComponent- the component that is setup for listening shortcuts onShortcutRegistration.listenOn(Component...)- Returns:
- a registration for removing the locator, does not affect active shortcuts or if the locator has changed from what was set for this registration
- Since:
-