summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2012-09-18 10:11:02 +0000
committerArtur Signell <artur@vaadin.com>2012-09-28 21:34:00 +0300
commita003c8724c1f719e3a9f3ab876396a180b19cae1 (patch)
tree909d4aac5839b421602282a2de15ff76fb295e37 /server/src
parentca59c93fb4dbc112e5deb5f5a4b10c0c730a4be4 (diff)
downloadvaadin-framework-a003c8724c1f719e3a9f3ab876396a180b19cae1.tar.gz
vaadin-framework-a003c8724c1f719e3a9f3ab876396a180b19cae1.zip
Merged shortcut action fix from 6.8 (#8484)
Change-Id: I1bc200afa9f4a4f3c5e469eb0b2f93278cca97a7
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/event/ActionManager.java30
-rw-r--r--server/src/com/vaadin/event/ShortcutAction.java45
-rw-r--r--server/src/com/vaadin/ui/Button.java9
3 files changed, 75 insertions, 9 deletions
diff --git a/server/src/com/vaadin/event/ActionManager.java b/server/src/com/vaadin/event/ActionManager.java
index 85a1bf0f12..ad643863a7 100644
--- a/server/src/com/vaadin/event/ActionManager.java
+++ b/server/src/com/vaadin/event/ActionManager.java
@@ -18,6 +18,7 @@ package com.vaadin.event;
import java.util.HashSet;
import java.util.Map;
+import com.vaadin.client.ui.ShortcutActionHandler;
import com.vaadin.event.Action.Container;
import com.vaadin.event.Action.Handler;
import com.vaadin.server.KeyMapper;
@@ -187,14 +188,29 @@ public class ActionManager implements Action.Container, Action.Handler,
}
if (a instanceof ShortcutAction) {
final ShortcutAction sa = (ShortcutAction) a;
- paintTarget.addAttribute("kc", sa.getKeyCode());
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_SHORTCUT_KEY_ATTRIBUTE,
+ sa.getKeyCode());
final int[] modifiers = sa.getModifiers();
if (modifiers != null) {
final String[] smodifiers = new String[modifiers.length];
for (int i = 0; i < modifiers.length; i++) {
smodifiers[i] = String.valueOf(modifiers[i]);
}
- paintTarget.addAttribute("mk", smodifiers);
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_MODIFIER_KEYS_ATTRIBUTE,
+ smodifiers);
+ }
+ if (sa.getTarget() != null) {
+ paintTarget.addAttribute(
+ ShortcutActionHandler.ACTION_TARGET_ATTRIBUTE,
+ sa.getTarget());
+ paintTarget
+ .addAttribute(
+ ShortcutActionHandler.ACTION_TARGET_ACTION_ATTRIBUTE,
+ sa.getTargetAction());
}
}
paintTarget.endTag("action");
@@ -212,10 +228,14 @@ public class ActionManager implements Action.Container, Action.Handler,
}
public void handleActions(Map<String, Object> variables, Container sender) {
- if (variables.containsKey("action") && actionMapper != null) {
- final String key = (String) variables.get("action");
+ if (variables
+ .containsKey(ShortcutActionHandler.ACTION_TARGET_ACTION_VARIABLE)
+ && actionMapper != null) {
+ final String key = (String) variables
+ .get(ShortcutActionHandler.ACTION_TARGET_ACTION_VARIABLE);
final Action action = actionMapper.get(key);
- final Object target = variables.get("actiontarget");
+ final Object target = variables
+ .get(ShortcutActionHandler.ACTION_TARGET_VARIABLE);
if (action != null) {
handleAction(action, sender, target);
}
diff --git a/server/src/com/vaadin/event/ShortcutAction.java b/server/src/com/vaadin/event/ShortcutAction.java
index b1d14b15fe..9d13d41b9f 100644
--- a/server/src/com/vaadin/event/ShortcutAction.java
+++ b/server/src/com/vaadin/event/ShortcutAction.java
@@ -21,6 +21,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.vaadin.server.Resource;
+import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;
@@ -57,6 +58,10 @@ public class ShortcutAction extends Action {
private final int[] modifiers;
+ private Component target;
+
+ private String targetAction;
+
/**
* Creates a shortcut that reacts to the given {@link KeyCode} and
* (optionally) {@link ModifierKey}s. <br/>
@@ -237,6 +242,46 @@ public class ShortcutAction extends Action {
}
/**
+ * Set the target for the shortcut action. If the target widget on the
+ * client side implements {@link ShortcutActionTarget} it will be notified
+ * of the action before the action is communicated to the server side
+ *
+ * @param target
+ * The component which will be thet target of the action
+ */
+ public void setTarget(Component target) {
+ this.target = target;
+ }
+
+ /**
+ * Get the target of the shortcut action
+ */
+ public Component getTarget() {
+ return target;
+ }
+
+ /**
+ * Get the action string that is given to the {@link ShortcutActionTarget}
+ * on the client side
+ *
+ * @return
+ */
+ public String getTargetAction() {
+ return targetAction;
+ }
+
+ /**
+ * Set the action string that is give to the {@link ShortcutActionTarget} on
+ * the client side
+ *
+ * @param targetAction
+ * The target action string
+ */
+ public void setTargetAction(String targetAction) {
+ this.targetAction = targetAction;
+ }
+
+ /**
* Key codes that can be used for shortcuts
*
*/
diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java
index 02b7689259..d248efd570 100644
--- a/server/src/com/vaadin/ui/Button.java
+++ b/server/src/com/vaadin/ui/Button.java
@@ -463,7 +463,6 @@ public class Button extends AbstractComponent implements
*
*/
public static class ClickShortcut extends ShortcutListener {
- protected Button button;
/**
* Creates a keyboard shortcut for clicking the given button using the
@@ -476,7 +475,8 @@ public class Button extends AbstractComponent implements
*/
public ClickShortcut(Button button, String shorthandCaption) {
super(shorthandCaption);
- this.button = button;
+ setTarget(button);
+ setTargetAction("click");
}
/**
@@ -492,7 +492,8 @@ public class Button extends AbstractComponent implements
*/
public ClickShortcut(Button button, int keyCode, int... modifiers) {
super(null, keyCode, modifiers);
- this.button = button;
+ setTarget(button);
+ setTargetAction("click");
}
/**
@@ -510,7 +511,7 @@ public class Button extends AbstractComponent implements
@Override
public void handleAction(Object sender, Object target) {
- button.click();
+ // Action handled on the client side
}
}