|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vaadin.event.Action
com.vaadin.event.ShortcutAction
org.vostok.vaadin.addon.keypress.KeyPressAction
public abstract class KeyPressAction
KeyPressAction allow you to register a specific listener for a component when using the same shortcut accross several others component.
It acts as a proxy between components and the default vaadin Shortcut listener.
ClientConnector.attach / ClientConnector.detach :
KeyPressAction can detect an ActionHanler from component. If it fail, it will use default, e.i. UI.
You can explicitly call addAction / removeAction within ClientConnector.attach / ClientConnector.detach methods instead.
Your action will then be linked to your component's proper ActionHanler, and removed when view exit.
Bulk registration :
It's common to need the same shortcut for several components. Instead of registering shortcut ones by ones, you can use addWithFactory / removeWithFactory. Note its still recommanded to override ClientConnector.attach / ClientConnector.detach.
PassThroughHandler
Keep in mind KeyPressAction is some kind of proxy, it works "globaly", at UI level, listens for any shortcut and take care of filtering and dispaching events to correct component.
But some component might need to prevent some shortcut, for example, TextArea must prevent <enter> because it's needed internally (else this may block a carriage return). Unfortunately it's not possible to push back key to the component, but you can use PassThroughHandler to "fix" it.
KeyPressAction already takes care of <enter> with TextArea.
RichTextArea issue
Unlike TextArea, RichTextArea lacks caret information. It's not possible to reinject <enter>.
See sample at http://vaadin.vostoksystem.eu
Nested Class Summary | |
---|---|
static interface |
KeyPressAction.KeyPressActionListener
|
static interface |
KeyPressAction.PassThroughHandler
|
Nested classes/interfaces inherited from class com.vaadin.event.ShortcutAction |
---|
com.vaadin.event.ShortcutAction.KeyCode, com.vaadin.event.ShortcutAction.ModifierKey |
Nested classes/interfaces inherited from class com.vaadin.event.Action |
---|
com.vaadin.event.Action.Container, com.vaadin.event.Action.Handler, com.vaadin.event.Action.Listener, com.vaadin.event.Action.Notifier, com.vaadin.event.Action.ShortcutNotifier |
Field Summary |
---|
Fields inherited from class com.vaadin.event.ShortcutAction |
---|
SHORTHAND_CHAR_ALT, SHORTHAND_CHAR_CTRL, SHORTHAND_CHAR_SHIFT |
Constructor Summary | |
---|---|
KeyPressAction(com.vaadin.ui.Component target,
int key,
int... modifier)
Create a new action on target for key and modifier . |
Method Summary | |
---|---|
static void |
addAction(KeyPressAction action)
Add an action. |
static void |
addAction(KeyPressAction[] action)
Add a list of actions. target can be different. |
static void |
addPassThrough(java.lang.Class c,
KeyPressAction.PassThroughHandler listener)
Keep in mind KeyPressAction, as build on top of shortcutListener is still global (within an Action.Handler). |
static void |
addWithFactory(com.vaadin.ui.Component[] list,
KeyPressAction.KeyPressActionListener listener,
int key,
int... modifier)
batch addition. |
static KeyPressAction |
getKeyPressAction(com.vaadin.ui.Component c,
int key,
int... modifier)
Return KeyPresAction from internal db |
com.vaadin.ui.Component |
getTarget()
return target this KeyPressAction was register for |
void |
handleAction(java.lang.Object sender,
java.lang.Object target)
DON'T OVERRIDE !!! |
abstract void |
handleKeyPress(com.vaadin.ui.Component target)
Your business code here, component is the one - and only the -one - you registered the KeyPressAction for. |
static boolean |
isThisMatch(int keycode_a,
int[] modifier_a,
int keycode_b,
int[] modifier_b)
convenience method to check if 2 keypress sequence match |
static void |
removeAction(KeyPressAction action)
Unregister an action. |
static void |
removeAction(KeyPressAction[] action)
Unregister a list of actions. target can be different. |
static void |
removeWithFactory(com.vaadin.ui.Component[] list,
int key,
int... modifier)
|
Methods inherited from class com.vaadin.event.ShortcutAction |
---|
getKeyCode, getModifiers |
Methods inherited from class com.vaadin.event.Action |
---|
getCaption, getIcon, setCaption, setIcon |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public KeyPressAction(com.vaadin.ui.Component target, int key, int... modifier)
target
for key
and modifier
.
target
- target this action will respond tokey
- shortcut, use ShortcutAction.KeyCodemodifier
- mdifier, use ShortcutAction.ModifierKey, can be nullShortcutAction
Method Detail |
---|
public void handleAction(java.lang.Object sender, java.lang.Object target)
handleAction
in interface com.vaadin.event.Action.Listener
sender
- target
- public abstract void handleKeyPress(com.vaadin.ui.Component target)
target
- public com.vaadin.ui.Component getTarget()
public static void addAction(KeyPressAction action)
action
- can be nullpublic static void addAction(KeyPressAction[] action)
action
- can be nullpublic static void removeAction(KeyPressAction action)
action
- can be nullpublic static void removeAction(KeyPressAction[] action)
action
- array, can be nullpublic static void addWithFactory(com.vaadin.ui.Component[] list, KeyPressAction.KeyPressActionListener listener, int key, int... modifier)
list
- listener
- key
- modifier
- public static void removeWithFactory(com.vaadin.ui.Component[] list, int key, int... modifier)
list
- key
- modifier
- public static KeyPressAction getKeyPressAction(com.vaadin.ui.Component c, int key, int... modifier)
c
- component
KeyPressAction was registered onkey
- ShortcutAction.KeyCode
KeyPressAction was registered withmodifier
- ShortcutAction.KeyCode
KeyPressAction was registered with
public static void addPassThrough(java.lang.Class c, KeyPressAction.PassThroughHandler listener)
c
- listener
- public static boolean isThisMatch(int keycode_a, int[] modifier_a, int keycode_b, int[] modifier_b)
keycode_a
- modifier_a
- keycode_b
- modifier_b
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |